Esempio n. 1
0
        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);
                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);
            }
        }
Esempio n. 2
0
        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 RestoreInternalAsync(IDictionary <string, Manifest> manifests, CancellationToken cancellationToken)
        {
            Logger.LogEventsHeader(OperationType.Restore, string.Empty);

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

                foreach (KeyValuePair <string, Manifest> manifest in manifests)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    Stopwatch swLocal = new Stopwatch();
                    swLocal.Start();
                    IDependencies dependencies = Dependencies.FromConfigFile(manifest.Key);
                    Project       project      = VsHelpers.GetDTEProjectFromConfig(manifest.Key);

                    Logger.LogEvent(string.Format(LibraryManager.Resources.Text.Restore_LibrariesForProject, project?.Name), LogLevel.Operation);

                    IEnumerable <ILibraryOperationResult> validationResults = await LibrariesValidator.GetManifestErrorsAsync(manifest.Value, dependencies, cancellationToken).ConfigureAwait(false);

                    if (!validationResults.All(r => r.Success))
                    {
                        swLocal.Stop();
                        AddErrorsToErrorList(project?.Name, manifest.Key, validationResults);
                        Logger.LogErrorsSummary(validationResults, OperationType.Restore, false);
                        Telemetry.LogErrors($"FailValidation_{OperationType.Restore}", validationResults);
                    }
                    else
                    {
                        IEnumerable <ILibraryOperationResult> results = await RestoreLibrariesAsync(manifest.Value, cancellationToken).ConfigureAwait(false);
                        await AddFilesToProjectAsync(manifest.Key, project, results.Where(r => r.Success && !r.UpToDate), cancellationToken).ConfigureAwait(false);

                        swLocal.Stop();
                        AddErrorsToErrorList(project?.Name, manifest.Key, results);
                        Logger.LogEventsSummary(results, OperationType.Restore, swLocal.Elapsed, false);
                        Telemetry.LogEventsSummary(results, OperationType.Restore, swLocal.Elapsed);
                    }
                }

                swTotal.Stop();
                Logger.LogEventsFooter(OperationType.Restore, swTotal.Elapsed);
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogEvent(LibraryManager.Resources.Text.Restore_OperationCancelled, LogLevel.Task);
                Telemetry.TrackException($@"{OperationType.Restore}Cancelled", ex);
            }
        }
Esempio n. 4
0
        private async Task RestoreInternalAsync(IDictionary <string, Manifest> manifests, CancellationToken cancellationToken)
        {
            Logger.LogEventsHeader(OperationType.Restore, string.Empty);

            List <ILibraryOperationResult> totalResults = new List <ILibraryOperationResult>();

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

                foreach (KeyValuePair <string, Manifest> manifest in manifests)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    Project project = VsHelpers.GetDTEProjectFromConfig(manifest.Key);

                    Logger.LogEvent(string.Format(LibraryManager.Resources.Text.Restore_LibrariesForProject, project?.Name), LogLevel.Operation);

                    IEnumerable <ILibraryOperationResult> results = await RestoreLibrariesAsync(manifest.Value, cancellationToken).ConfigureAwait(false);

                    await AddFilesToProjectAsync(manifest.Key, project, results.Where(r => r.Success && !r.UpToDate), cancellationToken).ConfigureAwait(false);

                    AddErrorsToErrorList(project?.Name, manifest.Key, results);
                    totalResults.AddRange(results);
                }

                sw.Stop();

                Logger.LogEventsSummary(totalResults, OperationType.Restore, sw.Elapsed);
                Telemetry.LogEventsSummary(totalResults, OperationType.Restore, sw.Elapsed);
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogEvent(LibraryManager.Resources.Text.Restore_OperationCancelled, LogLevel.Task);
                Telemetry.TrackException($@"{OperationType.Restore}Cancelled", ex);
            }
        }