Пример #1
0
        public async IAsyncEnumerable <IInstalledPackInfo> GetCandidatePacksAsync()
        {
            int  skip      = 0;
            bool done      = false;
            int  packCount = 0;

            do
            {
                string queryString = string.Format(SearchUrlFormat, skip, _pageSize, _includePreviewPacks);
                Uri    queryUri    = new Uri(queryString);
                using (HttpClient client = new HttpClient())
                    using (HttpResponseMessage response = await client.GetAsync(queryUri).ConfigureAwait(false))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            string responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            NugetPackageSearchResult resultsForPage = JsonConvert.DeserializeObject <NugetPackageSearchResult>(responseText);

                            if (resultsForPage.Data.Count > 0)
                            {
                                skip      += _pageSize;
                                packCount += resultsForPage.Data.Count;

                                foreach (NugetPackageSourceInfo sourceInfo in resultsForPage.Data)
                                {
                                    string packageFilePath = await DownloadPackageAsync(sourceInfo).ConfigureAwait(false);

                                    if (!string.IsNullOrEmpty(packageFilePath))
                                    {
                                        NugetPackInfo packInfo = new NugetPackInfo()
                                        {
                                            VersionedPackageIdentity = sourceInfo.VersionedPackageIdentity,
                                            Id             = sourceInfo.Id,
                                            Version        = sourceInfo.Version,
                                            Path           = packageFilePath,
                                            TotalDownloads = sourceInfo.TotalDownloads
                                        };

                                        yield return(packInfo);
                                    }
                                }
                            }
                            else
                            {
                                done = true;
                            }
                        }
                        else
                        {
                            done = true;
                        }
                    }
            } while (!done && !_runOnlyOnePage);
        }
Пример #2
0
        public async Task <int> GetPackageCountAsync()
        {
            string queryString = string.Format(_searchUriFormat, 0, _pageSize);
            Uri    queryUri    = new Uri(queryString);

            using (HttpClient client = new HttpClient())
                using (HttpResponseMessage response = await client.GetAsync(queryUri).ConfigureAwait(false))
                {
                    response.EnsureSuccessStatusCode();
                    string responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    NugetPackageSearchResult resultsForPage = JsonConvert.DeserializeObject <NugetPackageSearchResult>(responseText);
                    return(resultsForPage.TotalHits);
                }
        }
Пример #3
0
        public async IAsyncEnumerable <IPackInfo> GetCandidatePacksAsync()
        {
            int  skip      = 0;
            bool done      = false;
            int  packCount = 0;

            do
            {
                string queryString = string.Format(_searchUriFormat, skip, _pageSize);
                Uri    queryUri    = new Uri(queryString);
                using (HttpClient client = new HttpClient())
                    using (HttpResponseMessage response = await client.GetAsync(queryUri).ConfigureAwait(false))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            string responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            NugetPackageSearchResult resultsForPage = JsonConvert.DeserializeObject <NugetPackageSearchResult>(responseText);

                            if (resultsForPage.Data.Count > 0)
                            {
                                skip      += _pageSize;
                                packCount += resultsForPage.Data.Count;
                                foreach (NugetPackageSourceInfo sourceInfo in resultsForPage.Data)
                                {
                                    yield return(sourceInfo);
                                }
                            }
                            else
                            {
                                done = true;
                            }
                        }
                        else
                        {
                            done = true;
                        }
                    }
            }while (!done && !_runOnlyOnePage);
        }