コード例 #1
0
        protected override async Task <int> ExecuteInternalAsync()
        {
            var sw = new Stopwatch();

            sw.Start();

            Manifest manifest = await GetManifestAsync();

            Task <bool> deleteFileAction(IEnumerable <string> s) => HostInteractions.DeleteFilesAsync(s, CancellationToken.None);

            IEnumerable <ILibraryOperationResult> validationResults = await manifest.GetValidationResultsAsync(CancellationToken.None);

            if (!validationResults.All(r => r.Success))
            {
                sw.Stop();
                LogErrors(validationResults.SelectMany(r => r.Errors));

                return(0);
            }

            IEnumerable <ILibraryOperationResult> results = await manifest.CleanAsync(deleteFileAction, CancellationToken.None);

            sw.Stop();
            LogResultsSummary(results, OperationType.Clean, sw.Elapsed);

            return(0);
        }
コード例 #2
0
        protected async override Task <int> ExecuteInternalAsync()
        {
            Manifest manifest = await GetManifestAsync();

            IEnumerable <ILibraryInstallationState> installedLibraries = ValidateParametersAndGetLibrariesToUninstall(manifest);

            if (installedLibraries == null || !installedLibraries.Any())
            {
                Logger.Log(string.Format(Resources.Text.NoLibraryToUninstall, LibraryId.Value), LogLevel.Operation);
                return(0);
            }

            ILibraryInstallationState libraryToUninstall = null;

            if (installedLibraries.Count() > 1)
            {
                Logger.Log(string.Format(Resources.Text.MoreThanOneLibraryFoundToUninstall, LibraryId.Value), LogLevel.Operation);

                libraryToUninstall = LibraryResolver.ResolveLibraryByUserChoice(installedLibraries, HostEnvironment);
            }
            else
            {
                libraryToUninstall = installedLibraries.First();
            }

            Task <bool> deleteFileAction(IEnumerable <string> s) => HostInteractions.DeleteFilesAsync(s, CancellationToken.None);

            string libraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(libraryToUninstall.Name, libraryToUninstall.Version, libraryToUninstall.ProviderId);

            ILibraryOperationResult result = await manifest.UninstallAsync(libraryToUninstall.Name, libraryToUninstall.Version, deleteFileAction, CancellationToken.None);

            if (result.Success)
            {
                await manifest.SaveAsync(Settings.ManifestFileName, CancellationToken.None);

                Logger.Log(string.Format(Resources.Text.UninstalledLibrary, libraryId), LogLevel.Operation);
            }
            else
            {
                Logger.Log(string.Format(Resources.Text.UninstallFailed, libraryId), LogLevel.Error);
                foreach (IError error in result.Errors)
                {
                    Logger.Log($"[{error.Code}]: {error.Message}", LogLevel.Error);
                }
            }

            return(0);
        }
コード例 #3
0
        protected override async Task <int> ExecuteInternalAsync()
        {
            Manifest manifest = await GetManifestAsync();

            Task <bool> deleteFileAction(IEnumerable <string> s) => HostInteractions.DeleteFilesAsync(s, CancellationToken.None);

            IEnumerable <ILibraryOperationResult> result = await manifest.CleanAsync(deleteFileAction, CancellationToken.None);

            IEnumerable <ILibraryOperationResult> failures = result.Where(r => !r.Success);

            if (failures.Any())
            {
                Logger.Log(Resources.CleanFailed, LogLevel.Error);
            }

            return(0);
        }