public async Task <(List <PowerStanding> standings, string cycle, DateTime updated)> GetData(CancellationTokenSource cancelToken, bool ignoreCache = false) { TimeSpan expiry = TimeSpan.FromMinutes(5); if ((powerStandings?.Any() == false) || (cycle != CycleService.CurrentCycle() && (lastUpdated + expiry < DateTime.Now))) { // download the standings string csvText; DownloadService downloadService = DownloadService.Instance(); (csvText, lastUpdated) = await downloadService.GetData(URL, dataKey, lastUpdatedKey, expiry, cancelToken, ignoreCache).ConfigureAwait(false); // parse the standings powerStandings = ParseStandings(csvText); if (!string.IsNullOrWhiteSpace(powerStandings[0].Cycle)) { int p = powerStandings[0].Cycle.IndexOf(" ") + 1; Int32.TryParse(powerStandings[0].Cycle.Substring(p, powerStandings[0].Cycle.Length - p), out cycle); } else { cycle = 0; } // cache till next cycle if updated if (cycle == CycleService.CurrentCycle()) { expiry = CycleService.TimeTillTick(); Barrel.Current.Add(dataKey, csvText, expiry); Barrel.Current.Add(lastUpdatedKey, lastUpdated.ToString(), expiry); } } return(powerStandings, powerStandings[0].Cycle, lastUpdated);
public async Task <GalacticStandings> GetData(CancellationTokenSource cancelToken, bool ignoreCache = false) { TimeSpan expiry = TimeSpan.FromMinutes(15); if ((galacticStandings == null) || (galacticStandings.Cycle != CycleService.CurrentCycle() && (lastUpdated + expiry < DateTime.Now))) { // download the standings string json; DownloadService downloadService = DownloadService.Instance(); (json, lastUpdated) = await downloadService.GetData(URL, dataKey, lastUpdatedKey, expiry, cancelToken, ignoreCache).ConfigureAwait(false); // parse the standings galacticStandings = JsonConvert.DeserializeObject <GalacticStandings>(json); // cache till next cycle if updated if (galacticStandings.Cycle == CycleService.CurrentCycle()) { expiry = CycleService.TimeTillTick(); Barrel.Current.Add(dataKey, json, expiry); Barrel.Current.Add(lastUpdatedKey, lastUpdated.ToString(), expiry); } } return(galacticStandings); }