Beispiel #1
0
        public NuGetProjectPackageManager(IPackageInstallationService packageInstallationService,
                                          INuGetProjectContextProvider nuGetProjectContextProvider, INuGetProjectConfigurationProvider nuGetProjectConfigurationProvider,
                                          IMessageService messageService, IFileSystemService fileSystemService)
        {
            Argument.IsNotNull(() => packageInstallationService);
            Argument.IsNotNull(() => nuGetProjectContextProvider);
            Argument.IsNotNull(() => nuGetProjectConfigurationProvider);
            Argument.IsNotNull(() => messageService);

            _packageInstallationService        = packageInstallationService;
            _nuGetProjectContextProvider       = nuGetProjectContextProvider;
            _nuGetProjectConfigurationProvider = nuGetProjectConfigurationProvider;
            _messageService    = messageService;
            _fileSystemService = fileSystemService;
        }
        public async Task <IDisposableToken <IProgress <float> > > TrackDownloadOperationAsync(IPackageInstallationService packageInstallationService, SourcePackageDependencyInfo packageDependencyInfo)
        {
            Argument.IsNotNull(() => packageInstallationService);
            Argument.IsNotNull(() => packageDependencyInfo);

            try
            {
#pragma warning disable IDISP001 // Dispose created.
                var watcher = new FileSystemWatcher();
#pragma warning restore IDISP001 // Dispose created.
                var downloadPath          = packageInstallationService.InstallerPathResolver.GetPackageFilePath(packageDependencyInfo.Id, packageDependencyInfo.Version);
                var downloadDirectoryPath = Path.GetDirectoryName(downloadPath);

                // the download method creates directory itself, but we need to create it eager to start watching
                _directoryService.Create(downloadDirectoryPath);

                watcher.Path = Path.GetDirectoryName(downloadPath);

                // determine package size
                var packageByteSize = await packageInstallationService.MeasurePackageSizeFromRepositoryAsync(packageDependencyInfo, packageDependencyInfo.Source);

                var trackToken = new DownloadProgressTrackToken(_fileService, this, packageDependencyInfo, packageDependencyInfo.Source, watcher, OnProgressReportedCallback, packageByteSize ?? 0);

                return(trackToken);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(null);
            }
        }