internal async Task <PVOutputResponse <TResponseContentType> > ExecuteSingleItemRequestAsync <TResponseContentType>(IRequest request, Dictionary <string, object> loggingScope, CancellationToken cancellationToken) { HttpResponseMessage responseMessage = null; try { using (Logger.BeginScope(loggingScope)) { using (HttpRequestMessage requestMessage = CreateRequestMessage(request)) { responseMessage = await ExecuteRequestAsync(requestMessage, cancellationToken).ConfigureAwait(false); } Stream responseStream = await GetResponseContentStreamAsync(responseMessage).ConfigureAwait(false); var result = new PVOutputResponse <TResponseContentType>(); result.ApiRateInformation = GetApiRateInformationfromResponse(responseMessage); if (ResponseIsErrorResponse(responseMessage, responseStream, result)) { return(result); } IObjectStringReader <TResponseContentType> reader = StringFactoryContainer.CreateObjectReader <TResponseContentType>(); TResponseContentType content = await reader.ReadObjectAsync(responseStream, cancellationToken).ConfigureAwait(false); result.IsSuccess = true; result.Value = content; return(result); } } finally { responseMessage.Dispose(); } }
private static async Task ReadAndAddObjectAsync(IObjectStringReader <TObjectType> objectReader, List <TObjectType> objectList, string objectContent, CancellationToken cancellationToken) { using (var reader = new StringReader(objectContent)) { TObjectType output = await objectReader.ReadObjectAsync(reader, cancellationToken).ConfigureAwait(false); objectList.Add(output); } }