public async Task <IReadOnlyList <IPackageSearchMetadata> > GetAllPackagesAsync(CancellationToken cancellationToken) { // Go off the UI thread to perform non-UI operations await TaskScheduler.Default; ActivityCorrelationContext.StartNew(); var packages = new List <IPackageSearchMetadata>(); ContinuationToken nextToken = null; do { var searchResult = await SearchAsync(nextToken, cancellationToken); while (searchResult.RefreshToken != null) { searchResult = await _packageFeed.RefreshSearchAsync(searchResult.RefreshToken, cancellationToken); } nextToken = searchResult.NextToken; packages.AddRange(searchResult.Items); } while (nextToken != null); return(packages); }
/// <summary> /// The static method which takes in all the possible parameters /// </summary> /// <returns>Returns true if at least one of the packages needed to be restored and got restored</returns> /// <remarks> /// Best use case is 'nuget.exe restore .sln' where there is no project loaded and there is no SolutionManager. /// The references are obtained by parsing of solution file and by using PackagesConfigReader. In this case, /// you don't construct an object of PackageRestoreManager, /// but just the NuGetPackageManager using constructor that does not need the SolutionManager, and, optionally /// register to events and/or specify the source repositories /// </remarks> public static async Task <PackageRestoreResult> RestoreMissingPackagesAsync(PackageRestoreContext packageRestoreContext, INuGetProjectContext nuGetProjectContext) { if (packageRestoreContext == null) { throw new ArgumentNullException(nameof(packageRestoreContext)); } if (nuGetProjectContext == null) { throw new ArgumentNullException(nameof(nuGetProjectContext)); } ActivityCorrelationContext.StartNew(); var missingPackages = packageRestoreContext.Packages.Where(p => p.IsMissing).ToList(); if (!missingPackages.Any()) { return(new PackageRestoreResult(true)); } bool packageRestoreResult = true; // It is possible that the dictionary passed in may not have used the PackageReferenceComparer. // So, just to be sure, create a hashset with the keys from the dictionary using the PackageReferenceComparer // Now, we are guaranteed to not restore the same package more than once var hashSetOfMissingPackageReferences = new HashSet <Packaging.PackageReference>(missingPackages.Select(p => p.PackageReference), new PackageReferenceComparer()); // Before starting to restore package, set the nuGetProjectContext such that satellite files are not copied yet // Satellite files will be copied as a post operation. This helps restore packages in parallel // and not have to determine if the package is a satellite package beforehand if (nuGetProjectContext.PackageExtractionContext == null) { nuGetProjectContext.PackageExtractionContext = new PackageExtractionContext(new LoggerAdapter(nuGetProjectContext)); } nuGetProjectContext.PackageExtractionContext.CopySatelliteFiles = false; packageRestoreContext.Token.ThrowIfCancellationRequested(); var restoreResults = await ThrottledPackageRestoreAsync(hashSetOfMissingPackageReferences, packageRestoreContext, nuGetProjectContext); packageRestoreContext.Token.ThrowIfCancellationRequested(); await ThrottledCopySatelliteFilesAsync(hashSetOfMissingPackageReferences, packageRestoreContext, nuGetProjectContext); packageRestoreResult &= restoreResults.All(r => r); if (packageRestoreResult) { packageRestoreContext.SetRestored(); } return(new PackageRestoreResult(packageRestoreContext.WasRestored)); }
protected NuGetPowerShellBaseCommand() { _sourceRepositoryProvider = ServiceLocator.GetInstance <ISourceRepositoryProvider>(); ConfigSettings = ServiceLocator.GetInstance <Configuration.ISettings>(); VsSolutionManager = ServiceLocator.GetInstance <ISolutionManager>(); DTE = ServiceLocator.GetInstance <DTE>(); SourceControlManagerProvider = ServiceLocator.GetInstance <ISourceControlManagerProvider>(); _commonOperations = ServiceLocator.GetInstance <ICommonOperations>(); PackageRestoreManager = ServiceLocator.GetInstance <IPackageRestoreManager>(); _deleteOnRestartManager = ServiceLocator.GetInstance <IDeleteOnRestartManager>(); if (_commonOperations != null) { ExecutionContext = new IDEExecutionContext(_commonOperations); } ActivityCorrelationContext.StartNew(); }
public async Task LoadNextAsync(IProgress <IItemLoaderState> progress, CancellationToken cancellationToken) { ActivityCorrelationContext.StartNew(); cancellationToken.ThrowIfCancellationRequested(); NuGetEventTrigger.Instance.TriggerEvent(NuGetEvent.PackageLoadBegin); var nextToken = _state.Results?.NextToken; var cleanState = SearchResult.Empty <IPackageSearchMetadata>(); cleanState.NextToken = nextToken; await UpdateStateAndReportAsync(cleanState, progress); var searchResult = await SearchAsync(nextToken, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); await UpdateStateAndReportAsync(searchResult, progress); NuGetEventTrigger.Instance.TriggerEvent(NuGetEvent.PackageLoadEnd); }
public async Task <int> GetTotalCountAsync(int maxCount, CancellationToken cancellationToken) { // Go off the UI thread to perform non-UI operations await TaskScheduler.Default; ActivityCorrelationContext.StartNew(); int totalCount = 0; ContinuationToken nextToken = null; do { var searchResult = await SearchAsync(nextToken, cancellationToken); while (searchResult.RefreshToken != null) { searchResult = await _packageFeed.RefreshSearchAsync(searchResult.RefreshToken, cancellationToken); } totalCount += searchResult.Items?.Count() ?? 0; nextToken = searchResult.NextToken; } while (nextToken != null && totalCount <= maxCount); return(totalCount); }