src/NuGetGallery/Services/JsonStatisticsService.cs
/// <summary>
/// Load a package version downloads report.
/// </summary>
/// <param name="statisticsReportName">The name of the report to load.</param>
/// <param name="packageVersionsAll">The model that should be hydrated with the report.</param>
/// <returns>The result of loading the report.</returns>
Load a package version downloads report.
Load a package version downloads report .
private async Task<StatisticsReportResult> LoadDownloadPackageVersions(
            StatisticsReportName statisticsReportName,
            List<StatisticsPackagesItemViewModel> packageVersionsAll,
            List<StatisticsPackagesItemViewModel> packageVersionsSummary)
        {
            try
            {
                var reportName = (statisticsReportName + ".json").ToLowerInvariant();
                var reportContent = await _reportService.Load(reportName);
                if (reportContent == null)
                {
                    return StatisticsReportResult.Failed;
                }
                var results = JArray.Parse(reportContent.Content).Select(item =>
                    new StatisticsPackagesItemViewModel
                    {
                        PackageId = item["PackageId"].ToString(),
                        PackageVersion = item["PackageVersion"].ToString(),
                        Downloads = item["Downloads"].Value<long>(),
                    }
                );
                packageVersionsAll.Clear();
                packageVersionsAll.AddRange(results);
                packageVersionsSummary.Clear();
                packageVersionsSummary.AddRange(packageVersionsAll.Take(10));
                return StatisticsReportResult.Success(reportContent.LastUpdatedUtc);
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return StatisticsReportResult.Failed;
            }
        }
private async Task < StatisticsReportResult > LoadDownloadPackageVersions ( StatisticsReportName statisticsReportName , List < StatisticsPackagesItemViewModel > packageVersionsAll , List < StatisticsPackagesItemViewModel > packageVersionsSummary ) { try { var reportName = ( statisticsReportName + " " ) . ToLowerInvariant ( ) ; var reportContent = await _reportService . Load ( reportName ) ; if ( reportContent == null ) { return StatisticsReportResult . Failed ; } var results = JArray . Parse ( reportContent . Content ) . Select ( item => new StatisticsPackagesItemViewModel { PackageId = item [ " " ] . ToString ( ) , PackageVersion = item [ " " ] . ToString ( ) , Downloads = item [ " " ] . Value < long > ( ) , } ) ; packageVersionsAll . Clear ( ) ; packageVersionsAll . AddRange ( results ) ; packageVersionsSummary . Clear ( ) ; packageVersionsSummary . AddRange ( packageVersionsAll . Take ( 10 ) ) ; return StatisticsReportResult . Success ( reportContent . LastUpdatedUtc ) ; } catch ( Exception e ) { QuietLog . LogHandledException ( e ) ; return StatisticsReportResult . Failed ; } }
Load a package version downloads report.
Load a package version downloads report .
The result of loading the report.
The result of loading the report .
statisticsReportName
StatisticsReportName
The name of the report to load.
The name of the report to load .
packageVersionsAll
List<StatisticsPackagesItemViewModel>
The model that should be hydrated with the report.
The model that should be hydrated with the report .
packageVersionsSummary
List<StatisticsPackagesItemViewModel>