public Task<ServiceResponse<IEnumerable<ResultFormatInformation>>> GetResultFormatsAsync() { var format = new ResultFormatInformation { DisplayName = "Excel", FileExtension = ".xlsx" }; var response = new ServiceResponse<IEnumerable<ResultFormatInformation>>(new[] { format }); return Task.FromResult(response); }
private async Task <ServiceResponse <TResponse> > CallInternalAsync <TResponse>(HttpRequestMessage request) { var json = new ResultFormatInformation { DisplayName = "Json", MimeType = "application/json", FileExtension = ".json" }; var response = await CallInternalAsync(request, new[] { json }); var result = response.Response.Single().Data.Deserialize <TResponse>(); return(new ServiceResponse <TResponse>(result, response.Headers)); }
public async Task <ServiceResponse <byte[]> > CallAsync(HttpMethod method, string requestUri, ResultFormatInformation format) { var result = await CallAsync(method, requestUri, new[] { format }); return(new ServiceResponse <byte[]>(result.Response.Data, result.Headers)); }
public async Task <ServiceResponse <byte[]> > CallAsync <TRequest>(HttpMethod method, string requestUri, TRequest requestData, ResultFormatInformation format) { var content = requestData.Serialize().Compress(); var request = new HttpRequestMessage(method, requestUri) { Content = new ByteArrayContent(content) }; request.Content.Headers.ContentEncoding.Add("gzip"); return(await CallInternalAsync(request, format)); }
public async Task <ServiceResponse <byte[]> > CallAsync(HttpMethod method, string requestUri, ResultFormatInformation format) { var request = new HttpRequestMessage(method, requestUri); return(await CallInternalAsync(request, format)); }
private async Task <ServiceResponse <byte[]> > CallInternalAsync(HttpRequestMessage request, ResultFormatInformation format) { try { if (request.Content != null) { request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); } request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(format.MimeType)); HttpResponseMessage response = await SendAsync(request); if (response.IsSuccessStatusCode) { var data = await response.Content.ReadAsByteArrayAsync(); return(new ServiceResponse <byte[]>(data, response)); } else { switch (response.StatusCode) { case HttpStatusCode.BadRequest: await ProcessBadRequestAsync(response); break; // ProcessBadRequestAsync always throws but the compiler does not detect it case HttpStatusCode.MovedPermanently: throw new MovedPermanentlyException(); case HttpStatusCode.NotFound: throw new NotFoundException(); case HttpStatusCode.Unauthorized: throw new UnauthorizedEndpointException(); } throw new PortabilityAnalyzerException(string.Format(CultureInfo.CurrentCulture, LocalizedStrings.UnknownErrorCodeMessage, response.StatusCode)); } } catch (HttpRequestException e) { throw new PortabilityAnalyzerException(LocalizedStrings.HttpExceptionMessage, e); } }