private async Task UninstallAppServices(UninstallCommandContext context)
        {
            foreach (var appInstallation in context.AppInstallations)
            {
                _log.InfoFormat(Resources.UninstallCommandHandler_StartUninstallAppService, appInstallation);

                // Удаление службы приложения
                await _appService.Uninstall(appInstallation);
            }
        }
        private Task FindAppInstallations(UninstallCommandContext context)
        {
            context.AppInstallations = _installDirectory.GetItems(context.CommandOptions.Id, context.CommandOptions.Version, context.CommandOptions.Instance);

            if (context.AppInstallations == null || context.AppInstallations.Length <= 0)
            {
                throw new CommandHandlerException(Resources.UninstallCommandHandler_CanNotFindAnyApplicationsToUninstall);
            }

            return(AsyncHelper.EmptyTask);
        }
        public override async Task Handle(UninstallCommandOptions options)
        {
            CommonHelper.CheckAdministrativePrivileges();

            var commandContext = new UninstallCommandContext
            {
                CommandOptions = options
            };

            var commandTransaction = new CommandTransactionManager <UninstallCommandContext>(_log)
                                     .Stage(Resources.UninstallCommandHandler_FindAppInstallations, FindAppInstallations)
                                     .Stage(Resources.UninstallCommandHandler_UninstallAppServices, UninstallAppServices)
                                     .Stage(Resources.UninstallCommandHandler_DeleteAppFiles, DeleteAppFiles)
            ;

            await commandTransaction.Execute(commandContext);
        }
        private Task DeleteAppFiles(UninstallCommandContext context)
        {
            foreach (var appInstallation in context.AppInstallations)
            {
                _log.InfoFormat(Resources.UninstallCommandHandler_StartDeleteAppFiles, appInstallation);

                try
                {
                    _installDirectory.Delete(appInstallation);
                }
                catch (InvalidOperationException exception)
                {
                    throw new CommandHandlerException(exception.Message, exception);
                }
            }

            return(AsyncHelper.EmptyTask);
        }