Example #1
0
        private IResponseDeserializationStrategy FindValidDeserializer(IDeserializationStrategyFactory deserializationFactory, HttpResponseMessage response)
        {
            if (deserializationFactory == null)
            {
                throw new ArgumentNullException(nameof(deserializationFactory));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            //We must try to find a serializer based on the content type header in the response
            return(deserializationFactory.DeserializerFor(response.Content.Headers.ContentType.MediaType));
        }
Example #2
0
        private IResponseDeserializationStrategy FindValidDeserializer(IDeserializationStrategyFactory deserializationFactory, IRestResponse response)
        {
            if (deserializationFactory == null)
            {
                throw new ArgumentNullException(nameof(deserializationFactory));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            //TODO: Restsharp doesn't split up content type and encoding. We need to maybe step through each value.
            //We must try to find a serializer based on the content type header in the response
            return(deserializationFactory.DeserializerFor(response.ContentType.Split(';').FirstOrDefault()));
        }
        public HttpServiceCallAsyncCallInterceptor(IRequestContextFactory requestContextFactory, IHttpServiceProxy proxyClient, ISerializationStrategyFactory serializerFactory, IDeserializationStrategyFactory deserializerFactory)
        {
            if (requestContextFactory == null)
            {
                throw new ArgumentNullException(nameof(requestContextFactory));
            }
            if (proxyClient == null)
            {
                throw new ArgumentNullException(nameof(proxyClient));
            }
            if (serializerFactory == null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }
            if (deserializerFactory == null)
            {
                throw new ArgumentNullException(nameof(deserializerFactory));
            }

            RequestContextFactory = requestContextFactory;
            ProxyClient           = proxyClient;
            SerializerFactory     = serializerFactory;
            DeserializerFactory   = deserializerFactory;
        }
Example #4
0
        /// <inheritdoc />
        public async Task <TReturnType> Send <TReturnType>(IHttpClientRequestContext requestContext, IDeserializationStrategyFactory deserializationFactory)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException(nameof(requestContext));
            }

            IRestResponse response = await SendHttpRequest(requestContext).ConfigureAwait(false);

            return(await FindValidDeserializer(deserializationFactory, response)
                   .DeserializeAsync <TReturnType>(new RestSharpResponseBodyReader(response))
                   .ConfigureAwait(false));
        }