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 void Setup() { string cacheFolder = Environment.ExpandEnvironmentVariables(@"%localappdata%\Microsoft\Library\"); string projectFolder = Path.Combine(Path.GetTempPath(), "LibraryInstaller"); _hostInteraction = new HostInteraction(projectFolder, cacheFolder); }
public IProvider CreateProvider(IHostInteraction hostInteraction) { var provider = new FileSystemProvider(); string storePath = Path.Combine(hostInteraction.CacheDirectory, provider.Id); provider.HostInteraction = hostInteraction; return(provider); }
public JsDelivrProvider(IHostInteraction hostInteraction, INpmPackageSearch packageSearch, INpmPackageInfoFactory infoFactory) { _packageSearch = packageSearch; _infoFactory = infoFactory; HostInteraction = hostInteraction; _cacheService = new CacheService(WebRequestHandler.Instance); }
public IProvider CreateProvider(IHostInteraction hostInteraction) { if (hostInteraction == null) { throw new ArgumentNullException(nameof(hostInteraction)); } return(new UnpkgProvider(hostInteraction, _packageSearch, _packageInfoFactory)); }
public IProvider CreateProvider(IHostInteraction hostInteraction) { if (hostInteraction == null) { throw new ArgumentNullException(nameof(hostInteraction)); } return(new UnpkgProvider(hostInteraction, new CacheService(WebRequestHandler.Instance), _packageSearch, _packageInfoFactory)); }
public UnpkgProvider(IHostInteraction hostInteraction, INpmPackageSearch packageSearch, INpmPackageInfoFactory infoFactory) { _packageSearch = packageSearch; _infoFactory = infoFactory; HostInteraction = hostInteraction; // TODO: {alexgav} Do we need multiple instances of CacheService? _cacheService = new CacheService(WebRequestHandler.Instance); }
/// <summary> /// Creates an <see cref="Microsoft.Web.LibraryManager.Contracts.IProvider" /> instance. /// </summary> /// <param name="hostInteraction">The <see cref="Microsoft.Web.LibraryManager.Contracts.IHostInteraction" /> provided by the host to handle file system writes etc.</param> /// <returns> /// A <see cref="Microsoft.Web.LibraryManager.Contracts.IProvider" /> instance. /// </returns> /// <exception cref="System.ArgumentNullException">hostInteraction</exception> public IProvider CreateProvider(IHostInteraction hostInteraction) { if (hostInteraction == null) { throw new ArgumentNullException(nameof(hostInteraction)); } return(new CdnjsProvider(hostInteraction, new CacheService(WebRequestHandler.Instance))); }
/// <summary> /// Creates an <see cref="T:Microsoft.Web.LibraryManager.Contracts.IProvider" /> instance. /// </summary> /// <param name="hostInteraction">The <see cref="T:Microsoft.Web.LibraryManager.Contracts.IHostInteraction" /> provided by the host to handle file system writes etc.</param> /// <returns> /// A <see cref="T:Microsoft.Web.LibraryManager.Contracts.IProvider" /> instance. /// </returns> /// <exception cref="System.ArgumentNullException">hostInteraction</exception> public IProvider CreateProvider(IHostInteraction hostInteraction) { if (hostInteraction == null) { throw new ArgumentNullException(nameof(hostInteraction)); } return(new CdnjsProvider(hostInteraction)); }
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); } }
public Dependencies(IHostEnvironment environment) { if (environment == null) { throw new ArgumentNullException(nameof(environment)); } _hostInteraction = environment?.HostInteraction; string toolInstallationDir = environment.ToolInstallationDir; //TODO: This will scan all dependencies of the tool. // Need to figure out how to handle when extensions are installed. _assemblyPaths = Directory.EnumerateFiles(toolInstallationDir, "*.dll"); Initialize(); }
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); } }
/// <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 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); } }
/// <summary> /// Initializes a new instance of the <see cref="Provider"/> class. /// </summary> /// <param name="hostInteraction">The host interaction.</param> public Provider(IHostInteraction hostInteraction) { HostInteraction = hostInteraction; }
public JsDelivrProvider(IHostInteraction hostInteraction, CacheService cacheService, INpmPackageSearch packageSearch, INpmPackageInfoFactory infoFactory) : base(hostInteraction, cacheService) { _packageSearch = packageSearch; _infoFactory = infoFactory; }
/// <summary> /// Creates a new instance of <see cref="Manifest"/>. /// </summary> /// <param name="dependencies">The host provided dependencies.</param> public Manifest(IDependencies dependencies) { _libraries = new List <ILibraryInstallationState>(); _dependencies = dependencies; _hostInteraction = dependencies?.GetHostInteractions(); }
/// <summary> /// Initializes a new instance of the <see cref="Dependencies"/> class. /// </summary> /// <param name="hostInteractions">The host interactions.</param> /// <param name="providers">The providers.</param> public Dependencies(IHostInteraction hostInteractions, params IProvider[] providers) { _hostInteractions = hostInteractions; Providers.AddRange(providers); }
/// <summary> /// Initializes a new instance of the <see cref="Dependencies"/> class. /// </summary> /// <param name="hostInteractions">The host interactions.</param> public Dependencies(IHostInteraction hostInteractions) { _hostInteractions = hostInteractions; }
/// <summary> /// Creates an <see cref="T:LibraryManager.Contracts.IProvider" /> instance and assigns the <paramref name="hostInteraction"/> to it. /// </summary> /// <param name="hostInteraction">The <see cref="T:LibraryManager.Contracts.IHostInteraction" /> provided by the host to handle file system writes etc.</param> /// <returns>A <see cref="T:LibraryManager.Contracts.IProvider" /> instance.</returns> public virtual IProvider CreateProvider(IHostInteraction hostInteraction) { return(new Provider(hostInteraction)); }
/// <summary> /// Initializes a new instance of the <see cref="CdnjsProvider"/> class. /// </summary> /// <param name="hostInteraction">The host interaction.</param> public CdnjsProvider(IHostInteraction hostInteraction) { HostInteraction = hostInteraction; _cacheService = new CacheService(WebRequestHandler.Instance); }
/// <summary> /// Initializes a new instance of the <see cref="Dependencies"/> class. /// </summary> /// <param name="hostInteraction">The host interactions.</param> /// <param name="factories">The provider factories.</param> public Dependencies(IHostInteraction hostInteraction, params IProviderFactory[] factories) { _hostInteractions = hostInteraction; AllProviders.AddRange(factories.Select(f => f.CreateProvider(hostInteraction))); }
private Dependencies(IHostInteraction hostInteraction, IEnumerable <string> assemblyPaths) { _hostInteraction = hostInteraction; _assemblyPaths = assemblyPaths; Initialize(); }
private void PopulateFilesWritten(IEnumerable <ILibraryOperationResult> results, IHostInteraction hostInteraction) { IEnumerable <ILibraryInstallationState> states = results.Where(r => r.Success).Select(r => r.InstallationState); var list = new List <ITaskItem>(); foreach (ILibraryInstallationState state in states) { foreach (string file in state.Files) { string absolutePath = Path.Combine(hostInteraction.WorkingDirectory, state.DestinationPath, file); var absolute = new FileInfo(absolutePath); if (absolute.Exists) { string relative = absolute.FullName.Replace(ProjectDirectory, string.Empty).TrimStart('/', '\\'); list.Add(new TaskItem(relative)); } } } FilesWritten = list.ToArray(); }
internal Dependencies(IHostInteraction hostInteraction, IReadOnlyList <IProvider> providers) { _hostInteraction = hostInteraction; Providers = providers; }
private IReadOnlyList <IProvider> GetProviders(IHostInteraction hostInteraction) { return(ProviderFactories.Select(pf => pf.CreateProvider(hostInteraction)).ToList()); }
private Dependencies(IHostInteraction hostInteraction) { _hostInteraction = hostInteraction; Initialize(); }
public UnpkgProvider(IHostInteraction hostInteraction) { HostInteraction = hostInteraction; // TODO: {alexgav} Do we need multiple instances of CacheService? _cacheService = new CacheService(WebRequestHandler.Instance); }
/// <summary> /// Initializes a new instance of the <see cref="CdnjsProvider"/> class. /// </summary> /// <param name="hostInteraction">The host interaction.</param> /// <param name="cacheService">The instance of a <see cref="CacheService"/> to use.</param> public CdnjsProvider(IHostInteraction hostInteraction, CacheService cacheService) : base(hostInteraction, cacheService) { }
/// <summary>Internal use only</summary> public FileSystemProvider(IHostInteraction hostInteraction) { HostInteraction = hostInteraction; }