public async Task <Optional <List <Question> > > GetSince(long unixEpoch, int page, string site, string[] tags) { var throttle = _store.Read <StackexchangeThrottle>("StackexchangeThrottle"); if (Unthrottled(throttle)) { if (UnixEpoch.Now >= throttle.QuotaResetTime) { throttle.QuotaResetTime = StackexchangeThrottle.UNKNOWN; } string url = CreateUrl(unixEpoch, page, site, tags); var results = await _web.Request(url); var wrapper = JsonConvert.DeserializeObject <StackexchangeWrapper>(Encoding.UTF8.GetString(Gzip.Decompress(results.Bytes))); if (results.StatusCode == HttpStatusCode.OK) { UpdateThrottle(throttle, wrapper); _store.Write("StackexchangeThrottle", throttle); return(new Optional <List <Question> >(wrapper.Items.ToList())); } else { throttle.BackoffUntil = ForceWait2Hours(); _store.Write("StackexchangeThrottle", throttle); } } return(new Optional <List <Question> >()); }
public async Task <bool> TestQuestionsHaveValidLinks(IWebRequester web) { var result = true; var tests = QuestionsWithEitherJavaOrCSharpSince2017.Take(5).Select(async(q) => (await web.Request(q.Link)).StatusCode == HttpStatusCode.OK); result = (await Task.WhenAll(tests)).All((t) => t); return(result); }