public async Task <ActionResult <BoolResult> > Gather([FromBody] GatherRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, GatherManager.PermissionsList)) { return(Unauthorized()); } //Task.Run(async () => await Main.GatherRuleRepository.GatherListAsync(adminInfo, siteId, ruleId, guid, false)).ConfigureAwait(false).GetAwaiter(); _gatherManager.Start(_authManager.AdminId, request.SiteId, request.RuleId, request.Guid); return(new BoolResult { Value = true }); }
private void QueueWork(IReadOnlyList <SourceResource> sources, PackageIdentity package, bool ignoreExceptions, bool isInstalledPackage) { IReadOnlyList <string> configuredPackageSources = null; if (_isSourceMappingConfigured) { configuredPackageSources = _context.PackageSourceMapping.GetConfiguredPackageSources(package.Id); if (configuredPackageSources != null) { var packageSourcesAtPrefix = string.Join(", ", configuredPackageSources); _context.Log.LogDebug(StringFormatter.Log_PackageSourceMappingMatchFound((package.Id), packageSourcesAtPrefix)); } else { _context.Log.LogDebug(StringFormatter.Log_PackageSourceMappingNoMatchFound((package.Id))); } } // No-op if the id has already been searched for // Exact versions are not added to the list since we may need to search for the full // set of packages for that id later if it becomes part of the closure later. if (package.HasVersion || _idsSearched.Add(package.Id)) { foreach (SourceResource source in sources) { if (_isSourceMappingConfigured) { if (configuredPackageSources == null || configuredPackageSources.Count == 0 || !configuredPackageSources.Contains(source.Source.PackageSource.Name, StringComparer.OrdinalIgnoreCase)) { // This package's id prefix is not defined in current package source, let's skip. continue; } } // Keep track of the order in which these were made var requestId = GetNextRequestId(); var request = new GatherRequest(source, package, ignoreExceptions, requestId, isInstalledPackage); // Order is important here _gatherRequests.Enqueue(request); } } }
private void QueueWork(IReadOnlyList <SourceResource> sources, PackageIdentity package, bool ignoreExceptions, bool isInstalledPackage) { // No-op if the id has already been searched for // Exact versions are not added to the list since we may need to search for the full // set of packages for that id later if it becomes part of the closure later. if (package.HasVersion || _idsSearched.Add(package.Id)) { foreach (var source in sources) { // Keep track of the order in which these were made var requestId = GetNextRequestId(); var request = new GatherRequest(source, package, ignoreExceptions, requestId, isInstalledPackage); // Order is important here _gatherRequests.Enqueue(request); } } }
/// <summary> /// Retrieve already installed packages /// </summary> private async Task GatherInstalledPackagesAsync(IEnumerable <PackageIdentity> installedPackages, HashSet <string> allPrimaryTargets, CancellationToken token) { foreach (var installedPackage in installedPackages) { // Skip installed packages which are targets, this is important for upgrade and reinstall if (!allPrimaryTargets.Contains(installedPackage.Id)) { var packageInfo = await _packagesFolderResource.ResolvePackage(installedPackage, _context.TargetFramework, _context.ResolutionContext.SourceCacheContext, _context.Log, token); // Installed packages should exist, but if they do not an attempt will be made to find them in the sources. if (packageInfo != null) { // Create a request and result to match the other packages var request = new GatherRequest( source: null, package: installedPackage, ignoreExceptions: false, order: GetNextRequestId(), isInstalledPackage: true); var packages = new List <SourcePackageDependencyInfo>() { packageInfo }; var result = new GatherResult(request, packages); _results.Add(result); } else { // retrieve the package info from another source if it does not exist in local QueueWork(_allResources, installedPackage, ignoreExceptions: true, isInstalledPackage: true); } } } }
public GatherResult(GatherRequest request, IReadOnlyList <SourcePackageDependencyInfo> packages) { Request = request; Packages = packages; }
/// <summary> /// Retrieve the packages from the cache or source /// </summary> private async Task <GatherResult> GatherPackageAsync(GatherRequest request, CancellationToken token) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); token.ThrowIfCancellationRequested(); var packages = new List <SourcePackageDependencyInfo>(); GatherCacheResult cacheResult = null; var packageSource = request.Source.Source.PackageSource; // Gather packages from cache if (_cache != null) { if (request.Package.HasVersion) { cacheResult = _cache.GetPackage(packageSource, request.Package, _context.TargetFramework); } else { cacheResult = _cache.GetPackages(packageSource, request.Package.Id, _context.TargetFramework); } } if (_cache != null && cacheResult.HasEntry) { // Use cached packages _context.Log.LogDebug(string.Format("Package {0} from source {1} gathered from cache.", request.Package.Id, request.Source.Source.PackageSource.Name)); packages.AddRange(cacheResult.Packages); } else { // No cache entry exists, request it from the source try { using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token)) { // stop requests after a timeout linkedTokenSource.CancelAfter(RequestTimeout); // Gather packages from source if it was not in the cache packages = await GatherPackageFromSourceAsync( request.Package.Id, request.Package.Version, request.Source.Resource, _context.TargetFramework, request.IgnoreExceptions, linkedTokenSource.Token); // add packages to the cache if (_cache != null) { if (request.Package.HasVersion) { _cache.AddPackageFromSingleVersionLookup( packageSource, request.Package, _context.TargetFramework, packages.FirstOrDefault()); } else { _cache.AddAllPackagesForId( packageSource, request.Package.Id, _context.TargetFramework, packages); } } } } catch (TaskCanceledException ex) { if (!ex.CancellationToken.IsCancellationRequested) { string message = String.Format(Strings.UnableToGatherPackageFromSource, request.Package.Id, request.Source.Source.PackageSource.Source); throw new InvalidOperationException(message, ex); } } catch (Exception ex) when(ex is System.Net.Http.HttpRequestException || ex is OperationCanceledException || ex is TaskCanceledException) { string message = String.Format(Strings.UnableToGatherPackageFromSource, request.Package.Id, request.Source.Source.PackageSource.Source); throw new InvalidOperationException(message, ex); } // it maintain each source total time taken so far stopWatch.Stop(); _timeTaken.AddOrUpdate(request.Source.Source.PackageSource.Source, stopWatch.Elapsed, (k, v) => stopWatch.Elapsed + v); } return(new GatherResult(request, packages)); }