private async Task <RegistrationIndexResponse> GetInlinedRegistrationIndexOrNullAsync( IPackageMetadataClient client, string packageId, CancellationToken cancellationToken) { // Return the index directly if it is not or if all the pages are inlined. var index = await client.GetRegistrationIndexOrNullAsync(packageId, cancellationToken); if (index == null || index.Pages.All(p => p.ItemsOrNull != null)) { return(index); } // Create a new registration index response with inlined pages. var pages = new List <RegistrationIndexPage>(); foreach (var pageItem in index.Pages) { if (pageItem.ItemsOrNull == null) { var page = await client.GetRegistrationPageAsync(pageItem.RegistrationPageUrl, cancellationToken); pages.Add(page); } } return(new RegistrationIndexResponse { RegistrationIndexUrl = index.RegistrationIndexUrl, Type = index.Type, Count = index.Count, Pages = pages }); }
/// <summary> /// Initializes a new instance of the <see cref="NuGetClient"/> class. /// </summary> /// <param name="clientFactory">The factory used to create NuGet clients.</param> public NuGetClient(NuGetClientFactory clientFactory) { if (clientFactory == null) { throw new ArgumentNullException(nameof(clientFactory)); } _contentClient = clientFactory.CreatePackageContentClient(); _metadataClient = clientFactory.CreatePackageMetadataClient(); _searchClient = clientFactory.CreateSearchClient(); }
/// <summary> /// Initializes a new instance of the <see cref="NuGetClient"/> class. /// </summary> /// <param name="serviceIndexUrl"> /// The NuGet Service Index resource URL. /// /// For NuGet.org, use https://api.nuget.org/v3/index.json /// </param> public NuGetClient(string serviceIndexUrl) { var httpClient = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, }); var clientFactory = new NuGetClientFactory(httpClient, serviceIndexUrl); _contentClient = clientFactory.CreatePackageContentClient(); _metadataClient = clientFactory.CreatePackageMetadataClient(); _searchClient = clientFactory.CreateSearchClient(); }