Beispiel #1
0
        internal void WriteToJson(System.Text.Json.Utf8JsonWriter writer)
        {
            writer.WritePropertyName(nameof(PartitionKeys));
            writer.WriteStartArray();
            if (PartitionKeys != null)
            {
                for (int i = 0; i < PartitionKeys.Length; i++)
                {
                    writer.WriteNumberValue(PartitionKeys[i]);
                }
            }
            writer.WriteEndArray();

            writer.WritePropertyName(nameof(ClusteringColumns));
            if (ClusteringColumns != null && ClusteringColumns.Length > 0)
            {
                writer.WriteStartArray();
                for (int i = 0; i < ClusteringColumns.Length; i++)
                {
                    writer.WriteStartObject();
                    writer.WriteNumber("MemberId", ClusteringColumns[i].MemberId);
                    writer.WriteBoolean("OrderByDesc", ClusteringColumns[i].OrderByDesc);
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }
            else
            {
                writer.WriteEmptyArray();
            }
        }
Beispiel #2
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();
        }
Beispiel #3
0
        public void NetCoreJson1()
        {
            using Stream stream             = new MemoryStream();
            using Utf8JsonWriter jsonWriter = new Utf8JsonWriter(stream);

            System.Text.Json.JsonSerializer.Serialize(jsonWriter, Model);
        }
Beispiel #4
0
 /// <summary>
 /// Serialize the internal ConcurrentDictionary to the stream.
 /// </summary>
 /// <param name="stream">Target Stream</param>
 public void Serialize(Stream stream)
 {
     using (var writer = new System.Text.Json.Utf8JsonWriter(stream))
     {
         System.Text.Json.JsonSerializer.Serialize(writer, Dictionary);
     }
 }
Beispiel #5
0
 protected override uint WriteHeader(System.Text.Json.Utf8JsonWriter writer, string command)
 {
     writer.WriteString("method", command);
     writer.WritePropertyName("params");
     writer.WriteStartArray();
     writer.WriteStartObject();
     return(0);
 }
Beispiel #6
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);
        }
Beispiel #7
0
 internal void WriteToJson(System.Text.Json.Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteNumber("startLineNumber", Start.Line + 1); //注意往前传+1,非-1
     writer.WriteNumber("startColumn", Start.Column + 1);
     writer.WriteNumber("endLineNumber", End.Line + 1);
     writer.WriteNumber("endColumn", End.Column + 1);
     writer.WriteEndObject();
 }
Beispiel #8
0
        protected Api()
        {
            jsonBuffer = new System.Buffers.ArrayBufferWriter <byte>();
            var jsonOptions = new System.Text.Json.JsonWriterOptions()
            {
                SkipValidation = true
            };

            jsonWriter = new System.Text.Json.Utf8JsonWriter(jsonBuffer, jsonOptions);
        }
        public void SetupSystemTextJsonSerializer_()
        {
            value = DataGenerator.Generate <T>();

            // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
            memoryStream          = new MemoryStream(capacity: short.MaxValue);
            memoryStream.Position = 0;
            using (var writer = new System.Text.Json.Utf8JsonWriter(memoryStream))
                System.Text.Json.JsonSerializer.Serialize(writer, value);
        }
Beispiel #10
0
 public override void Write(System.Text.Json.Utf8JsonWriter Utf8JsonWriter, System.Text.Json.JsonElement JsonElement, System.Text.Json.JsonSerializerOptions JsonSerializerOptions)
 {
     if (JsonElement.ValueKind != System.Text.Json.JsonValueKind.Undefined)
     {
         JsonElement.WriteTo(Utf8JsonWriter);
     }
     else
     {
         Utf8JsonWriter.WriteNullValue();
     }
 }
Beispiel #11
0
 public JSONResponseContent(T content)
 {
     buffer = new MemoryStream();
     using (var writer = new System.Text.Json.Utf8JsonWriter(buffer))
     {
         System.Text.Json.JsonSerializer.Serialize <T>(writer, content);
     }
     buffer.Position = 0;
     ContentLength   = buffer.Length;
     ContentType     = "application/json;charset=UTF-8;";
 }
Beispiel #12
0
        internal void _WriteJSON(System.IO.Stream sw, bool indented)
        {
            System.Text.Json.JsonWriterOptions options = default;

            options.Indented = indented;

            using (var writer = new System.Text.Json.Utf8JsonWriter(sw, options))
            {
                this.Serialize(writer);
            }
        }
Beispiel #13
0
 public override void Write(System.Text.Json.Utf8JsonWriter writer, Maybe <T> value, System.Text.Json.JsonSerializerOptions options)
 {
     if (value.HasValue)
     {
         System.Text.Json.JsonSerializer.Serialize(writer, value.Value, options);
     }
     else
     {
         writer.WriteNullValue();
     }
 }
        internal void _WriteJSON(System.IO.Stream sw, bool indented)
        {
            System.Text.Json.JsonWriterOptions options = new System.Text.Json.JsonWriterOptions()
            {
                Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
            };

            options.Indented = indented;

            using (var writer = new System.Text.Json.Utf8JsonWriter(sw, options))
            {
                this.Serialize(writer);
            }
        }
Beispiel #15
0
 internal void WriteToJson(System.Text.Json.Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteString("label", Label);
     if (!string.IsNullOrEmpty(Documentation))
     {
         writer.WritePropertyName("documentation");
         //monaco.IMarkdownString
         writer.WriteStartObject();
         writer.WriteString("value", $"**{Name}**: {Documentation}");
         writer.WriteEndObject();
     }
     writer.WriteEndObject();
 }
Beispiel #16
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.Write("\n\tWrong parameters.\n\n\tRequired parameters:\n\n\t\t\tXML documentation path(s) [...]\t\tOutput prefix\n\n");
                return(64);
            }

            string outputFile = args.Last();

            string[] xmlDocDirectories = args.Take(args.Length - 1).ToArray();

            Dictionary <string, string> xmlDocumentation = new Dictionary <string, string>();

            HashSet <string> dllFilesDocumented = new HashSet <string>();

            foreach (string directory in xmlDocDirectories)
            {
                foreach (string dll in from el in Directory.GetFiles(directory, "*.dll") select Path.GetFileName(el))
                {
                    dllFilesDocumented.Add(dll);
                }

                foreach (string xmlFile in Directory.GetFiles(directory, "*.xml"))
                {
                    XDocument doc = XDocument.Load(xmlFile);

                    foreach (XElement element in doc.Descendants("member"))
                    {
                        string name = element.Attribute("name").Value;
                        using XmlReader reader = element.CreateReader();
                        reader.MoveToContent();
                        string value = reader.ReadInnerXml();

                        xmlDocumentation[name] = value;
                    }
                }
            }

            File.WriteAllLines(outputFile + ".dll.list", dllFilesDocumented);

            using (FileStream fs = new FileStream(outputFile + ".json", FileMode.Create))
            {
                using System.Text.Json.Utf8JsonWriter writer = new System.Text.Json.Utf8JsonWriter(fs);
                System.Text.Json.JsonSerializer.Serialize <Dictionary <string, string> >(writer, xmlDocumentation);
            }

            return(0);
        }
 internal void WriteToJson(System.Text.Json.Utf8JsonWriter writer)
 {
     //对应monaco.SignatureInformation
     writer.WriteStartObject();
     writer.WriteString("label", Label);
     writer.WriteString("documentation", StructuredDocumentation.SummaryText);
     writer.WritePropertyName("parameters");
     writer.WriteStartArray();
     foreach (var item in Parameters)
     {
         item.WriteToJson(writer);
     }
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
Beispiel #18
0
        public static string SertializeJson(Scene scene)
        {
            JsonSerializer serializer = new JsonSerializer(CreateSettings(scene));

            using (MemoryStream stream = new MemoryStream())
                using (System.Text.Json.Utf8JsonWriter writer = new System.Text.Json.Utf8JsonWriter(stream, new System.Text.Json.JsonWriterOptions()
                {
                    Indented = true
                }))
                {
                    serializer.Serialize(writer, scene);
                    writer.Flush();
                    stream.Flush();
                    return(Encoding.Default.GetString(stream.ToArray()));
                }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            var m1 = new Winner3Way(
                new Outcome.Priced(1.85m),
                new Outcome.PricedWithProb(3.3m, 0.33f),
                new Outcome.Resulted(OutcomeResult.Canceled));

            Console.WriteLine($"Orig: {m1}");

            using var outputStream = new MemoryStream();
            using var output       = new Google.Protobuf.CodedOutputStream(outputStream);

            m1.FromDomain().WriteTo(output);
            output.Flush();

            var bytes = outputStream.ToArray();

            Console.WriteLine($"Protobuf Bytes Length={bytes.Length}, {BitConverter.ToString(bytes)}");

            using var inputStream = new MemoryStream(bytes);
            using var input       = new Google.Protobuf.CodedInputStream(inputStream);
            var protoCopy = new Domain.Protobuf.Winner3Way();

            protoCopy.MergeFrom(input);

            var copy = protoCopy.ToDomain();

            Console.WriteLine($"Copy: {copy}");

            using var jsonStream = new MemoryStream();
            using var jsonWriter = new System.Text.Json.Utf8JsonWriter(jsonStream);
            m1.WriteJson(jsonWriter);
            jsonWriter.Flush();
            var jsonString = Encoding.UTF8.GetString(jsonStream.ToArray());

            Console.WriteLine($"Json {jsonString}");

            var jsonDoc  = System.Text.Json.JsonDocument.Parse(jsonString);
            var jsonCopy = Json.ReadWinner3Way(jsonDoc.RootElement);

            Console.WriteLine($"Json Copy: {jsonCopy}");

            ComplexDomainDemo.Run();
        }
Beispiel #20
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);
            }
        }
        private string FormatJson(string json)
        {
            if (json == null)
            {
                return(null);
            }
            var doc = System.Text.Json.JsonDocument.Parse(Symbol.ToJson());

            using (var ms = new System.IO.MemoryStream())
            {
                using (var jw = new System.Text.Json.Utf8JsonWriter(ms, new System.Text.Json.JsonWriterOptions()
                {
                    Indented = true
                }))
                {
                    doc.WriteTo(jw);
                    jw.Flush();
                    return(Encoding.UTF8.GetString(ms.ToArray()));
                }
            }
        }
        static ClassDeserializeBenchmark()
        {
            ProtoInput = new MemoryStream();
            ProtoBuf.Serializer.Serialize(ProtoInput, IntClass.Create());

            HyperionInput   = new MemoryStream();
            HyperionSession = HyperionSerializer.GetDeserializerSession();
            HyperionSerializer.Serialize(IntClass.Create(), HyperionInput);

            // Hagar
            var services = new ServiceCollection()
                           .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly))
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <Serializer <IntClass> >();
            var bytes = new byte[1000];

            Session = services.GetRequiredService <SerializerSessionPool>().GetSession();
            var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session);

            //HagarSerializer.Serialize(ref writer, IntClass.Create());
            writer.WriteStartObject(0, typeof(IntClass), typeof(IntClass));
            Generated.Serialize(ref writer, IntClass.Create());
            writer.WriteEndObject();
            HagarInput = bytes;

            Utf8JsonInput = Utf8JsonNS.JsonSerializer.Serialize(IntClass.Create(), Utf8JsonResolver);

            var stream = new MemoryStream();

            using (var jsonWriter = new System.Text.Json.Utf8JsonWriter(stream))
            {
                System.Text.Json.JsonSerializer.Serialize <IntClass>(jsonWriter, IntClass.Create());
            }

            SystemTextJsonInput = stream.ToArray();
        }
        static StructDeserializeBenchmark()
        {
            ProtoInput = new MemoryStream();
            ProtoBuf.Serializer.Serialize(ProtoInput, IntStruct.Create());

            HyperionInput = new MemoryStream();
            HyperionSerializer.Serialize(IntStruct.Create(), HyperionInput);

            // Hagar
            var services = new ServiceCollection()
                           .AddHagar(hagar => hagar.AddAssembly(typeof(Program).Assembly))
                           .BuildServiceProvider();

            HagarSerializer = services.GetRequiredService <ValueSerializer <IntStruct> >();
            Session         = services.GetRequiredService <SerializerSessionPool>().GetSession();
            var       bytes     = new byte[1000];
            var       writer    = new SingleSegmentBuffer(bytes).CreateWriter(Session);
            IntStruct intStruct = IntStruct.Create();

            HagarSerializer.Serialize(ref intStruct, ref writer);
            HagarHandCraftedSerializer = new HagarGen_Serializer_IntStruct_1843466();
            HagarInput = bytes;

            HyperionSession = HyperionSerializer.GetDeserializerSession();

            Utf8JsonInput = Utf8JsonNS.JsonSerializer.Serialize(IntStruct.Create(), Utf8JsonResolver);

            var stream = new MemoryStream();

            using (var jsonWriter = new System.Text.Json.Utf8JsonWriter(stream))
            {
                System.Text.Json.JsonSerializer.Serialize <IntStruct>(jsonWriter, IntStruct.Create());
            }

            SystemTextJsonInput = stream.ToArray();
        }
 public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object value, System.Type inputType, System.Text.Json.JsonSerializerOptions options = null)
 {
 }
 public override void Write(System.Text.Json.Utf8JsonWriter writer, object value, System.Text.Json.JsonSerializerOptions options)
 {
 }
Beispiel #26
0
 public override void Write(System.Text.Json.Utf8JsonWriter writer, StringId value, System.Text.Json.JsonSerializerOptions options)
 {
     writer.WriteStringValue(value.Value);
 }
Beispiel #27
0
 public override void Write(System.Text.Json.Utf8JsonWriter writer, Azure.Core.Spatial.Geometry value, System.Text.Json.JsonSerializerOptions options)
 {
 }
 public static void Serialize <TValue>(System.Text.Json.Utf8JsonWriter writer, TValue value, System.Text.Json.JsonSerializerOptions options = null)
 {
 }
 public void WriteTo(System.Text.Json.Utf8JsonWriter writer)
 {
 }
Beispiel #30
0
 public override void Write(System.Text.Json.Utf8JsonWriter writer, Azure.Core.GeoJson.GeoObject value, System.Text.Json.JsonSerializerOptions options)
 {
 }