예제 #1
0
        public virtual HttpRequest Create(FindRequest request)
        {
            Ensure.That(request, "request").IsNotNull();

            return new HttpRequest(HttpMethod.Post, GenerateRelativeUrl(request))
                .SetRequestTypeHeader(request.GetType())
                .SetJsonContent(GenerateRequestBody(request));
        }
예제 #2
0
        protected virtual string GenerateRequestBody(FindRequest request)
        {
            Ensure.That(request.SelectorExpression, "request.SelectorExpression").IsNotNullOrWhiteSpace();

            var sb = new StringBuilder();
            sb.Append("{");

            sb.AppendFormat(FormatStrings.JsonPropertyFormat, KeyNames.Selector, request.SelectorExpression);
            if(request.Limit.HasValue)
                sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.Limit, Serializer.ToJson(request.Limit.Value));
            if (request.Skip.HasValue)
                sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.Skip, Serializer.ToJson(request.Skip.Value));
            if(request.HasSortings())
                sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.Sort, Serializer.ToJsonArray(request.Sort));
            if (request.HasFields())
                sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.Fields, Serializer.ToJsonArray(request.Fields.ToArray()));
            if(request.ReadQuorum.HasValue)
                sb.AppendFormat(FormatStrings.JsonPropertyAppendFormat, KeyNames.ReadQuorum, Serializer.ToJson(request.ReadQuorum.Value));

            sb.Append("}");

            return sb.ToString();
        }
예제 #3
0
 protected virtual string GenerateRelativeUrl(FindRequest request)
 {
     return "/_find";
 }