private void PrepareRequestWithMultipleCounters(StringBuilder pathBuilder, HttpRequestMessage request, JsonOperationContext ctx)
            {
                var uniqueNames = GetOrderedUniqueNames(out int sumLength);

                // if it is too big, we drop to POST (note that means that we can't use the HTTP cache any longer)
                // we are fine with that, such requests are going to be rare
                if (sumLength < 1024)
                {
                    foreach (var counter in uniqueNames)
                    {
                        pathBuilder.Append("&counter=").Append(Uri.EscapeDataString(counter ?? string.Empty));
                    }
                }
                else
                {
                    request.Method = HttpMethod.Post;

                    var docOps = new DocumentCountersOperation
                    {
                        DocumentId = _docId,
                        Operations = new List <CounterOperation>()
                    };

                    foreach (var counter in uniqueNames)
                    {
                        docOps.Operations.Add(new CounterOperation
                        {
                            Type        = CounterOperationType.Get,
                            CounterName = counter
                        });
                    }

                    var batch = new CounterBatch
                    {
                        Documents = new List <DocumentCountersOperation>
                        {
                            docOps
                        },
                        ReplyWithAllNodesValues = _returnFullResults
                    };

                    request.Content = new BlittableJsonContent(stream =>
                    {
                        var config = EntityToBlittable.ConvertCommandToBlittable(batch, ctx);

                        ctx.Write(stream, config);
                    });
                }
            }
Esempio n. 2
0
            private void PrepareRequestWithMultipleCounters(StringBuilder pathBuilder, HttpRequestMessage request, JsonOperationContext ctx)
            {
                var uniqueNames = new HashSet <string>(_counters);

                // if it is too big, we drop to POST (note that means that we can't use the HTTP cache any longer)
                // we are fine with that, requests to load more than 1024 counters are going to be rare
                if (uniqueNames.Sum(x => x?.Length ?? 0) < 1024)
                {
                    uniqueNames.ApplyIfNotNull(counter => pathBuilder.Append("&counter=").Append(Uri.EscapeDataString(counter ?? string.Empty)));
                }
                else
                {
                    request.Method = HttpMethod.Post;

                    var docOps = new DocumentCountersOperation
                    {
                        DocumentId = _docId,
                        Operations = new List <CounterOperation>()
                    };

                    foreach (var counter in uniqueNames)
                    {
                        docOps.Operations.Add(new CounterOperation
                        {
                            Type        = CounterOperationType.Get,
                            CounterName = counter
                        });
                    }

                    var batch = new CounterBatch
                    {
                        Documents = new List <DocumentCountersOperation>
                        {
                            docOps
                        },
                        ReplyWithAllNodesValues = _returnFullResults
                    };

                    request.Content = new BlittableJsonContent(stream =>
                    {
                        var config = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(batch, ctx);

                        ctx.Write(stream, config);
                    });
                }
            }
 public CounterBatchCommand(CounterBatch counterBatch)
 {
     _counterBatch = counterBatch ?? throw new ArgumentNullException(nameof(counterBatch));
 }
 public CounterBatchOperation(CounterBatch counterBatch)
 {
     _counterBatch = counterBatch;
 }
Esempio n. 5
0
 public CounterBatchCommand(CounterBatch counterBatch, DocumentConventions conventions)
 {
     _counterBatch = counterBatch ?? throw new ArgumentNullException(nameof(counterBatch));
     _conventions  = conventions;
 }