public override async Task <IEnumerable <TObjectType> > ReadArrayAsync(TextReader reader, CancellationToken cancellationToken = default)
        {
            if (reader == null)
            {
                return(await Task.FromResult(default(IEnumerable <TObjectType>)).ConfigureAwait(false));
            }

            IObjectStringReader <TObjectType> objectReader = StringFactoryContainer.CreateObjectReader <TObjectType>();
            var results    = new List <TObjectType>();
            var characters = new List <char>();

            while (reader.Peek() >= 0)
            {
                var c = (char)reader.Read();

                if (c == Delimiter)
                {
                    await ReadAndAddObjectAsync(objectReader, results, new string(characters.ToArray()), cancellationToken).ConfigureAwait(false);

                    characters.Clear();
                    continue;
                }

                characters.Add(c);
            }

            if (characters.Count > 0)
            {
                await ReadAndAddObjectAsync(objectReader, results, new string(characters.ToArray()), cancellationToken).ConfigureAwait(false);
            }

            return(await Task.FromResult(results).ConfigureAwait(false));
        }
Exemplo n.º 2
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();
            }
        }
        public override async Task <IEnumerable <TObjectType> > ReadArrayAsync(TextReader reader, CancellationToken cancellationToken = default)
        {
            if (reader == null)
            {
                return(await Task.FromResult(default(IEnumerable <TObjectType>)).ConfigureAwait(false));
            }

            IObjectStringReader <TObjectType> objectReader = StringFactoryContainer.CreateObjectReader <TObjectType>();
            var results = new List <TObjectType>();

            while (reader.Peek() >= 0)
            {
                var line = reader.ReadLine();
                await ReadAndAddObjectAsync(objectReader, results, line, cancellationToken).ConfigureAwait(false);
            }

            return(await Task.FromResult(results).ConfigureAwait(false));
        }
Exemplo n.º 4
0
 public void StringFactoryContainer_ForTypeWithoutArrayReader_Throws()
 {
     Assert.Throws <InvalidOperationException>(() => {
         _ = StringFactoryContainer.CreateArrayReader <IStatus>();
     });
 }
Exemplo n.º 5
0
 public void StringFactoryContainer_ForUnknownType_Throws()
 {
     Assert.Throws <InvalidOperationException>(() => {
         _ = StringFactoryContainer.CreateObjectReader <IServiceProvider>();
     });
 }
Exemplo n.º 6
0
        public void StringFactoryContainer_ForType_CreatesArrayReader()
        {
            IArrayStringReader <ISystemSearchResult> reader = StringFactoryContainer.CreateArrayReader <ISystemSearchResult>();

            Assert.That(reader, Is.TypeOf <LineDelimitedArrayStringReader <ISystemSearchResult> >());
        }
Exemplo n.º 7
0
        public void StringFactoryContainer_ForType_CreatesObjectReader()
        {
            IObjectStringReader <IStatus> reader = StringFactoryContainer.CreateObjectReader <IStatus>();

            Assert.That(reader, Is.TypeOf <StatusObjectStringReader>());
        }
Exemplo n.º 8
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)));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates and executes an object reader for a given type
        /// </summary>
        /// <typeparam name="TContentResponseType">Interface to create a reader for</typeparam>
        /// <param name="response">The content to create an object for</param>
        /// <returns>The returned object from the reader</returns>
        public static async Task <TContentResponseType> ExecuteObjectReaderByTypeAsync <TContentResponseType>(string response)
        {
            var reader = StringFactoryContainer.CreateObjectReader <TContentResponseType>();

            return(await reader.ReadObjectAsync(new StringReader(response)));
        }
 public async Task BaseObjectReader_WithNullStream_ReturnsDefaultForType()
 {
     IObjectStringReader <IStatus> reader = StringFactoryContainer.CreateObjectReader <IStatus>();
     IStatus content = await reader.ReadObjectAsync(stream : null, cancellationToken : default).ConfigureAwait(false);