public Task <bool> UpdatePackageAsync(Package package, Week week, PackageUpdateMilestone milestone) { switch (milestone) { case PackageUpdateMilestone.StartOfWeek: case PackageUpdateMilestone.EndOfWeek: return(this.UpdatePackageStatsAsync(package, week, milestone)); case PackageUpdateMilestone.Dependencies: return(this.UpdatePackageDependencies(package, week)); default: return(Task.FromResult(false)); } }
private async Task <bool> UpdatePackageStatsAsync(Package package, Week week, PackageUpdateMilestone milestone) { var info = await this.GetPackageStatsAsync(package, week); var stats = (milestone == PackageUpdateMilestone.EndOfWeek) ? info.PackageStatsAtEnd : info.PackageStatsAtStart; if (stats.HasBeenModified) { return(true); } this._logger.LogInformation("Updating {Milestone} stats for package {PackageName}", milestone, package.Name); var dubJson = default(DubStatsRootJson); using (var response = await this._client.GetAsync(Constants.GetPackageStatsUri(package))) { if (!response.IsSuccessStatusCode) { return(false); } dubJson = JsonSerializer.Deserialize <DubStatsRootJson>( await response.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ); } stats.Downloads = dubJson.Downloads.Weekly; stats.Forks = dubJson.Repo.Forks; stats.Issues = dubJson.Repo.Issues; stats.Stars = dubJson.Repo.Stars; stats.Watchers = dubJson.Repo.Watchers; stats.HasBeenModified = true; this._db.Update(stats); await this._db.SaveChangesAsync(); return(true); }