Ejemplo n.º 1
0
        internal async Task <PVOutputArrayResponse <TResponseContentType> > ExecuteArrayRequestAsync <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 PVOutputArrayResponse <TResponseContentType>();
                    result.ApiRateInformation = GetApiRateInformationfromResponse(responseMessage);

                    if (ResponseIsErrorResponse(responseMessage, responseStream, result))
                    {
                        return(result);
                    }

                    IArrayStringReader <TResponseContentType> reader  = StringFactoryContainer.CreateArrayReader <TResponseContentType>();
                    IEnumerable <TResponseContentType>        content = await reader.ReadArrayAsync(responseStream, cancellationToken).ConfigureAwait(false);

                    result.IsSuccess = true;
                    result.Values    = content;
                    return(result);
                }
            }
            finally
            {
                responseMessage.Dispose();
            }
        }
Ejemplo n.º 2
0
 public void StringFactoryContainer_ForTypeWithoutArrayReader_Throws()
 {
     Assert.Throws <InvalidOperationException>(() => {
         _ = StringFactoryContainer.CreateArrayReader <IStatus>();
     });
 }
Ejemplo n.º 3
0
        public void StringFactoryContainer_ForType_CreatesArrayReader()
        {
            IArrayStringReader <ISystemSearchResult> reader = StringFactoryContainer.CreateArrayReader <ISystemSearchResult>();

            Assert.That(reader, Is.TypeOf <LineDelimitedArrayStringReader <ISystemSearchResult> >());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates and executes an array reader for a given type
        /// </summary>
        /// <typeparam name="TContentResponseType"></typeparam>
        /// <param name="response">The content to create an array for</param>
        /// <returns>The returned array from the reader</returns>
        public static async Task <IEnumerable <TContentResponseType> > ExecuteArrayReaderByTypeAsync <TContentResponseType>(string response)
        {
            var reader = StringFactoryContainer.CreateArrayReader <TContentResponseType>();

            return(await reader.ReadArrayAsync(new StringReader(response)));
        }