public async Task <TItem> ReadItemAsync(string url) { if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) { throw new ArgumentException(nameof(url)); } var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, url); var response = await _httpService.SendAsync(httpRequestMessage); if (!response.IsSuccessStatusCode) { throw new FailedRequestException(response.StatusCode); } return(await _deserializer.DeserializeAsync <TItem>(response.Content)); }
public async Task <ICollectionPageData <TItem> > ReadPageAsync(string url) { if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) { throw new ArgumentException(nameof(url)); } var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, url); var response = await _httpService.SendAsync(httpRequestMessage); if (!response.IsSuccessStatusCode) { throw new FailedRequestException(response.StatusCode); } var items = await _deserializer.DeserializeAsync <ImmutableList <TItem> >(response.Content); response.Headers.TryGetValues("Link", out var links); return(new CollectionPageData <TItem>(items, links.FirstOrDefault())); }
public async Task <FitsDocument> ReadAsync(Stream inputStream) { var pipeReader = PipeReader.Create( inputStream, new StreamPipeReaderOptions( bufferSize: ChunkSize, minimumReadSize: ChunkSize)) !; var header = await headerDeserializer .DeserializeAsync(pipeReader) .ConfigureAwait(false); var validatorTasks = new List <Task <ValidationResult> >(); foreach (var headerValidator in headerValidators) { validatorTasks.Add(headerValidator.ValidateAsync(header)); } var validationResults = await Task.WhenAll(validatorTasks).ConfigureAwait(continueOnCapturedContext: false); foreach (var validationResult in validationResults) { if (!validationResult.ValidationSuccessful) { throw new InvalidDataException($"Validation failed for the header of the fits file: {validationResult.ValidationFailureMessage}"); } } var content = await contentDeserializer .DeserializeAsync(pipeReader, header) .ConfigureAwait(false); return(new FitsDocument( header: header, content: content)); }
static Task <T> DeserializeContentAsync <T>(IContentDeserializer deserializer, HttpContent content) { return(content == null ? Task.FromResult(default(T)) : deserializer.DeserializeAsync <T>(content)); }