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); } }
public async Task <bool> DeleteFilesAsync(IEnumerable <string> relativeFilePaths, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); List <string> absolutePaths = new List <string>(); foreach (string filePath in relativeFilePaths) { string absoluteFilePath = Path.Combine(WorkingDirectory, filePath); FileInfo file = new FileInfo(absoluteFilePath); if (file.Exists) { absolutePaths.Add(absoluteFilePath); } } //Delete from project Project project = VsHelpers.GetDTEProjectFromConfig(_configFilePath); bool isCoreProject = await VsHelpers.IsDotNetCoreWebProjectAsync(project); if (!isCoreProject) { var logAction = new Action <string, LogLevel>((message, level) => { Logger.Log(message, level); }); bool deleteFromProject = await VsHelpers.DeleteFilesFromProjectAsync(project, absolutePaths, logAction, cancellationToken); if (deleteFromProject) { return(true); } } // Delete from file system return(await DeleteFilesFromDisk(absolutePaths, cancellationToken)); }
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); } }
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 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); } }