public DownloadedData(HiveConfiguration hive, string url, string storageUrl, T data) { Hive = hive; Url = url; StorageUrl = storageUrl; Data = data; }
private async Task <DownloadedData <JObject> > GetJObjectOrNullAsync(HiveConfiguration hive, string url) { if (!url.StartsWith(hive.BaseUrl)) { throw new ArgumentException("The provided URL must start with the hive base URL."); } var storageUrl = hive.StorageBaseUrl + url.Substring(hive.BaseUrl.Length); var requestId = Interlocked.Increment(ref _requestId); _logger.LogInformation("[Request {RequestId}] Fetching {Url}", requestId, storageUrl); var stopwatch = Stopwatch.StartNew(); using (var response = await _httpClient.GetAsync(storageUrl, HttpCompletionOption.ResponseContentRead)) { _logger.LogInformation( "[Request {RequestId}] Got {StatusCode} {ReasonPhrase} after {DurationMs}ms", requestId, (int)response.StatusCode, response.ReasonPhrase, (int)stopwatch.Elapsed.TotalMilliseconds); if (response.StatusCode == HttpStatusCode.NotFound) { return(new DownloadedData <JObject>(hive, url, storageUrl, null)); } response.EnsureSuccessStatusCode(); using (var stream = await response.Content.ReadAsStreamAsync()) using (var streamReader = new StreamReader(stream)) using (var jsonTextReader = new JsonTextReader(streamReader)) { jsonTextReader.DateParseHandling = DateParseHandling.None; var data = JObject.Load(jsonTextReader); return(new DownloadedData <JObject>(hive, url, storageUrl, data)); } } }
private async Task <DownloadedData <JObject> > GetIndexAsync(HiveConfiguration hive, string id) { var url = $"{hive.BaseUrl}{id}/index.json"; return(await GetJObjectOrNullAsync(hive, url)); }