Exemplo n.º 1
0
        private async Task <SiteUpdate> FetchResource(string path)
        {
            var response = await _client.GetAsync(new Uri(new Uri("https://www.blaseball.com/"), path));

            if (!response.IsSuccessStatusCode)
            {
                _logger.Warning("Got {StatusCode} response from {Path}, returning null", response.StatusCode, path);
                return(null);
            }

            var bytes = await response.Content.ReadAsByteArrayAsync();

            var lastModifiedDto = response.Content.Headers.LastModified;
            var lastModified    = lastModifiedDto != null
                ? Instant.FromDateTimeOffset(lastModifiedDto.Value)
                : (Instant?)null;

            var update = SiteUpdate.From(_sourceId, path, _clock.GetCurrentInstant(), bytes, lastModified);

            _logger.Information("- Fetched resource {Path} (hash {Hash})", path, update.Hash);
            return(update);
        }