Skip to content

Commit

Permalink
Ensure commonality in behavior by managing the context flag setting f…
Browse files Browse the repository at this point in the history
…or COM Commands from a parent-level structure,

leveraging inheritance instead of compelling every COMCommand concrete implementation to override the Execute function for flag setting
  • Loading branch information
Madhusudhan-MSFT committed Mar 20, 2024
1 parent dfc73b6 commit f20ca2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
37 changes: 14 additions & 23 deletions src/AppInstallerCLICore/Commands/COMCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace AppInstaller::CLI
using namespace AppInstaller::Manifest;
using namespace AppInstaller::Utility::literals;

// IMPORTANT: This serves as a base interface for all COM commands and should not be used directly.
// It allows the COM Command implementations to share and enforce common behavior before invoking the base implementation.
// Currently, it sets the WinGetCOMApiCall flag in the context before invoking the base Execute implementation.
void COMCommand::Execute(Context& context) const
{
context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall);
Command::Execute(context);
}

// IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data
void COMDownloadCommand::ExecuteInternal(Context& context) const
{
Expand All @@ -28,12 +37,6 @@ namespace AppInstaller::CLI
Workflow::SetDownloadDirectory <<
Workflow::DownloadPackageDependencies <<
Workflow::DownloadInstaller;
}

void COMDownloadCommand::Execute(Context& context) const
{
context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall);
Command::Execute(context);
}

// IMPORTANT: To use this command, the caller should have already executed the COMDownloadCommand
Expand All @@ -43,24 +46,12 @@ namespace AppInstaller::CLI
Workflow::InstallDependencies <<
Workflow::ReverifyInstallerHash <<
Workflow::InstallPackageInstaller;
}

void COMInstallCommand::Execute(Context& context) const
{
context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall);
Command::Execute(context);
}

// IMPORTANT: To use this command, the caller should have already retrieved the InstalledPackageVersion and added it to the Context Data
void COMUninstallCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
Workflow::UninstallSinglePackage;
}

void COMUninstallCommand::Execute(Execution::Context& context) const
{
context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall);
Command::Execute(context);
}
void COMUninstallCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
Workflow::UninstallSinglePackage;
}
}
32 changes: 19 additions & 13 deletions src/AppInstallerCLICore/Commands/COMCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,45 @@
#include "Command.h"

namespace AppInstaller::CLI
{
{
// IMPORTANT: This acts as a base interface for all COM commands, and should not be used directly
// This will only all the COM Command implementations to share and enforce common behavior before invoking based implementation.
// Right now, it sets the WinGetCOMApiCall flag to the context before invoking the base Execute implementation.
struct COMCommand : public Command
{
protected:
COMCommand(std::string_view name, std::string_view parent) : Command(name, parent) {}

public:
void Execute(Execution::Context& context) const override;
};

// IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data
struct COMDownloadCommand final : public Command
struct COMDownloadCommand final : public COMCommand
{
constexpr static std::string_view CommandName = "download"sv;
COMDownloadCommand(std::string_view parent) : Command(CommandName, parent) {}
COMDownloadCommand(std::string_view parent) : COMCommand(CommandName, parent) {}

void Execute(Execution::Context& context) const override;

protected:
void ExecuteInternal(Execution::Context& context) const override;
};

// IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data
struct COMInstallCommand final : public Command
struct COMInstallCommand final : public COMCommand
{
constexpr static std::string_view CommandName = "install"sv;
COMInstallCommand(std::string_view parent) : Command(CommandName, parent) {}
COMInstallCommand(std::string_view parent) : COMCommand(CommandName, parent) {}

void Execute(Execution::Context& context) const override;

protected:
void ExecuteInternal(Execution::Context& context) const override;
};

// IMPORTANT: To use this command, the caller should have already retrieved the InstalledPackageVersion and added it to the Context Data
struct COMUninstallCommand final : public Command
struct COMUninstallCommand final : public COMCommand
{
constexpr static std::string_view CommandName = "uninstall"sv;
COMUninstallCommand(std::string_view parent) : Command(CommandName, parent) {}
COMUninstallCommand(std::string_view parent) : COMCommand(CommandName, parent) {}

void Execute(Execution::Context& context) const override;

protected:
void ExecuteInternal(Execution::Context& context) const override;
};
Expand Down

0 comments on commit f20ca2c

Please sign in to comment.