Пример #1
0
        public async Task Put()
        {
            var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name");

            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
            {
                var json = await context.ReadForMemoryAsync(RequestBodyStream(), name);

                var transformerDefinition = JsonDeserializationServer.TransformerDefinition(json);
                transformerDefinition.Name = name;

                var transformerId = Database.TransformerStore.CreateTransformer(transformerDefinition);

                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName(("Transformer"));
                    writer.WriteString(name);
                    writer.WriteComma();

                    writer.WritePropertyName(("TransformerId"));
                    writer.WriteInteger(transformerId);

                    writer.WriteEndObject();
                }
            }
        }
Пример #2
0
        public static void WriteIncludes(this BlittableJsonTextWriter writer, JsonOperationContext context, List <Document> includes)
        {
            writer.WriteStartObject();

            var first = true;

            foreach (var document in includes)
            {
                if (first == false)
                {
                    writer.WriteComma();
                }
                first = false;

                if (document is IncludeDocumentsCommand.ConflictDocument conflict)
                {
                    writer.WritePropertyName(conflict.Id);
                    WriteConflict(writer, conflict);
                    continue;
                }

                writer.WritePropertyName(document.Id);
                WriteDocument(writer, context, metadataOnly: false, document: document);
            }

            writer.WriteEndObject();
        }
Пример #3
0
        private void WriteDocumentsJson(DocumentsOperationContext context, bool metadataOnly, IEnumerable <Document> documentsToWrite,
                                        IncludeDocumentsCommand includeDocs, List <Document> includes)
        {
            HttpContext.Response.Headers["Content-Type"] = "application/json; charset=utf-8";
            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteStartObject();
                writer.WritePropertyName("Results");
                writer.WriteDocuments(context, documentsToWrite, metadataOnly);

                includeDocs.Fill(includes);

                writer.WriteComma();
                writer.WritePropertyName("Includes");
                if (includes.Count > 0)
                {
                    writer.WriteDocuments(context, includes, metadataOnly);
                }
                else
                {
                    writer.WriteStartArray();
                    writer.WriteEndArray();
                }

                writer.WriteEndObject();
            }
        }
Пример #4
0
        public Task Stale()
        {
            var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name");

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        var index = Database.IndexStore.GetIndex(name);
                        if (index == null)
                        {
                            IndexDoesNotExistException.ThrowFor(name);
                        }

                        var stalenessReasons = new List <string>();
                        var isStale          = index.IsStale(context, stalenessReasons: stalenessReasons);

                        writer.WriteStartObject();

                        writer.WritePropertyName("IsStale");
                        writer.WriteBool(isStale);
                        writer.WriteComma();

                        writer.WriteArray("StalenessReasons", stalenessReasons);

                        writer.WriteEndObject();
                    }

            return(Task.CompletedTask);
        }
Пример #5
0
        private async Task Send(string command, string value)
        {
            await _semaphore.WaitAsync(_cts.Token).ConfigureAwait(false);

            try
            {
                JsonOperationContext context;
                using (_requestExecutor.ContextPool.AllocateOperationContext(out context))
                    using (var writer = new BlittableJsonTextWriter(context, _ms))
                    {
                        writer.WriteStartObject();

                        writer.WritePropertyName("Command");
                        writer.WriteString(command);
                        writer.WriteComma();

                        writer.WritePropertyName("Param");
                        writer.WriteString(value);

                        writer.WriteEndObject();
                    }

                ArraySegment <byte> buffer;
                _ms.TryGetBuffer(out buffer);

                await _client.SendAsync(buffer, WebSocketMessageType.Text, endOfMessage : true, cancellationToken : _cts.Token).ConfigureAwait(false);
            }
            finally
            {
                _ms.SetLength(0);
                _semaphore.Release();
            }
        }
Пример #6
0
        public Task GetIdentities()
        {
            var start    = GetStart();
            var pageSize = GetPageSize();

            using (Database.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
                using (context.OpenReadTransaction())
                {
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();

                        var first = true;
                        foreach (var identity in Database.ServerStore.Cluster.ReadIdentities(context, Database.Name, start, pageSize))
                        {
                            if (first == false)
                            {
                                writer.WriteComma();
                            }

                            first = false;
                            writer.WritePropertyName(identity.Prefix);
                            writer.WriteInteger(identity.Value);
                        }

                        writer.WriteEndObject();
                    }
                }

            return(Task.CompletedTask);
        }
Пример #7
0
        public static void WriteFacetedQueryResult(this BlittableJsonTextWriter writer, JsonOperationContext context, FacetedQueryResult result, out int numberOfResults)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(result.TotalResults));
            writer.WriteInteger(result.TotalResults);
            writer.WriteComma();

            writer.WritePropertyName(nameof(result.DurationInMs));
            writer.WriteInteger(result.DurationInMs);
            writer.WriteComma();

            writer.WriteQueryResult(context, result, metadataOnly: false, numberOfResults: out numberOfResults, partial: true);

            writer.WriteEndObject();
        }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/certificates/replace-cluster-cert?replaceImmediately={_replaceImmediately}";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Post,
                    Content = new BlittableJsonContent(stream =>
                    {
                        using (var writer = new BlittableJsonTextWriter(ctx, stream))
                        {
                            writer.WriteStartObject();

                            writer.WritePropertyName(nameof(CertificateDefinition.Name));
                            writer.WriteString(_name.ToString());
                            writer.WriteComma();
                            writer.WritePropertyName(nameof(CertificateDefinition.Certificate));
                            writer.WriteString(Convert.ToBase64String(_certificate.Export(X509ContentType.Pfx))); // keep the private key -> this is a server cert

                            writer.WriteEndObject();
                        }
                    })
                };

                return(request);
            }
Пример #9
0
        public Task AllEnvironmentsReport()
        {
            var name = GetStringQueryString("database");

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName("DatabaseName");
                    writer.WriteString(name);
                    writer.WriteComma();

                    writer.WritePropertyName("Environments");
                    writer.WriteStartArray();
                    WriteAllEnvs(writer, context);
                    writer.WriteEndArray();

                    writer.WriteEndObject();
                }
            }

            return(Task.CompletedTask);
        }
Пример #10
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/databases/{node.Database}/attachments?id={Uri.EscapeDataString(_documentId)}&name={Uri.EscapeDataString(_name)}";
                var request = new HttpRequestMessage
                {
                    Method = HttpMethods.Get
                };

                if (_type != AttachmentType.Document)
                {
                    request.Method = HttpMethod.Post;

                    request.Content = new BlittableJsonContent(stream =>
                    {
                        using (var writer = new BlittableJsonTextWriter(_context, stream))
                        {
                            writer.WriteStartObject();

                            writer.WritePropertyName("Type");
                            writer.WriteString(_type.ToString());
                            writer.WriteComma();

                            writer.WritePropertyName("ChangeVector");
                            writer.WriteString(_changeVector);

                            writer.WriteEndObject();
                        }
                    });
                }

                return(request);
            }
Пример #11
0
        public Task GetJSAdminDebugInfo()
        {
            var detailed = GetBoolValueQueryString("detailed", required: false);

            using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("ScriptRunners");

                    writer.WriteStartArray();
                    var first = true;
                    foreach (var runnerInfo in Server.AdminScripts.GetDebugInfo(detailed ?? false))
                    {
                        if (first == false)
                        {
                            writer.WriteComma();
                        }
                        first = false;
                        using (var runnerInfoReader = context.ReadObject(runnerInfo, "runnerInfo"))
                            writer.WriteObject(runnerInfoReader);
                    }
                    writer.WriteEndArray();
                    writer.WriteEndObject();
                }
            }
            return(Task.CompletedTask);
        }
Пример #12
0
        public Task GetSegmentSummary()
        {
            var documentId = GetStringQueryString("docId");
            var name       = GetStringQueryString("name");
            var from       = GetDateTimeQueryString("from", false) ?? DateTime.MinValue;
            var to         = GetDateTimeQueryString("to", false) ?? DateTime.MaxValue;

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (context.OpenReadTransaction())
                {
                    var segmantsSummary = Database.DocumentsStorage.TimeSeriesStorage.GetSegmentsSummary(context, documentId, name, from, to);

                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Results");
                        writer.WriteStartArray();
                        var first = true;
                        foreach (var summery in segmantsSummary)
                        {
                            if (!first)
                            {
                                writer.WriteComma();
                            }
                            context.Write(writer, summery.ToJson());
                            first = false;
                        }
                        writer.WriteEndArray();
                        writer.WriteEndObject();
                    }
                }
            return(Task.CompletedTask);
        }
Пример #13
0
        public static void WriteObjects(this BlittableJsonTextWriter writer, JsonOperationContext context, IEnumerable <BlittableJsonReaderObject> objects, out int numberOfResults)
        {
            numberOfResults = 0;

            writer.WriteStartArray();

            var first = true;

            foreach (var o in objects)
            {
                numberOfResults++;

                if (first == false)
                {
                    writer.WriteComma();
                }
                first = false;

                if (o == null)
                {
                    writer.WriteNull();
                    continue;
                }

                using (o)
                {
                    writer.WriteObject(o);
                }
            }

            writer.WriteEndArray();
        }
Пример #14
0
        public Task GetSetupParameters()
        {
            AssertOnlyInSetupMode();
            var setupParameters = SetupParameters.Get(ServerStore);

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName(nameof(SetupParameters.FixedServerPortNumber));

                    if (setupParameters.FixedServerPortNumber.HasValue)
                    {
                        writer.WriteInteger(setupParameters.FixedServerPortNumber.Value);
                    }
                    else
                    {
                        writer.WriteNull();
                    }

                    writer.WriteComma();

                    writer.WritePropertyName(nameof(SetupParameters.IsDocker));
                    writer.WriteBool(setupParameters.IsDocker);

                    writer.WriteEndObject();
                }

            return(Task.CompletedTask);
        }
Пример #15
0
        public Task GetConnectionsDebugInfo()
        {
            using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("Connections");

                    writer.WriteStartArray();
                    var first = true;
                    foreach (var connection in Database.Changes.Connections)
                    {
                        if (first == false)
                        {
                            writer.WriteComma();
                        }
                        first = false;
                        context.Write(writer, connection.Value.GetDebugInfo());
                    }
                    writer.WriteEndArray();

                    writer.WriteEndObject();
                }
            return(Task.CompletedTask);
        }
Пример #16
0
        public static void WriteTermsQueryResult(this BlittableJsonTextWriter writer, JsonOperationContext context, TermsQueryResultServerSide queryResult)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(nameof(queryResult.IndexName));
            writer.WriteString(queryResult.IndexName);
            writer.WriteComma();

            writer.WritePropertyName(nameof(queryResult.ResultEtag));
            writer.WriteInteger(queryResult.ResultEtag);
            writer.WriteComma();

            writer.WriteArray(nameof(queryResult.Terms), queryResult.Terms);

            writer.WriteEndObject();
        }
Пример #17
0
        public static void Export(BlittableJsonTextWriter writer, Index index, JsonOperationContext context, bool removeAnalyzers)
        {
            if (index.Type == IndexType.Faulty)
            {
                return;
            }

            writer.WriteStartObject();

            writer.WritePropertyName(nameof(IndexDefinition.Type));
            writer.WriteString(index.Type.ToString());
            writer.WriteComma();

            writer.WritePropertyName(nameof(IndexDefinition));

            if (index.Type == IndexType.Map || index.Type == IndexType.MapReduce || index.Type == IndexType.JavaScriptMap || index.Type == IndexType.JavaScriptMapReduce)
            {
                var indexDefinition = index.GetIndexDefinition();
                writer.WriteIndexDefinition(context, indexDefinition, removeAnalyzers);
            }
            else if (index.Type == IndexType.AutoMap || index.Type == IndexType.AutoMapReduce)
            {
                index.Definition.Persist(context, writer);
            }
            else
            {
                throw new NotSupportedException(index.Type.ToString());
            }

            writer.WriteEndObject();
        }
Пример #18
0
 private void WriteOperationHeaderToRemote(BlittableJsonTextWriter writer, TcpConnectionHeaderMessage.OperationTypes operation, string databaseName)
 {
     writer.WriteStartObject();
     {
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.Operation));
         writer.WriteString(operation.ToString());
         writer.WriteComma();
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.OperationVersion));
         writer.WriteInteger(TcpConnectionHeaderMessage.GetOperationTcpVersion(operation));
         writer.WriteComma();
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.DatabaseName));
         writer.WriteString(databaseName);
     }
     writer.WriteEndObject();
     writer.Flush();
 }
Пример #19
0
 private void WriteOperationHeaderToRemote(BlittableJsonTextWriter writer)
 {
     writer.WriteStartObject();
     {
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.Operation));
         writer.WriteString(TcpConnectionHeaderMessage.OperationTypes.Heartbeats.ToString());
         writer.WriteComma();
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.OperationVersion));
         writer.WriteInteger(TcpConnectionHeaderMessage.HeartbeatsTcpVersion);
         writer.WriteComma();
         writer.WritePropertyName(nameof(TcpConnectionHeaderMessage.DatabaseName));
         writer.WriteNull();
     }
     writer.WriteEndObject();
     writer.Flush();
 }
Пример #20
0
        public async Task Allocations()
        {
            var delay = GetIntValueQueryString("delay", required: false) ?? 5;

            IReadOnlyCollection <AllocationInfo> allocations;

            using (var listener = new Expensive_GcEventListener())
            {
                await Task.Delay(TimeSpan.FromSeconds(delay));

                allocations = listener.Allocations;
            }

            using (ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();

                    var first = true;
                    foreach (var alloc in allocations.OrderByDescending(x => x.Allocations))
                    {
                        if (first == false)
                        {
                            writer.WriteComma();
                        }

                        first = false;
                        writer.WritePropertyName(alloc.Type);
                        writer.WriteString(new Size((long)alloc.Allocations, SizeUnit.Bytes).ToString());
                    }

                    writer.WriteEndObject();
                }
        }
Пример #21
0
        public Task GetDebugStats()
        {
            JsonOperationContext context;

            using (ServerStore.ContextPool.AllocateOperationContext(out context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartArray();
                    bool first = true;
                    foreach (var replication in Database.SqlReplicationLoader.Replications.Select(x => x as SqlReplication))
                    {
                        if (first == false)
                        {
                            writer.WriteComma();
                        }
                        else
                        {
                            first = false;
                        }

                        var json = new DynamicJsonValue
                        {
                            ["Name"]       = replication.ReplicationUniqueName,
                            ["Statistics"] = replication.Statistics.ToBlittable(),
                            ["Metrics"]    = replication.MetricsCountersManager.ToSqlReplicationMetricsData(),
                        };
                        context.Write(writer, json);
                    }
                    writer.WriteEndArray();
                }
            }
            return(Task.CompletedTask);
        }
        public Task HugeDocuments()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    using (context.OpenReadTransaction())
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Results");

                        writer.WriteStartArray();

                        var isFirst = true;

                        foreach (var pair in context.DocumentDatabase.HugeDocuments.GetHugeDocuments())
                        {
                            if (isFirst == false)
                            {
                                writer.WriteComma();
                            }

                            isFirst = false;

                            writer.WriteStartObject();

                            writer.WritePropertyName("Id");
                            writer.WriteString(pair.Key.Item1);

                            writer.WriteComma();

                            writer.WritePropertyName("Size");
                            writer.WriteInteger(pair.Value);

                            writer.WriteComma();

                            writer.WritePropertyName("LastAccess");
                            writer.WriteString(pair.Key.Item2.ToString("o", CultureInfo.InvariantCulture));

                            writer.WriteEndObject();
                        }

                        writer.WriteEndArray();

                        writer.WriteEndObject();
                    }

            return(Task.CompletedTask);
        }
Пример #23
0
        public Task EnvironmentReport()
        {
            var name         = GetStringQueryString("name");
            var typeAsString = GetStringQueryString("type");
            var details      = GetBoolValueQueryString("details", required: false) ?? false;

            StorageEnvironmentWithType.StorageEnvironmentType type;
            if (Enum.TryParse(typeAsString, out type) == false)
            {
                throw new InvalidOperationException("Query string value 'type' is not a valid environment type: " + typeAsString);
            }

            var env = Database.GetAllStoragesEnvironment()
                      .FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) && x.Type == type);

            if (env == null)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Task.CompletedTask);
            }

            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
            {
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName("Name");
                    writer.WriteString(env.Name);
                    writer.WriteComma();

                    writer.WritePropertyName("Type");
                    writer.WriteString(env.Type.ToString());
                    writer.WriteComma();

                    var djv = (DynamicJsonValue)TypeConverter.ToBlittableSupportedType(GetDetailedReport(env, details));
                    writer.WritePropertyName("Report");
                    writer.WriteObject(context.ReadObject(djv, env.Name));

                    writer.WriteEndObject();
                }
            }

            return(Task.CompletedTask);
        }
Пример #24
0
        protected override void PersistMapFields(JsonOperationContext context, BlittableJsonTextWriter writer)
        {
            writer.WritePropertyName(nameof(MapFields));
            writer.WriteStartArray();
            var first = true;

            foreach (var field in MapFields.Values.Select(x => x.As <AutoIndexField>()))
            {
                if (first == false)
                {
                    writer.WriteComma();
                }

                writer.WriteStartObject();

                writer.WritePropertyName(nameof(field.Name));
                writer.WriteString(field.Name);
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.Indexing));
                writer.WriteString(field.Indexing.ToString());
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.Aggregation));
                writer.WriteInteger((int)field.Aggregation);
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.Spatial));
                if (field.Spatial == null)
                {
                    writer.WriteNull();
                }
                else
                {
                    writer.WriteObject(DocumentConventions.DefaultForServer.Serialization.DefaultConverter.ToBlittable(field.Spatial, context));
                }
                writer.WriteComma();

                writer.WritePropertyName(nameof(field.HasSuggestions));
                writer.WriteBool(field.HasSuggestions);

                writer.WriteEndObject();

                first = false;
            }
            writer.WriteEndArray();
        }
Пример #25
0
        public Task GetRevisions()
        {
            var etag     = GetLongQueryString("etag", false) ?? 0;
            var pageSize = GetPageSize();

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (context.OpenReadTransaction())
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName("Revisions");
                        writer.WriteStartArray();

                        var first = true;
                        foreach (var revision in Database.DocumentsStorage.RevisionsStorage.GetRevisionsFrom(context, etag, pageSize))
                        {
                            if (first == false)
                            {
                                writer.WriteComma();
                            }
                            first = false;

                            writer.WriteStartObject();

                            writer.WritePropertyName(nameof(Document.Id));
                            writer.WriteString(revision.Id);
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(Document.Etag));
                            writer.WriteInteger(revision.Etag);
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(Document.LastModified));
                            writer.WriteDateTime(revision.LastModified, true);
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(Document.ChangeVector));
                            writer.WriteString(revision.ChangeVector);

                            writer.WriteEndObject();
                        }

                        writer.WriteEndArray();
                        writer.WriteEndObject();
                    }
            return(Task.CompletedTask);
        }
Пример #26
0
        public Task GetMigratedServerUrls()
        {
            using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (context.OpenReadTransaction())
                {
                    var documents = Database.DocumentsStorage.GetDocumentsStartingWith(
                        context, Migrator.MigrationStateKeyBase, null, null, null, 0, 64);

                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteStartObject();
                        writer.WritePropertyName(nameof(MigratedServerUrls.List));
                        writer.WriteStartArray();

                        var urls = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                        foreach (var document in documents)
                        {
                            if (document.Data.TryGet(nameof(ImportInfo.ServerUrl), out string serverUrl) == false)
                            {
                                // server url used to be saved only in the document id
                                // document id: Raven/Migration/Status/{server-version}/{database-name}/{url}
                                var splitted = document.Id.ToString()
                                               .Replace(Migrator.MigrationStateKeyBase, string.Empty)
                                               .Split("/http");

                                if (splitted.Length != 2)
                                {
                                    continue;
                                }

                                serverUrl = $"http{splitted.Last()}";
                                if (string.IsNullOrWhiteSpace(serverUrl))
                                {
                                    continue;
                                }
                            }

                            urls.Add(serverUrl);
                        }

                        var first = true;
                        foreach (var url in urls)
                        {
                            if (first == false)
                            {
                                writer.WriteComma();
                            }
                            first = false;

                            writer.WriteString(url);
                        }

                        writer.WriteEndArray();
                        writer.WriteEndObject();
                    }
                }

            return(Task.CompletedTask);
        }
        protected override void PersistFields(JsonOperationContext context, BlittableJsonTextWriter writer)
        {
            PersistMapFields(context, writer);

            writer.WriteComma();

            PersistGroupByFields(context, writer);
        }
Пример #28
0
            public DatabaseRecordActions(BlittableJsonTextWriter writer)
            {
                _writer = writer;

                _writer.WriteComma();
                _writer.WritePropertyName(nameof(DatabaseItemType.DatabaseRecord));
                _writer.WriteStartObject();
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/certificates";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(stream =>
                    {
                        using (var writer = new BlittableJsonTextWriter(ctx, stream))
                        {
                            writer.WriteStartObject();
                            writer.WritePropertyName(nameof(CertificateDefinition.Name));
                            writer.WriteString(_name.ToString());
                            writer.WriteComma();
                            writer.WritePropertyName(nameof(CertificateDefinition.Certificate));
                            writer.WriteString(Convert.ToBase64String(_certificate.Export(X509ContentType.Cert)));
                            writer.WriteComma();
                            writer.WritePropertyName(nameof(CertificateDefinition.SecurityClearance));
                            writer.WriteString(_clearance.ToString());
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(CertificateDefinition.Permissions));
                            writer.WriteStartObject();
                            bool first = true;
                            foreach (var kvp in _permissions)
                            {
                                if (first == false)
                                {
                                    writer.WriteComma();
                                }
                                first = false;

                                writer.WriteString(kvp.Key);
                                writer.WriteComma();
                                writer.WriteString(kvp.Value == DatabaseAccess.ReadWrite ? nameof(DatabaseAccess.ReadWrite) : nameof(DatabaseAccess.Admin));
                            }

                            writer.WriteEndObject();
                            writer.WriteEndObject();
                        }
                    })
                };

                return(request);
            }
Пример #30
0
            private void WriteTablesArray(string name, List <SqlMigrationTable> tables, BlittableJsonTextWriter writer)
            {
                writer.WritePropertyName(name);
                writer.WriteStartArray();

                var first = true;

                if (tables != null)
                {
                    foreach (var table in tables)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            writer.WriteComma();
                        }

                        writer.WriteStartObject();

                        writer.WritePropertyName(nameof(table.Name));
                        writer.WriteString(table.Name);
                        writer.WriteComma();

                        writer.WritePropertyName(nameof(table.Query));
                        writer.WriteString(table.Query);
                        writer.WriteComma();

                        writer.WritePropertyName(nameof(table.Patch));
                        writer.WriteString(table.Patch);
                        writer.WriteComma();

                        writer.WritePropertyName(nameof(table.NewName));
                        writer.WriteString(table.NewName);
                        writer.WriteComma();

                        WriteTablesArray(nameof(table.EmbeddedTables), table.EmbeddedTables, writer);

                        writer.WriteEndObject();
                    }
                }

                writer.WriteEndArray();
            }