Пример #1
0
        public async Task <StatisticsReportResult> LoadNuGetClientVersion()
        {
            try
            {
                var reportContent = await _reportService.Load(Reports.NuGetClientVersion.ToString() + ".json");

                if (reportContent == null)
                {
                    return(StatisticsReportResult.Failed);
                }

                JArray array = JArray.Parse(reportContent.Content);

                ((List <StatisticsNuGetUsageItem>)NuGetClientVersion).Clear();

                foreach (JObject item in array)
                {
                    ((List <StatisticsNuGetUsageItem>)NuGetClientVersion).Add(
                        new StatisticsNuGetUsageItem
                    {
                        Version   = string.Format("{0}.{1}", item["ClientMajorVersion"], item["ClientMinorVersion"]),
                        Downloads = (int)item["Downloads"]
                    });
                }

                return(StatisticsReportResult.Success(reportContent.LastUpdatedUtc));
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return(StatisticsReportResult.Failed);
            }
        }
Пример #2
0
        public async Task <StatisticsReportResult> LoadLast6Months()
        {
            try
            {
                var reportContent = await _reportService.Load(Reports.Last6Months.ToString() + ".json");

                if (reportContent == null)
                {
                    return(StatisticsReportResult.Failed);
                }

                JArray array = JArray.Parse(reportContent.Content);

                ((List <StatisticsMonthlyUsageItem>)Last6Months).Clear();

                foreach (JObject item in array)
                {
                    ((List <StatisticsMonthlyUsageItem>)Last6Months).Add(
                        new StatisticsMonthlyUsageItem
                    {
                        Year        = (int)item["Year"],
                        MonthOfYear = (int)item["MonthOfYear"],
                        Downloads   = (int)item["Downloads"]
                    });
                }

                return(StatisticsReportResult.Success(reportContent.LastUpdatedUtc));
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return(StatisticsReportResult.Failed);
            }
        }
        public async Task <StatisticsReportResult> LoadNuGetClientVersion()
        {
            try
            {
                var reportName    = (StatisticsReportName.NuGetClientVersion + ".json").ToLowerInvariant();
                var reportContent = await _reportService.Load(reportName);

                if (reportContent == null)
                {
                    return(StatisticsReportResult.Failed);
                }

                var array = JArray.Parse(reportContent.Content);
                var statisticsNuGetUsageItems = (List <StatisticsNuGetUsageItem>)NuGetClientVersion;
                statisticsNuGetUsageItems.Clear();

                foreach (JObject item in array)
                {
                    statisticsNuGetUsageItems.Add(
                        new StatisticsNuGetUsageItem
                    {
                        Version   = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", item["Major"], item["Minor"]),
                        Downloads = (int)item["Downloads"]
                    });
                }

                return(StatisticsReportResult.Success(reportContent.LastUpdatedUtc));
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return(StatisticsReportResult.Failed);
            }
        }
        public async Task <StatisticsReportResult> LoadLast6Weeks()
        {
            try
            {
                var reportName    = (StatisticsReportName.Last6Weeks + ".json").ToLowerInvariant();
                var reportContent = await _reportService.Load(reportName);

                if (reportContent == null)
                {
                    return(StatisticsReportResult.Failed);
                }

                var array = JArray.Parse(reportContent.Content);
                var statisticsMonthlyUsageItems = (List <StatisticsWeeklyUsageItem>)Last6Weeks;
                statisticsMonthlyUsageItems.Clear();

                foreach (JObject item in array)
                {
                    statisticsMonthlyUsageItems.Add(
                        new StatisticsWeeklyUsageItem
                    {
                        Year       = (int)item["Year"],
                        WeekOfYear = (int)item["WeekOfYear"],
                        Downloads  = (int)item["Downloads"]
                    });
                }

                return(StatisticsReportResult.Success(reportContent.LastUpdatedUtc));
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return(StatisticsReportResult.Failed);
            }
        }
Пример #5
0
        public async Task <StatisticsReportResult> LoadDownloadPackageVersions()
        {
            try
            {
                var reportContent = await _reportService.Load(Reports.RecentPopularityDetail.ToString() + ".json");

                if (reportContent == null)
                {
                    return(StatisticsReportResult.Failed);
                }

                JArray array = JArray.Parse(reportContent.Content);

                ((List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsAll).Clear();

                foreach (JObject item in array)
                {
                    ((List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsAll).Add(new StatisticsPackagesItemViewModel
                    {
                        PackageId          = item["PackageId"].ToString(),
                        PackageVersion     = item["PackageVersion"].ToString(),
                        Downloads          = item["Downloads"].Value <int>(),
                        PackageTitle       = GetOptionalProperty("PackageTitle", item),
                        PackageDescription = GetOptionalProperty("PackageDescription", item),
                        PackageIconUrl     = GetOptionalProperty("PackageIconUrl", item)
                    });
                }

                int count = ((List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsAll).Count;

                ((List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsSummary).Clear();

                for (int i = 0; i < Math.Min(10, count); i++)
                {
                    ((List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsSummary).Add(((List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsAll)[i]);
                }

                return(StatisticsReportResult.Success(reportContent.LastUpdatedUtc));
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return(StatisticsReportResult.Failed);
            }
        }
        public async Task <StatisticsReportResult> LoadDownloadPackageVersions()
        {
            try
            {
                var reportName    = (StatisticsReportName.RecentPopularityDetail + ".json").ToLowerInvariant();
                var reportContent = await _reportService.Load(reportName);

                if (reportContent == null)
                {
                    return(StatisticsReportResult.Failed);
                }

                var array = JArray.Parse(reportContent.Content);
                var statisticsPackagesItemViewModels = (List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsAll;
                statisticsPackagesItemViewModels.Clear();

                foreach (JObject item in array)
                {
                    statisticsPackagesItemViewModels.Add(new StatisticsPackagesItemViewModel
                    {
                        PackageId      = item["PackageId"].ToString(),
                        PackageVersion = item["PackageVersion"].ToString(),
                        Downloads      = item["Downloads"].Value <int>(),
                    });
                }

                var count = statisticsPackagesItemViewModels.Count;
                var downloadPackageVersionsSummary = (List <StatisticsPackagesItemViewModel>)DownloadPackageVersionsSummary;
                downloadPackageVersionsSummary.Clear();

                for (var i = 0; i < Math.Min(10, count); i++)
                {
                    downloadPackageVersionsSummary.Add(statisticsPackagesItemViewModels[i]);
                }

                return(StatisticsReportResult.Success(reportContent.LastUpdatedUtc));
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return(StatisticsReportResult.Failed);
            }
        }
Пример #7
0
        /// <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>
        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 <int>(),
                }
                                                                         );

                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);
            }
        }