private async Task CleanLibrariesAsync(ProjectItem configProjectItem, CancellationToken cancellationToken)
        {
            Logger.LogEventsHeader(OperationType.Clean, string.Empty);

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                string  configFileName = configProjectItem.FileNames[1];
                var     dependencies   = Dependencies.FromConfigFile(configFileName);
                Project project        = VsHelpers.GetDTEProjectFromConfig(configFileName);

                Manifest manifest = await Manifest.FromFileAsync(configFileName, dependencies, CancellationToken.None).ConfigureAwait(false);

                IEnumerable <ILibraryOperationResult> results = new List <ILibraryOperationResult>();

                if (manifest != null)
                {
                    IHostInteraction hostInteraction = dependencies.GetHostInteractions();
                    results = await manifest.CleanAsync(async (filesPaths) => await hostInteraction.DeleteFilesAsync(filesPaths, cancellationToken), cancellationToken);
                }

                sw.Stop();

                AddErrorsToErrorList(project?.Name, configFileName, results);
                Logger.LogEventsSummary(results, OperationType.Clean, sw.Elapsed);
            }
            catch (OperationCanceledException)
            {
                Logger.LogEvent(LibraryManager.Resources.Text.Clean_OperationCancelled, LogLevel.Task);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes unwanted library files
        /// </summary>
        /// <param name="newManifest"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <bool> RemoveUnwantedFilesAsync(Manifest newManifest, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (newManifest != null)
            {
                IEnumerable <FileIdentifier> existingFiles = await GetAllManifestFilesWithVersionsAsync(Libraries).ConfigureAwait(false);

                IEnumerable <FileIdentifier> newFiles = await GetAllManifestFilesWithVersionsAsync(newManifest.Libraries).ConfigureAwait(false);

                IEnumerable <string> filesToRemove = existingFiles.Except(newFiles).Select(f => f.Path);

                if (filesToRemove.Any())
                {
                    IHostInteraction hostInteraction = _dependencies.GetHostInteractions();
                    return(await hostInteraction.DeleteFilesAsync(filesToRemove, cancellationToken).ConfigureAwait(false));
                }
            }

            return(true);
        }
        private async Task UninstallLibraryAsync(string configFilePath, string libraryName, string version, string providerId, CancellationToken cancellationToken)
        {
            string libraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(libraryName, version, providerId);

            Logger.LogEventsHeader(OperationType.Uninstall, libraryId);

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                var      dependencies = _dependenciesFactory.FromConfigFile(configFilePath);
                Manifest manifest     = await Manifest.FromFileAsync(configFilePath, dependencies, cancellationToken).ConfigureAwait(false);

                ILibraryOperationResult result = null;

                if (manifest == null)
                {
                    result = LibraryOperationResult.FromError(PredefinedErrors.ManifestMalformed());
                }
                else
                {
                    IHostInteraction hostInteraction = dependencies.GetHostInteractions();
                    result = await manifest.UninstallAsync(libraryName, version, async (filesPaths) => await hostInteraction.DeleteFilesAsync(filesPaths, cancellationToken), cancellationToken).ConfigureAwait(false);
                }

                sw.Stop();

                if (result.Errors.Any())
                {
                    Logger.LogErrorsSummary(new List <ILibraryOperationResult> {
                        result
                    }, OperationType.Uninstall);
                }
                else
                {
                    Logger.LogEventsSummary(new List <ILibraryOperationResult> {
                        result
                    }, OperationType.Uninstall, sw.Elapsed);
                }

                Telemetry.LogEventsSummary(new List <ILibraryOperationResult> {
                    result
                }, OperationType.Uninstall, sw.Elapsed);
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogEvent(string.Format(LibraryManager.Resources.Text.Uninstall_LibraryCancelled, libraryId), LogLevel.Task);
                Telemetry.TrackException($@"{OperationType.Uninstall}Cancelled", ex);
            }
        }
        private async Task CleanLibrariesAsync(ProjectItem configProjectItem, CancellationToken cancellationToken)
        {
            Logger.LogEventsHeader(OperationType.Clean, string.Empty);

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                string  configFileName = configProjectItem.FileNames[1];
                var     dependencies   = _dependenciesFactory.FromConfigFile(configFileName);
                Project project        = VsHelpers.GetDTEProjectFromConfig(configFileName);

                Manifest manifest = await Manifest.FromFileAsync(configFileName, dependencies, CancellationToken.None).ConfigureAwait(false);

                IEnumerable <ILibraryOperationResult> results = new List <ILibraryOperationResult>();

                if (manifest != null)
                {
                    IEnumerable <ILibraryOperationResult> validationResults = await LibrariesValidator.GetManifestErrorsAsync(manifest, dependencies, cancellationToken).ConfigureAwait(false);

                    if (!validationResults.All(r => r.Success))
                    {
                        sw.Stop();
                        AddErrorsToErrorList(project?.Name, configFileName, validationResults);
                        Logger.LogErrorsSummary(validationResults, OperationType.Clean);
                        Telemetry.LogErrors($"FailValidation_{OperationType.Clean}", validationResults);
                    }
                    else
                    {
                        IHostInteraction hostInteraction = dependencies.GetHostInteractions();
                        results = await manifest.CleanAsync(async (filesPaths) => await hostInteraction.DeleteFilesAsync(filesPaths, cancellationToken), cancellationToken);

                        sw.Stop();
                        AddErrorsToErrorList(project?.Name, configFileName, results);
                        Logger.LogEventsSummary(results, OperationType.Clean, sw.Elapsed);
                        Telemetry.LogEventsSummary(results, OperationType.Clean, sw.Elapsed);
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogEvent(LibraryManager.Resources.Text.Clean_OperationCancelled, LogLevel.Task);
                Telemetry.TrackException($@"{OperationType.Clean}Cancelled", ex);
            }
        }
        private async Task UninstallLibraryAsync(string configFilePath, string libraryId, CancellationToken cancellationToken)
        {
            Logger.LogEventsHeader(OperationType.Uninstall, libraryId);

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                var      dependencies = Dependencies.FromConfigFile(configFilePath);
                Manifest manifest     = await Manifest.FromFileAsync(configFilePath, dependencies, cancellationToken).ConfigureAwait(false);

                ILibraryOperationResult result = null;

                if (manifest == null)
                {
                    result = LibraryOperationResult.FromError(PredefinedErrors.ManifestMalformed());
                }
                else
                {
                    IHostInteraction hostInteraction = dependencies.GetHostInteractions();
                    result = await manifest.UninstallAsync(libraryId, async (filesPaths) => await hostInteraction.DeleteFilesAsync(filesPaths, cancellationToken), cancellationToken).ConfigureAwait(false);
                }

                sw.Stop();

                Logger.LogEventsSummary(new List <ILibraryOperationResult> {
                    result
                }, OperationType.Uninstall, sw.Elapsed);
                Telemetry.TrackUserTask("libraryuninstall");
            }
            catch (OperationCanceledException)
            {
                Logger.LogEvent(string.Format(LibraryManager.Resources.Text.Uninstall_LibraryCancelled, libraryId), LogLevel.Task);
            }
        }