Ejemplo n.º 1
0
 /// <summary>
 ///     For display
 /// </summary>
 /// <returns></returns>
 internal virtual void Render(ConsoleStringBuilderInterlaced sb)
 {
     sb
     .AppendInterlacedLine("new GenericQueryPart {")
     .Up()
     .AppendInterlacedLine("QueryCommand = \"{0}\",", Prefix)
     .AppendInterlacedLine("Builder = \"{0}\",", Builder != null ? Builder.GetType().Name : "{NULL}")
     .AppendInterlaced("Parameter[{0}] = ", QueryParameters.Count());
     if (QueryParameters.Any())
     {
         sb.AppendInterlacedLine("{")
         .Up();
         foreach (var queryParameter in QueryParameters.Cast <QueryParameter>())
         {
             queryParameter.Render(sb);
             sb.AppendLine(",");
         }
         sb.Down()
         .AppendInterlacedLine("}");
     }
     else
     {
         sb.AppendLine("{}");
     }
     sb.Down()
     .AppendInterlaced("}");
     //return string.Format("{{QueryCommand = {0}, Parameter = [{1}]}}", Prefix, paraString);
 }
Ejemplo n.º 2
0
        public HttpRequestMessage BuildHttpRequestMessage(HttpHandlerOptions httpHandlerOptions, HttpMethod httpMethod, object?content)
        {
            var requestUri = !PathSegments.Any()
                ? httpHandlerOptions.RequestUri
                : new Uri(httpHandlerOptions.RequestUri, String.Join('/', PathSegments));



            if (QueryParameters.Any())
            {
                var qb = new QueryBuilder();
                if (!String.IsNullOrWhiteSpace(requestUri.Query))
                {
                    var query = QueryHelpers.ParseQuery(requestUri.Query);
                    foreach (var kv in query)
                    {
                        qb.Add(kv.Key, kv.Value.ToArray());
                    }
                }
                foreach (var kv in QueryParameters)
                {
                    qb.Add(kv.Key, kv.Value.ToArray());
                }

                var uriBuilder = new UriBuilder(requestUri);
                uriBuilder.Query = qb.ToQueryString().ToString();

                requestUri = uriBuilder.Uri;
            }



            var message = new HttpRequestMessage(httpMethod, requestUri);

            if (content != null)
            {
                message.Content = CreateHttpContent(content);
            }

            if (Headers.Any())
            {
                foreach (var kv in Headers)
                {
                    if (message.Headers.Contains(kv.Key))
                    {
                        message.Headers.Remove(kv.Key);
                    }
                    message.Headers.Add(kv.Key, kv.Value);
                }
            }


            if (!String.IsNullOrWhiteSpace(ContentType) && message.Content != null)
            {
                message.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentType);
            }

            return(message);
        }
Ejemplo n.º 3
0
        public Link WithQueryParameter(ScalarQueryParameter parameter)
        {
            if (QueryParameters.Any(p => p.Position == parameter.Position))
            {
                throw new LinkQueryParameterPositionDuplicatedException();
            }

            QueryParameters.Add(parameter);
            return(this);
        }
        private QueryWorkerParameters GetQueryWorkerParameters(int workerId, CancellationToken cancellationToken)
        {
            var parameters = QueryParameters.Any() ? QueryParameters.ElementAt(workerId) : new ParameterSet();

            return(new QueryWorkerParameters()
            {
                Iterations = Iterations,
                ConnectionString = ConnectionString,
                Query = Query,
                QueryParameters = parameters,
                CancellationToken = cancellationToken
            });
        }
        public EncodedParameters Encode()
        {
            var result = new EncodedParameters(_options, AccessToken);

            result.TimeStamp = TimeStamp.ToEpochTime();

            if (Method != null)
            {
                Logger.LogDebug("Encoding method");
                result.Method = Method;
            }

            if (Host != null)
            {
                Logger.LogDebug("Encoding host");
                result.Host = Host;
            }

            if (Path != null)
            {
                Logger.LogDebug("Encoding path");
                result.Path = Path;
            }

            if (QueryParameters != null && QueryParameters.Any())
            {
                Logger.LogDebug("Encoding query params");
                var query = new EncodingQueryParameters(_options, QueryParameters);
                result.QueryParameters = query.Encode();
            }

            if (RequestHeaders != null && RequestHeaders.Any())
            {
                Logger.LogDebug("Encoding request headers");
                var headers = new EncodingHeaderList(_options, RequestHeaders);
                result.RequestHeaders = headers.Encode();
            }

            if (Body != null)
            {
                Logger.LogDebug("Encoding body");
                result.BodyHash = CalculateBodyHash();
            }

            return(result);
        }
Ejemplo n.º 6
0
        public async Task <HttpRequestMessage> BuildHttpRequestMessage(HttpHandlerOptions httpHandlerOptions, HttpMethod httpMethod, object content)
        {
            var requestUri = String.IsNullOrWhiteSpace(Path)
                ? httpHandlerOptions.RequestUri
                : new Uri(httpHandlerOptions.RequestUri, Path);



            if (QueryParameters.Any())
            {
                var qb = new QueryBuilder();
                if (!String.IsNullOrWhiteSpace(requestUri.Query))
                {
                    var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(requestUri.Query);
                    foreach (var(key, value) in query)
                    {
                        qb.Add(key, value.ToArray());
                    }
                }
                foreach (var(key, value) in QueryParameters)
                {
                    qb.Add(key, value.ToArray());
                }

                var uriBuilder = new UriBuilder(requestUri);
                uriBuilder.Query = qb.ToQueryString().ToString();

                requestUri = uriBuilder.Uri;
            }

            var message = new HttpRequestMessage(httpMethod, requestUri);

            if (content != null)
            {
                message.Content = await CreateHttpContent(content);
            }

            if (!String.IsNullOrWhiteSpace(ContentType))
            {
                message.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentType);
            }

            return(message);
        }
Ejemplo n.º 7
0
        public List <(string, object)> GetProperties()
        {
            List <(string, object)> res = new List <(string, object)>
            {
                (HREF, HRef)
            };

            if (HttpVerb != null)
            {
                res.Add((HTTP_VERB, HttpVerb));
            }
            if (Templated != null)
            {
                res.Add((TEMPLATED, Templated));
            }

            if (!string.IsNullOrWhiteSpace(Name))
            {
                res.Add((NAME, Name));
            }
            if (!string.IsNullOrWhiteSpace(Type))
            {
                res.Add((TYPE, Type));
            }

            if (!string.IsNullOrWhiteSpace(Deprecation))
            {
                res.Add((DEPRECATION, Deprecation));
            }

            if (QueryParameters.Any())
            {
                res.Add((QUERY_PARAMETERS, QueryParameters));
            }

            return(res);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Convert a series of RestParam objects into a single query string.
 /// </summary>
 /// <returns>The RestParam objects converted to a single query string.</returns>
 private string AsQueryString()
 {
     return(QueryParameters.Any() ?
            "?" + string.Join("&", QueryParameters.Select(p => $"{Uri.EscapeUriString(p.Name)}={Uri.EscapeUriString(p.Value)}")) :
            "");
 }