Exemplo n.º 1
0
        internal void WriteToJson(System.Text.Json.Utf8JsonWriter writer)
        {
            //monaco.DocumentSymbol
            writer.WriteStartObject();
            writer.WriteString("name", DisplayName);
            writer.WriteString("detail", "");
            writer.WriteNumber("kind", SymbolKinds.ToMonacoKind(Kind));

            var fullRange = Ranges["full"];
            var nameRange = Ranges["name"];

            writer.WritePropertyName("range");
            fullRange.WriteToJson(writer);
            writer.WritePropertyName("selectionRange");
            nameRange.WriteToJson(writer);

            if (Children != null)
            {
                writer.WritePropertyName("children");
                writer.WriteStartArray();
                foreach (var child in Children)
                {
                    child.WriteToJson(writer);
                }
                writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }
Exemplo n.º 2
0
        protected override uint WriteHeader(System.Text.Json.Utf8JsonWriter writer, string command)
        {
            var thisId = ++currentId;

            writer.WriteNumber("id", thisId);
            writer.WriteString("command", command);
            return(thisId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The ledger_data method retrieves contents of the specified ledger.
        /// You can iterate through several calls to retrieve the entire contents of a single ledger version.
        /// </summary>
        public async Task <LedgerDataResponse> LedgerData(LedgerDataRequest request, CancellationToken cancellationToken = default)
        {
            jsonBuffer.Clear();
            jsonWriter.Reset();
            jsonWriter.WriteStartObject();
            var requestId = WriteHeader(jsonWriter, "ledger_data");

            LedgerSpecification.Write(jsonWriter, request.Ledger);
            jsonWriter.WriteBoolean("binary", true);
            if (request.Limit.HasValue)
            {
                jsonWriter.WriteNumber("limit", request.Limit.Value);
            }
            if (request.Marker.HasValue)
            {
                jsonWriter.WritePropertyName("marker");
                request.Marker.Value.WriteTo(jsonWriter);
            }
            WriteFooter(jsonWriter);
            jsonWriter.WriteEndObject();
            jsonWriter.Flush();
            var response = await SendReceiveAsync(requestId, jsonBuffer.WrittenMemory, cancellationToken);

            return(new LedgerDataResponse(response));
        }
Exemplo n.º 4
0
        private void sendState(System.Collections.Generic.Dictionary <string, object> properties)
        {
            if (coreWebView2 == null)
            {
                return;
            }

            using (var stream = new System.IO.MemoryStream())
            {
                using (var writer = new System.Text.Json.Utf8JsonWriter(stream))
                {
                    writer.WriteStartObject();
                    writer.WriteString("type", "state");
                    writer.WriteStartObject("state");

                    foreach (var pair in properties)
                    {
                        if (pair.Value == null)
                        {
                            writer.WriteNull(pair.Key);
                        }
                        else if (pair.Value is double)
                        {
                            writer.WriteNumber(pair.Key, (double)pair.Value);
                        }
                        else if (pair.Value is string)
                        {
                            writer.WriteString(pair.Key, (string)pair.Value);
                        }
                        else
                        {
                            throw new System.ArgumentException("Unsupported type for property '" + pair.Key + "'.");
                        }
                    }

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

                string json = System.Text.Encoding.UTF8.GetString(stream.ToArray());
                coreWebView2.PostWebMessageAsJson(json);
            }
        }