Esempio n. 1
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/docs?id={Uri.EscapeDataString(_id)}";
                if (_skipPatchIfChangeVectorMismatch)
                {
                    url += "&skipPatchIfChangeVectorMismatch=true";
                }
                if (_returnDebugInformation)
                {
                    url += "&debug=true";
                }
                if (_test)
                {
                    url += "&test=true";
                }

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethods.Patch,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _patch).ConfigureAwait(false))
                };

                AddChangeVectorIfNotNull(_changeVector, request);
                return(request);
            }
Esempio n. 2
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/smuggler/import/csv?operationId={_operationId}&collection={_collection}";
                var form = new MultipartFormDataContent();

                if (_csvConfig != null)
                {
                    var _csvConfigBlittable = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_csvConfig, ctx);
                    form = new MultipartFormDataContent
                    {
                        { new BlittableJsonContent(async stream => { await ctx.WriteAsync(stream, _csvConfigBlittable); }), Constants.Smuggler.CsvImportOptions },
                        { new StreamContent(_stream), "file", "name" }
                    };
                }
                else
                {
                    form = new MultipartFormDataContent
                    {
                        { new StreamContent(_stream), "file", "name" }
                    };
                }

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    Content = form
                });
            }
Esempio n. 3
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/logs/configuration";

                return(new HttpRequestMessage(HttpMethod.Post, url)
                {
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_parameters, ctx)).ConfigureAwait(false))
                });
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/indexes/set-priority";

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _parameters).ConfigureAwait(false))
                });
            }
Esempio n. 5
0
                public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
                {
                    url = $"{node.Url}/databases/{node.Database}/revisions/revert";

                    return(new HttpRequestMessage
                    {
                        Method = HttpMethod.Post,
                        Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_request, ctx)).ConfigureAwait(false))
                    });
                }
Esempio n. 6
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/setup/dns-n-cert?action=claim";

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _payload).ConfigureAwait(false))
                });
            }
Esempio n. 7
0
                public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
                {
                    url = $"{node.Url}/admin/configuration/studio";

                    return(new HttpRequestMessage
                    {
                        Method = HttpMethod.Put,
                        Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _configuration).ConfigureAwait(false))
                    });
                }
Esempio n. 8
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{_databaseName}/admin/configuration/settings";
                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _configurationSettings).ConfigureAwait(false))
                };

                return(request);
            }
Esempio n. 9
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                var toggle = _disable ? "disable" : "enable";

                url = $"{node.Url}/admin/databases/{toggle}";

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _parameters).ConfigureAwait(false))
                });
            }
Esempio n. 10
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/admin/tasks/pull-replication/hub";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, ctx.ReadObject(_pullReplicationDefinition.ToJson(), "update-pull-replication-definition")).ConfigureAwait(false))
                };

                return(request);
            }
Esempio n. 11
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/admin/etl?id={_taskId}";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_configuration, ctx)).ConfigureAwait(false))
                };

                return(request);
            }
Esempio n. 12
0
        public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
        {
            url = $"{node.Url}/databases/{node.Database}/docs?id={UrlEncode(_id)}";

            var request = new HttpRequestMessage
            {
                Method  = HttpMethod.Put,
                Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _document).ConfigureAwait(false))
            };

            AddChangeVectorIfNotNull(_changeVector, request);
            return(request);
        }
Esempio n. 13
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/migrate/offline";

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        var config = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_configuration, ctx);
                        await ctx.WriteAsync(stream, config).ConfigureAwait(false);
                    })
                });
            }
Esempio n. 14
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/smuggler/export?operationId={_operationId}";

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        await ctx.WriteAsync(stream, _options).ConfigureAwait(false);
                        _tcs.TrySetResult(null);
                    })
                });
            }
Esempio n. 15
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/timeseries?docId={Uri.EscapeDataString(_documentId)}";

                return(new HttpRequestMessage
                {
                    Method = HttpMethod.Post,

                    Content = new BlittableJsonContent(async stream =>
                    {
                        var op = ctx.ReadObject(_operation.ToJson(), "convert-time-series-operation");
                        await ctx.WriteAsync(stream, op).ConfigureAwait(false);
                    })
                });
            }
        public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
        {
            url = $"{node.Url}/databases/{node.Database}/subscriptions";
            if (_id != null)
            {
                url += "?id=" + Uri.EscapeDataString(_id);
            }
            var request = new HttpRequestMessage
            {
                Method  = HttpMethod.Put,
                Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_options, ctx)).ConfigureAwait(false))
            };

            return(request);
        }
Esempio n. 17
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/timeseries/names/config";
                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        var config = ctx.ReadObject(_parameters.ToJson(), "convert time-series configuration");
                        await ctx.WriteAsync(stream, config).ConfigureAwait(false);
                    })
                };

                return(request);
            }
Esempio n. 18
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/admin/timeseries/policy?collection={Uri.EscapeDataString(_collection)}";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        var config = ctx.ReadObject(_configuration.ToJson(), "convert time-series policy");
                        await ctx.WriteAsync(stream, config).ConfigureAwait(false);
                    })
                };

                return(request);
            }
Esempio n. 19
0
                public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
                {
                    url = $"{node.Url}/databases/{node.Database}{_url}";

                    var request = new HttpRequestMessage
                    {
                        Method  = _method,
                        Content = new BlittableJsonContent(async stream =>
                        {
                            if (_payload != null)
                            {
                                await ctx.WriteAsync(stream, _payload);
                            }
                        })
                    };

                    return(request);
                }
Esempio n. 20
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/admin/transactions/start-recording";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        var parametersJson = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(new Parameters {
                            File = _filePath
                        }, ctx);
                        await ctx.WriteAsync(stream, parametersJson).ConfigureAwait(false);
                    })
                };

                return(request);
            }
Esempio n. 21
0
            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(async stream => await ctx.WriteAsync(stream, DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(batch, ctx)).ConfigureAwait(false));
                }
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/certificates/edit";

                var definition = new CertificateDefinition
                {
                    Thumbprint        = _thumbprint,
                    Permissions       = _permissions,
                    SecurityClearance = _clearance,
                    Name = _name
                };
                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(definition, ctx)).ConfigureAwait(false))
                };

                return(request);
            }
Esempio n. 23
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/smuggler/import?operationId={_operationId}";

                var form = new MultipartFormDataContent
                {
                    { new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, _options).ConfigureAwait(false)), Constants.Smuggler.ImportOptions },
                    { new StreamContentWithConfirmation(_stream, _tcs, _parent), "file", "name" }
                };

                return(new HttpRequestMessage
                {
                    Headers =
                    {
                        TransferEncodingChunked = true
                    },
                    Method = HttpMethod.Post,
                    Content = form
                });
            }
Esempio n. 24
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/admin/tasks/external-replication";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        var json = new DynamicJsonValue
                        {
                            ["Watcher"] = _newWatcher.ToJson()
                        };

                        await ctx.WriteAsync(stream, ctx.ReadObject(json, "update-replication")).ConfigureAwait(false);
                    })
                };

                return(request);
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/replication/conflicts/solver?name={_databaseName}";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Post,
                    Content = new BlittableJsonContent(async stream =>
                    {
                        var solver = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(new ConflictSolver
                        {
                            ResolveByCollection = _solver.CollectionByScript,
                            ResolveToLatest     = _solver.ResolveToLatest,
                        }, ctx);
                        await ctx.WriteAsync(stream, solver).ConfigureAwait(false);
                    })
                };

                return(request);
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/databases?name={_databaseName}";

                url += "&replicationFactor=" + _replicationFactor;
                var databaseDocument = DocumentConventions.Default.Serialization.DefaultConverter.ToBlittable(_databaseRecord, ctx);

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, databaseDocument).ConfigureAwait(false))
                };

                if (_etag.HasValue)
                {
                    request.Headers.TryAddWithoutValidation(Constants.Headers.Etag, $"\"{_etag.ToInvariantString()}\"");
                }

                return(request);
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/cmpxchg?key={Uri.EscapeDataString(_key)}&index={_index}";
                var djv = new DynamicJsonValue
                {
                    [Constants.CompareExchange.ObjectFieldName] = CompareExchangeValueBlittableJsonConverter.ConvertToBlittable(_value, _conventions, ctx)
                };

                if (_metadata != null)
                {
                    var metadata = ClusterTransactionOperationsBase.CompareExchangeSessionValue.PrepareMetadataForPut(_key, _metadata, _conventions, ctx);
                    djv[Constants.Documents.Metadata.Key] = metadata;
                }
                var blittable = ctx.ReadObject(djv, _key);

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethods.Put,
                    Content = new BlittableJsonContent(async stream => await ctx.WriteAsync(stream, blittable).ConfigureAwait(false))
                };

                return(request);
            }