示例#1
0
 public RequestRunner(
     ITransmissionSettings transmissionSettings,
     IAuthenticator authenticator,
     ICookieStrategy cookieStrategy,
     IArrayFormatter arrayFormatter)
 {
     this.transmissionSettings = transmissionSettings;
     this.authenticator        = authenticator;
     this.cookieStrategy       = cookieStrategy;
     this.arrayFormatter       = arrayFormatter;
 }
示例#2
0
        public string BuildRequestUrl(IArrayFormatter arrayFormatter)
        {
            if (!Resource.HasParameters || Body.ConsumesResourceParameters)
            {
                return(Resource.Path);
            }

            var queryString = Resource.GetEncodedParameters(arrayFormatter);

            return(string.Concat(Resource.Path, "?", queryString));
        }
示例#3
0
 public RequestMiddleware(
     SystemHttpClient client,
     ITransmissionSettings transmissionSettings,
     IArrayFormatter arrayFormatter,
     CookieContainer cookieContainer)
 {
     this.transmissionSettings = transmissionSettings;
     this.arrayFormatter       = arrayFormatter;
     this.cookieContainer      = cookieContainer;
     this.client = client;
 }
示例#4
0
        private IEnumerable <string> GetFormattedParameters(IArrayFormatter arrayFormatter)
        {
            if (parameters == null)
            {
                return(Enumerable.Empty <string>());
            }

            return(parameters
                   .Where(p => p.HasValue)
                   .Select(p => p.ToQueryString(arrayFormatter)));
        }
示例#5
0
        public IContent Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
        {
            if (!resource.HasParameters)
            {
                return(new ByteArrayContent(transmissionSettings.DefaultSerializerContentType, new byte[0]));
            }

            var parameters = resource.GetEncodedParameters(arrayFormatter);
            var content    = Encoding.UTF8.GetBytes(parameters);

            return(new ByteArrayContent("application/x-www-form-urlencoded", content));
        }
示例#6
0
        public RequestRunner(
            SystemHttpClient client,
            ITransmissionSettings transmissionSettings,
            IArrayFormatter arrayFormatter,
            CookieContainer cookieContainer,
            MiddlewareCollection middleware)
        {
            var defaultMiddleware = new RequestMiddleware(client, transmissionSettings, arrayFormatter, cookieContainer);

            middleware.Append(defaultMiddleware);
            middlewareHead = middleware.BuildMiddlewareChain();
        }
示例#7
0
        public string ToQueryString(IArrayFormatter arrayFormatter)
        {
            if (!HasValue)
            {
                throw new NotSupportedException($"Could not convert the parameter {Name} to a query string because it did not have a value");
            }

            if (Value is Array array)
            {
                return(arrayFormatter.FormatParameter(Name, array, ToQueryStringValue));
            }

            var value = ToQueryStringValue(Value);

            return(string.Concat(Name, "=", value));
        }
示例#8
0
        public string ToQueryString(IArrayFormatter arrayFormatter)
        {
            if (!HasValue)
            {
                throw new NotSupportedException($"Could not convert the parameter {Name} to a query string because it did not have a value");
            }

            var enumerable = Value as Array;

            if (enumerable != null)
            {
                return arrayFormatter.FormatParameter(Name, enumerable, ToQueryStringValue);
            }

            var value = ToQueryStringValue(Value);

            return string.Concat(Name, "=", value);
        }
示例#9
0
        public string ToQueryString(IArrayFormatter arrayFormatter)
        {
            if (!HasValue)
            {
                var message = string.Format(
                    "Could not convert the parameter {0} to a query string because it did not have a value", Name);

                throw new NotSupportedException(message);
            }

            var enumerable = Value as Array;

            if (enumerable != null)
            {
                return(arrayFormatter.FormatParameter(Name, enumerable, ToQueryStringValue));
            }

            var value = ToQueryStringValue(Value);

            return(string.Concat(Name, "=", value));
        }
示例#10
0
 public ISerializableBody Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
 {
     return(new MultipartMimeDocumentBody(resource, files));
 }
示例#11
0
 public IContent Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
 {
     return(new MultipartMimeContent(resource, files));
 }
示例#12
0
        public string GetEncodedParameters(IArrayFormatter arrayFormatter)
        {
            var formattedParameters = GetFormattedParameters(arrayFormatter);

            return(string.Join("&", formattedParameters));
        }
        public ISerializableBody Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
        {
            var serialized = transmissionSettings.Serialize(body);
            var content    = Encoding.UTF8.GetBytes(serialized);

            return(new SerializableByteArray(transmissionSettings.DefaultSerializerContentType, content));
        }
示例#14
0
 public ISerializableBody Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
 {
     return(new NullSerializableBody(transmissionSettings));
 }
示例#15
0
 public IContent Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
 {
     return(new NullContent(transmissionSettings));
 }
示例#16
0
        public string BuildRequestUrl(IArrayFormatter arrayFormatter)
        {
            if (!Resource.HasParameters || Body.ConsumesResourceParameters)
            {
                return Resource.Path;
            }

            var queryString = Resource.GetEncodedParameters(arrayFormatter);

            return string.Concat(Resource.Path, "?", queryString);
        }
示例#17
0
 public IContent Serialize(ITransmissionSettings transmissionSettings, IArrayFormatter arrayFormatter)
 {
     return(new StreamableContent(
                transmissionSettings.DefaultSerializerContentType,
                (stream, cancellationToken) => transmissionSettings.SerializeAsync(stream, body, cancellationToken)));
 }