public int UpdateFromHLTB(bool includeImputedTimes) { int updated = 0; lock (SyncRoot) { HttpClient client = null; Stream stream = null; StreamReader streamReader = null; try { client = new HttpClient(); stream = client.GetStreamAsync("https://www.howlongtobeatsteam.com/api/games/library/cached/all").Result; streamReader = new StreamReader(stream); using (JsonReader reader = new JsonTextReader(streamReader)) { streamReader = null; stream = null; client = null; JsonSerializer serializer = new JsonSerializer(); HLTB_RawData rawData = serializer.Deserialize <HLTB_RawData>(reader); foreach (Game game in rawData.Games) { SteamAppData steamAppData = game.SteamAppData; int id = steamAppData.SteamAppId; if (!Contains(id, out DatabaseEntry entry)) { continue; } HltbInfo info = steamAppData.HltbInfo; if (!includeImputedTimes && info.MainTtbImputed) { entry.HltbMain = 0; } else { entry.HltbMain = info.MainTtb; } if (!includeImputedTimes && info.ExtrasTtbImputed) { entry.HltbExtras = 0; } else { entry.HltbExtras = info.ExtrasTtb; } if (!includeImputedTimes && info.CompletionistTtbImputed) { entry.HltbCompletionist = 0; } else { entry.HltbCompletionist = info.CompletionistTtb; } updated++; } } } finally { streamReader?.Dispose(); stream?.Dispose(); client?.Dispose(); } LastHLTBUpdate = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); } return(updated); }
public int UpdateFromHLTB(bool includeImputedTimes) { int updated = 0; lock (SyncRoot) { using (WebClient client = new WebClient()) { string result = client.DownloadString(Constants.HowLongToBeat); if (result.Contains("An error has occurred.")) { return(updated); } HLTB_RawData rawData = JsonConvert.DeserializeObject <HLTB_RawData>(result); if (rawData == null) { return(updated); } foreach (Game game in rawData.Games) { SteamAppData steamAppData = game.SteamAppData; int id = steamAppData.SteamAppId; if (!Contains(id, out DatabaseEntry entry)) { continue; } HltbInfo info = steamAppData.HltbInfo; if (!includeImputedTimes && info.MainTtbImputed) { entry.HltbMain = 0; } else { entry.HltbMain = info.MainTtb; } if (!includeImputedTimes && info.ExtrasTtbImputed) { entry.HltbExtras = 0; } else { entry.HltbExtras = info.ExtrasTtb; } if (!includeImputedTimes && info.CompletionistTtbImputed) { entry.HltbCompletionists = 0; } else { entry.HltbCompletionists = info.CompletionistTtb; } updated++; } } LastHLTBUpdate = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); } return(updated); }