private static async Task Run(Options options) { // Set up NuGet stuff sourceCache = new(); sourceRepository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); searchResource = await sourceRepository.GetResourceAsync <PackageSearchResource>(); updateResource = await sourceRepository.GetResourceAsync <PackageUpdateResource>(); findByIdResource = await sourceRepository.GetResourceAsync <FindPackageByIdResource>(); // Search for the nightly package IDs that were just built var localPackageIds = GetLocalNightlyPackageIds(options); // Search for the remotely published packages var remotePackageIds = await GetRemotePackageIds(options); // If there are differences, that means we removed/renmed something // In those cases, unist/deprecate all versions var toCompletelyUnlist = remotePackageIds.Except(localPackageIds).ToList(); foreach (var packageId in toCompletelyUnlist) { await DeleteAllVersionsOfPackage(options, packageId); } // Now for each package that exists on remote, we want to unlish the nightly versions // These are packages that are both present locally and on remote var toUnlistNightly = localPackageIds.Intersect(remotePackageIds).ToList(); foreach (var packageId in toUnlistNightly) { await DeleteAllNightlyVersionsOfPackage(options, packageId); } }
public async Task <List <PackageItem> > LoadNextPackageSet(CancellationToken token) { var list = new List <PackageItem>(); if (string.IsNullOrWhiteSpace(_uri)) { return(list); } IPackageSearchMetadata[] data; try { if (_searchResource == null) { PackageSource packageSource = new PackageSource(_uri); SourceRepository sourceRepo = new SourceRepository(packageSource, Repository.Provider.GetCoreV3()); _searchResource = await sourceRepo.GetResourceAsync <PackageSearchResource>(token); } data = (await _searchResource.SearchAsync(null, _searchFilter, _startIndex, C_QuerySize, NullLogger.Instance, token)).ToArray(); token.ThrowIfCancellationRequested(); } catch (TaskCanceledException) { return(list); } foreach (var item in data) { list.Add(new PackageItem(item)); } HasMoreData = data.Length == C_QuerySize; _startIndex += C_QuerySize; return(list); }
SearchPackagesByKeywordAsync ( string keyword, int number_of_results = 100 ) { PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); SearchFilter filter = new SearchFilter ( includePrerelease: true, new SearchFilterType { } ); IEnumerable <IPackageSearchMetadata> results = await resource.SearchAsync ( keyword, filter, skip : 0, take : number_of_results, logger, cancellationToken ); return(results); }
public static async Task SearchPackages() { // This code region is referenced by the NuGet docs. Please update the docs if you rename the region // or move it to a different file. #region SearchPackages ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); SearchFilter searchFilter = new SearchFilter(includePrerelease: true); IEnumerable <IPackageSearchMetadata> results = await resource.SearchAsync( "json", searchFilter, skip : 0, take : 20, logger, cancellationToken); foreach (IPackageSearchMetadata result in results) { Console.WriteLine($"Found package {result.Identity.Id} {result.Identity.Version}"); } #endregion }
public IEnumerable <PSResourceInfo> SearchAcrossNamesInRepository( string repositoryName, PackageSearchResource pkgSearchResource, PackageMetadataResource pkgMetadataResource, SearchFilter searchFilter, SourceCacheContext sourceContext) { foreach (string pkgName in _pkgsLeftToFind.ToArray()) { if (String.IsNullOrWhiteSpace(pkgName)) { _cmdletPassedIn.WriteDebug(String.Format("Package name: {0} provided was null or whitespace, so name was skipped in search.", pkgName == null ? "null string" : pkgName)); continue; } foreach (PSResourceInfo pkg in FindFromPackageSourceSearchAPI( repositoryName: repositoryName, pkgName: pkgName, pkgSearchResource: pkgSearchResource, pkgMetadataResource: pkgMetadataResource, searchFilter: searchFilter, sourceContext: sourceContext)) { yield return(pkg); } } }
public async Task <string> DownloadCoreToolsAsync() { //ID of the package to be looked string coreToolsId = "Microsoft.CrmSdk.CoreTools"; string dir = Path.GetDirectoryName(typeof(MyPluginControl).Assembly.Location).ToUpperInvariant(); string folder = Path.GetFileNameWithoutExtension(typeof(MyPluginControl).Assembly.Location); dir = Path.Combine(dir, folder); Directory.CreateDirectory(dir); //Connect to the official package repository IPackageRepository ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceCacheContext cache = new SourceCacheContext(); SourceRepository repository = Repository.Factory.GetCoreV3(myPlugin.options.NuGetFeed); PackageSearchResource packageSearch = await repository.GetResourceAsync <PackageSearchResource>(); FindPackageByIdResource findPackageById = await repository.GetResourceAsync <FindPackageByIdResource>(); var metadata = (await packageSearch.SearchAsync(coreToolsId, new SearchFilter(false, SearchFilterType.IsLatestVersion), 0, 1, logger, cancellationToken)).FirstOrDefault(); var version = (await metadata.GetVersionsAsync()).Max(v => v.Version); System.Diagnostics.Debug.WriteLine($"Version {version}"); using (MemoryStream packageStream = new MemoryStream()) { if (!await findPackageById.CopyNupkgToStreamAsync( coreToolsId, version, packageStream, cache, logger, cancellationToken)) { return(string.Format(Resources.Culture, Resources.CORE_TOOLS_NOT_FOUND, coreToolsId, myPlugin.options.NuGetFeed)); } using (PackageArchiveReader packageReader = new PackageArchiveReader(packageStream)) { foreach (var packageFile in await packageReader.GetFilesAsync(cancellationToken)) { System.Diagnostics.Debug.WriteLine($"{packageFile} {Path.GetDirectoryName(packageFile)} {Path.GetFileName(Path.GetDirectoryName(packageFile))}"); if (Path.GetFileName(Path.GetDirectoryName(packageFile)) == "coretools") { using (var fileStream = File.OpenWrite(Path.Combine(dir, Path.GetFileName(packageFile)))) using (var stream = await packageReader.GetStreamAsync(packageFile, cancellationToken)) { await stream.CopyToAsync(fileStream); } } } } } return(null); }
public async Task LoadNuget() { SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); packageSearch = await repository.GetResourceAsync <PackageSearchResource>(); findPackageById = await repository.GetResourceAsync <FindPackageByIdResource>(); }
public EnumeratorAsync(PackageSearchResource feedParser, string searchTerm, SearchFilter filter, ILogger logger, CancellationToken token) { _packageSearchResource = feedParser; _searchTerm = searchTerm; _filter = filter; _logger = logger; _token = token; }
public Runner() { this.source = new PackageSource(Program.Source); this.providers = Repository.Provider.GetCoreV3(); this.repository = new SourceRepository(this.source, this.providers); this.search = this.repository.GetResource <PackageSearchResource>(); this.filter = new SearchFilter(includePrerelease: true); }
public async Task <IEnumerable <IPackage> > SearchAsync(IEnumerable <IPackageSource> packageSources, string searchText, SearchOptions options = default, CancellationToken cancellationToken = default) { var(feedTerm, localTerm) = PrepareSearchTerms(searchText); log.Debug($"Searching - user text:'{searchText}'; feed query:'{feedTerm}'."); options = EnsureOptions(options); List <IPackage> result = new List <IPackage>(); List <IPackageSource> sources = new List <IPackageSource>(packageSources); List <IPackageSource> sourcesToSkip = new List <IPackageSource>(); // Try to find N results passing filter (until zero results is returned). while (result.Count < options.PageSize && options.PageIndex < PageCountToProbe) { log.Debug($"Loading page '{options.PageIndex}'."); foreach (IPackageSource packageSource in sources) { log.Debug($"Searching in '{packageSource.Uri}'."); SourceRepository repository = repositoryFactory.Create(packageSource); PackageSearchResource search = await repository.GetResourceAsync <PackageSearchResource>(cancellationToken); if (search == null) { log.Debug($"Source skipped, because it doesn't provide '{nameof(PackageSearchResource)}'."); sourcesToSkip.Add(packageSource); continue; } if (!await ApplyLocalResourceSearchAsync(result, repository, search, feedTerm, localTerm, options, cancellationToken)) { sourcesToSkip.Add(packageSource); } } options = new SearchOptions() { PageIndex = options.PageIndex + 1, PageSize = options.PageSize }; foreach (IPackageSource source in sourcesToSkip) { sources.Remove(source); } if (sources.Count == 0) { break; } } log.Debug($"Search completed. Found '{result.Count}' items."); return(result); }
public override async Task ExecuteCommandAsync() { string sourceSeparator = new string('=', _lineSeparatorLength); string packageSeparator = new string('-', _lineSeparatorLength); ILogger logger = Console; CancellationToken cancellationToken = CancellationToken.None; SearchFilter searchFilter = new SearchFilter(includePrerelease: PreRelease); IList <PackageSource> listEndpoints = GetEndpointsAsync(); foreach (PackageSource source in listEndpoints) { SourceRepository repository = Repository.Factory.GetCoreV3(source); PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); if (resource is null) { Console.WriteLine(sourceSeparator); System.Console.WriteLine($"Source: {source.Name}"); System.Console.WriteLine(packageSeparator); System.Console.WriteLine("Failed to obtain a search resource."); Console.WriteLine(packageSeparator); System.Console.WriteLine(); continue; } IEnumerable <IPackageSearchMetadata> results = await resource.SearchAsync( string.Join(" ", Arguments).Trim(), // The arguments are joined with spaces to form a single query string searchFilter, skip : 0, take : Take, logger, cancellationToken); Console.WriteLine(sourceSeparator); System.Console.WriteLine($"Source: {source.Name}"); // System.Console is used so that output is not suppressed by Verbosity.Quiet if (results.Any()) { if (Verbosity == Verbosity.Quiet) { System.Console.WriteLine(packageSeparator); } PrintResults(results); } else { System.Console.WriteLine(packageSeparator); System.Console.WriteLine("No results found."); Console.WriteLine(packageSeparator); System.Console.WriteLine(); } } }
public async Task <IEnumerable <ModuleInfo> > GetUniversalDashboardPackages(string tag, ItemType itemType) { var logger = new Log(); List <Lazy <INuGetResourceProvider> > providers = new List <Lazy <INuGetResourceProvider> >(); providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support //providers.AddRange(Repository.Provider.GetCoreV2()); // Add v2 API support PackageSource packageSource = new PackageSource("https://www.powershellgallery.com/api/v2/"); SourceRepository sourceRepository = new SourceRepository(packageSource, providers); PackageSearchResource searchResource = sourceRepository.GetResource <PackageSearchResource>(); var filter = new SearchFilter(true); int skip = 0; IEnumerable <IPackageSearchMetadata> searchMetadata; List <ModuleInfo> packageInfos = new List <ModuleInfo>(); do { searchMetadata = await searchResource.SearchAsync(tag, filter, skip, 10, logger, CancellationToken.None); if (!searchMetadata.Any()) { break; } foreach (var metadata in searchMetadata) { var packageInfo = new ModuleInfo { NuGetId = metadata.Identity.Id, Version = metadata.Identity.Version?.ToFullString(), ProjectUrl = metadata.ProjectUrl?.ToString(), Title = metadata.Title, Tags = metadata.Tags, Summary = metadata.Summary, RequireLicenseAcceptance = metadata.RequireLicenseAcceptance, Owners = metadata.Owners, Published = metadata.Published, ReportAbuseUrl = metadata.ReportAbuseUrl?.ToString(), LicenseUrl = metadata.LicenseUrl?.ToString(), IconUrl = metadata.IconUrl?.ToString(), DownloadCount = metadata.DownloadCount, Description = metadata.Description, Authors = metadata.Authors, Type = itemType }; packageInfos.Add(packageInfo); } skip += 10; } while (searchMetadata.Any()); return(packageInfos.OrderByDescending(m => m.Published)); }
public async Task <IList <T> > GetItemsForCurrentPage(CancellationToken token) { IEnumerable <IPackageSearchMetadata> result = null; if (_searchText?.StartsWith("id:", StringComparison.OrdinalIgnoreCase) == true) { var id = _searchText.Substring(3).Trim(); if (!string.IsNullOrEmpty(id)) { var findPackageByIdResource = await _sourceRepository.GetResourceAsync <PackageMetadataResource>(); var metadata = await findPackageByIdResource.GetMetadataAsync(id, _searchFilter.IncludePrerelease, true, NullSourceCacheContext.Instance, NullLogger.Instance, token); result = metadata.OrderByDescending(m => m.Identity.Version).Take(1); } else { result = Enumerable.Empty <IPackageSearchMetadata>(); } } else { if (_packageSearchResouce == null && _rawPackageSearchResouce == null) { _rawPackageSearchResouce = await _sourceRepository.GetResourceAsync <RawSearchResourceV3>(token); } if (_rawPackageSearchResouce != null) { var json = await _rawPackageSearchResouce.Search(_searchText, _searchFilter, _pageIndex *_pageSize, _pageSize, NullLogger.Instance, token); result = json.Select(s => s.FromJToken <PackageSearchMetadata>()); } if (result == null) { if (_packageSearchResouce == null) { _packageSearchResouce = await _sourceRepository.GetResourceAsync <PackageSearchResource>(token); } result = await _packageSearchResouce.SearchAsync(_searchText, _searchFilter, _pageIndex *_pageSize, _pageSize, NullLogger.Instance, token); } } token.ThrowIfCancellationRequested(); var list = result.Cast <T>().ToList(); if (list.Count < _pageSize) { _lastPageIndex = _pageIndex; _lastPageCount = list.Count; } return(list); }
private async Task LoadVersionsEagerIfNeedAsync(PackageSearchResource searchResource, IEnumerable <IPackageSearchMetadata> packages) { if (searchResource is PackageSearchResourceV2Feed) { foreach (var package in packages) { await V2SearchHelper.GetVersionsMetadataAsync(package); } } }
public async Task <IEnumerable <IPackageSearchMetadata> > GetPackagesMetaDataFullSearchAsync(SearchFilter searchFilter) { _logger.DEBUG($"started performing full search for packages metadata from the providers, using V3 and V2 protocols"); var sourceRepository = GetSourceRepository(); PackageSearchResource searchResource = await sourceRepository.GetResourceAsync <PackageSearchResource>(); return(await searchResource.SearchAsync(_configuration.packageID, searchFilter, 0, 10, null, CancellationToken.None)); }
SearchPackagesByKeywordAsync ( string keyword, SearchFilter search_filter = null, int skip = 0, int take = 100, // Func<IPackageSearchMetadata, bool> filter Predicate <IPackageSearchMetadata> filter = null ) { if (null == search_filter) { search_filter = new SearchFilter(true); } if (null == filter) { } PackageSearchResource resource = null; IEnumerable <IPackageSearchMetadata> results = null; resource = await repository.GetResourceAsync <PackageSearchResource>(); // https://apisof.net/catalog/NuGet.Protocol.Core.Types.IPackageSearchMetadata // https://apisof.net/catalog/NuGet.Protocol.Core.Types.SearchFilter // https://github.com/NuGet/Home/issues/8719 // https://apisof.net/catalog/NuGet.Protocol.Core.Types.PackageSearchResource.SearchAsync(String,SearchFilter,Int32,Int32,ILogger,CancellationToken) // search_filter_type // https://scm.mbwarez.dk/tools/nuget-package-overview/blob/3dab8c9ba3d9d65c52d9036d4695e91eb6ee169a/NugetOverview/Program.cs // https://128.39.141.180/justworks/playground/blob/168480a22f353c250ed0276af21e9b1993f40032/InternalDevTools/GitHooks/Resharper/NuGet.Protocol.xml // https://aakinshin.net/posts/rider-nuget-search/ // https://devblogs.microsoft.com/nuget/improved-search-syntax/ results = await resource.SearchAsync ( keyword, search_filter, skip : 0, take : 1000, logger, cancellationToken ); IEnumerable <IPackageSearchMetadata> results_filtered = null; results_filtered = from IPackageSearchMetadata psm in results where filter(psm) select psm; return(results); }
private static async Task GetAllPackages(int skip, int take, PackageSearchResource searchResource, IEnumerable <SourceRepository> repositories, ILogger logger, ISet <PackageIdentity> availablePackages, CancellationToken cancelToken) { var metadatas = await searchResource.SearchAsync(null, new SearchFilter(false), skip, take, logger, cancelToken); var nuGetFramework = NuGetFramework.AnyFramework; foreach (var metadata in metadatas) { var id = metadata.Identity.Id; var versions = await metadata.GetVersionsAsync(); foreach (var version in versions) { var package = new PackageIdentity(id, new NuGetVersion(version.Version)); if (!availablePackages.Contains(package)) { using (var cacheContext = new SourceCacheContext()) { availablePackages.Add(package); await GetDependenciesAsync(package, nuGetFramework, cacheContext, logger, repositories, availablePackages, cancelToken); } } } } var count = metadatas.Count(); if (count == take) { skip = skip + take; await GetAllPackages(skip, take, searchResource, repositories, logger, availablePackages, cancelToken); } }
public async Task <object> DownloadCoreToolsAsync(string nugetSource) { //ID of the package to be looked string coreToolsId = "Microsoft.CrmSdk.CoreTools"; string dir = GetToolDirectory(); //Connect to the official package repository IPackageRepository ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceCacheContext cache = new SourceCacheContext(); SourceRepository repository = Repository.Factory.GetCoreV3(nugetSource); PackageSearchResource packageSearch = await repository.GetResourceAsync <PackageSearchResource>(); FindPackageByIdResource findPackageById = await repository.GetResourceAsync <FindPackageByIdResource>(); var metadata = (await packageSearch.SearchAsync(coreToolsId, new SearchFilter(false, SearchFilterType.IsLatestVersion), 0, 1, logger, cancellationToken)).FirstOrDefault(); var version = (await metadata.GetVersionsAsync()).Max(v => v.Version); using (MemoryStream packageStream = new MemoryStream()) { if (!await findPackageById.CopyNupkgToStreamAsync( coreToolsId, version, packageStream, cache, logger, cancellationToken)) { return(string.Format(Resources.Culture, Resources.CORE_TOOLS_NOT_FOUND, coreToolsId, nugetSource)); } using (PackageArchiveReader packageReader = new PackageArchiveReader(packageStream)) { foreach (var packageFile in await packageReader.GetFilesAsync(cancellationToken)) { if (Path.GetFileName(Path.GetDirectoryName(packageFile)) == "coretools") { using (var fileStream = File.OpenWrite(Path.Combine(dir, Path.GetFileName(packageFile)))) using (var stream = await packageReader.GetStreamAsync(packageFile, cancellationToken)) { await stream.CopyToAsync(fileStream); } } } } } return(GetSolutionPackagerVersion(dir)); }
/// <summary> /// Constructor /// </summary> /// <param name="packageSource">package source</param> /// <param name="destinationPath">destination path where the packages should be downloaded</param> internal NuGetPackageDownloader(string packageSource, string destinationPath) { _logger = new Logger(); _providers = new List <Lazy <INuGetResourceProvider> >(); _providers.AddRange(Repository.Provider.GetCoreV3()); _packageSource = new PackageSource(packageSource); _sourceRepository = new SourceRepository(_packageSource, _providers); _searchResource = _sourceRepository.GetResource <PackageSearchResource>(); _settings = Settings.LoadDefaultSettings(destinationPath); _project = new FolderNuGetProject(destinationPath); _packageManager = new NuGetPackageManager(new SourceRepositoryProvider(new PackageSourceProvider(_settings), _providers), _settings, destinationPath); _projectContext = new ProjectContext(_logger); _searchFilter = new SearchFilter(true, SearchFilterType.IsAbsoluteLatestVersion); _resolutionContext = new ResolutionContext(NuGet.Resolver.DependencyBehavior.Ignore, false, false, VersionConstraints.None); _secondarySources = new List <SourceRepository>(); }
public async Task <IEnumerable <IPackageSearchMetadata> > Search(string searchTerm) { List <Lazy <INuGetResourceProvider> > providers = new List <Lazy <INuGetResourceProvider> >(); providers.AddRange(Repository.Provider.GetCoreV3()); PackageSource packageSource = new PackageSource("https://api.nuget.org/v3/index.json"); SourceRepository sourceRepository = new SourceRepository(packageSource, providers); NuGet.Common.ILogger logger = new NullLogger(); PackageSearchResource searchResource = await sourceRepository.GetResourceAsync <PackageSearchResource>(); IEnumerable <IPackageSearchMetadata> searchMetadata = await searchResource.SearchAsync(searchTerm, new SearchFilter(), 0, 10, logger, CancellationToken.None); return(searchMetadata); }
public async Task <IEnumerable <string> > SearchPackageAsync(string searchPackageName, string repositoryUrl, bool includePrerelease) { ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceCacheContext cache = new SourceCacheContext(); SourceRepository repository = Repository.Factory.GetCoreV3(repositoryUrl); PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); SearchFilter searchFilter = new SearchFilter(includePrerelease: includePrerelease); IEnumerable <IPackageSearchMetadata> results = await resource.SearchAsync( searchPackageName, searchFilter, skip : 0, take : 10, logger, cancellationToken); return(results.Select(x => x.Identity.Id).AsEnumerable <string>()); }
public static async Task <List <IPackageSearchMetadata> > SearchPackages(string packageKeyword, string source, bool includePrerelease) { ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceRepository repository = Repository.Factory.GetCoreV3(source); PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); SearchFilter searchFilter = new SearchFilter(includePrerelease: includePrerelease); IEnumerable <IPackageSearchMetadata> results = await resource.SearchAsync( packageKeyword, searchFilter, skip : 0, take : 35, logger, cancellationToken); return(results.ToList()); }
private IEnumerable <IPackageInfo> GetPackagesFromRepository(string searchTerm, string repositoryUrl) { var packages = new Dictionary <string, ImmutableSortedSet <string> .Builder>(new InsensitiveStringComparer()); var previousPackageVersions = ImmutableSortedSet.CreateBuilder <string>(new InsensitiveOpositeStringComparer()); string previousPackageId = string.Empty; PackageSearchResource resource = BuildSearchResource(repositoryUrl); var searchResult = resource.SearchAsync( searchTerm, new SearchFilter(true, null) { OrderBy = null }, 0, 10, new Logger(texoLogger), CancellationToken.None).Result; foreach (IPackageSearchMetadata metadata in searchResult) { if (!string.Equals(previousPackageId, metadata.Identity.Id, StringComparison.OrdinalIgnoreCase)) { previousPackageId = metadata.Identity.Id; if (!packages.TryGetValue(previousPackageId, out previousPackageVersions)) { previousPackageVersions = ImmutableSortedSet.CreateBuilder <string>(new InsensitiveOpositeStringComparer()); packages[previousPackageId] = previousPackageVersions; } } if (metadata.Identity.HasVersion) { previousPackageVersions.Add(metadata.Identity.Version.ToNormalizedString()); } } foreach (var packagePair in packages) { yield return(new PackageInfo(packagePair.Key, packagePair.Value.ToImmutable())); } }
public async Task <IList <PackageInfo> > Search(string name) { IList <PackageInfo> packages = new List <PackageInfo>(); ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); SearchFilter filter = new SearchFilter(includePrerelease: false); IEnumerable <IPackageSearchMetadata> results = await resource.SearchAsync( name, filter, skip : 0, take : 20, logger, cancellationToken); foreach (IPackageSearchMetadata result in results) { packages.Add(new PackageInfo(result.Identity.Id, result.Identity.Version.ToString(), result.Description, null)); } return(packages); }
public static async IAsyncEnumerable <IPackageSearchMetadata> SearchPackagesByIdAsync( this PackageSearchResource searchResource, string packageId, bool includePrerelease, NuGet.Common.ILogger?logger, int batchSize = 50, [EnumeratorCancellation] CancellationToken cancellationToken = default ) { var skip = 0; while (true) { var metadataBatch = (await searchResource.SearchAsync( $"packageId:{packageId}", filters: new SearchFilter(includePrerelease: includePrerelease), skip: skip, take: batchSize, logger, cancellationToken )) .ToList(); foreach (var metadata in metadataBatch) { yield return(metadata); } if (metadataBatch.Count == batchSize) { // There may be more... skip += batchSize; } else { yield break; } } }
private static async Task <PackageIdentity> FindPackageAsync( string packageSearch, IReadOnlyCollection <SourceRepository> repositories, ILogger nugetLogger) { var results = await Task.WhenAll(repositories .Select(async repository => { PackageSearchResource searchResource = await repository.GetResourceAsync <PackageSearchResource>(); var searchResults = await searchResource.SearchAsync( packageSearch, new SearchFilter(includePrerelease: false), 0, 10, nugetLogger, CancellationToken.None ); var exactMatch = searchResults.FirstOrDefault( package => package.Identity.Id.Equals(packageSearch, StringComparison.OrdinalIgnoreCase) ); return(exactMatch?.Identity); }) ); return(results.FirstOrDefault(result => result != null)); }
public async Task SearchPackagesAsync(string searchstring) { ILogger logger = NullLogger.Instance; CancellationToken cancellationToken = CancellationToken.None; SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); PackageSearchResource resource = await repository.GetResourceAsync <PackageSearchResource>(); SearchFilter searchFilter = new SearchFilter(includePrerelease: true); results = await resource.SearchAsync( searchstring, searchFilter, skip : 0, take : 20, logger, cancellationToken); foreach (IPackageSearchMetadata result in results) { Console.WriteLine($"Found package {result.Identity.Id} {result.Identity.Version}"); } }
public async Task <IList <T> > GetItemsForCurrentPage(CancellationToken token) { IEnumerable <IPackageSearchMetadata> result = null; if (_packageSearchResouce == null && _rawPackageSearchResouce == null) { _rawPackageSearchResouce = await _sourceRepository.GetResourceAsync <RawSearchResourceV3>(token); } if (_rawPackageSearchResouce != null) { var json = await _rawPackageSearchResouce.Search(_searchText, _searchFilter, _pageIndex *_pageSize, _pageSize, NullLogger.Instance, token); result = json.Select(s => s.FromJToken <PackageSearchMetadata>()); } if (result == null) { if (_packageSearchResouce == null) { _packageSearchResouce = await _sourceRepository.GetResourceAsync <PackageSearchResource>(token); } result = await _packageSearchResouce.SearchAsync(_searchText, _searchFilter, _pageIndex *_pageSize, _pageSize, NullLogger.Instance, token); } token.ThrowIfCancellationRequested(); var list = result.Cast <T>().ToList(); if (list.Count < _pageSize) { _lastPageIndex = _pageIndex; _lastPageCount = list.Count; } return(list); }
/// <summary> /// This method gets the latest version of the package that is compatible with /// The target framework of the project provided. /// </summary> /// <param name="packageId">The nuget package to be installed</param> /// <param name="sourceRepository">The <see cref="SourceRepository"/> to use.</param> /// <param name="projectTargetVersion">The version of net framework/.netcore that the project targets.</param> /// <returns>The <see cref="NuGetVersion"/> of the package</returns> private async Task <NuGetVersion> GetPackageLatestNugetVersionAsync( string packageId, SourceRepository sourceRepository, string projectTargetFramework) { NuGetVersion packageVersion = null; PackageSearchResource searchResource = await sourceRepository.GetResourceAsync <PackageSearchResource>(); string[] targetProjectFrameworks = new[] { projectTargetFramework }; SearchFilter searchFilter = new SearchFilter(false) { SupportedFrameworks = targetProjectFrameworks }; IEnumerable <IPackageSearchMetadata> jsonNugetPackages = await searchResource .SearchAsync(packageId, searchFilter, 0, 10, new Logger(this.messageLogger), CancellationToken.None); //The first one is the latest package that is compatible with the supported framework IPackageSearchMetadata jsonPackage = jsonNugetPackages.First(); packageVersion = NuGetVersion.Parse(jsonPackage.Identity.Version.ToString()); return(packageVersion); }
public NuGetPackageEnumerator(PackageSearchResource packageSearchResource, ILogger logger) { _packageSearchResource = packageSearchResource; _logger = logger; }
public LocalPackageListResource(PackageSearchResource localPackageSearchResource, string baseAddress) { _localPackageSearchResource = localPackageSearchResource; _baseAddress = baseAddress; }