コード例 #1
0
ファイル: program.cs プロジェクト: csdahlberg/bond
        static void Main()
        {
            // Get runtime schemas for two "versions" of Example schema. 
            // When using untagged protocols the consumer must have access to runtime schema of the data.
            var schema1 = Schema<Example1>.RuntimeSchema;
            var schema2 = Schema<Example2>.RuntimeSchema;

            // Create and cache deserializers for objects of type Example2 from payloads using the two schemas
            var deserializers = new Dictionary<string, Deserializer<SimpleBinaryReader<InputBuffer>>>
            {
                {"Example1", new Deserializer<SimpleBinaryReader<InputBuffer>>(typeof(Example2), schema1)},
                {"Example2", new Deserializer<SimpleBinaryReader<InputBuffer>>(typeof(Example2), schema2)}
            };

            // Create payload serializing an instance of Example1
            var src = new Example1
            {
                Enabled = true,
                Name = "Foo"
            };

            var output = new OutputBuffer();
            var writer = new SimpleBinaryWriter<OutputBuffer>(output);

            Serialize.To(writer, src);

            var input = new InputBuffer(output.Data);
            var reader = new SimpleBinaryReader<InputBuffer>(input);

            // Use the precreated deserializer to deserialize an instance of Example2 schema for Example1
            var dst = deserializers["Example1"].Deserialize<Example2>(reader);
            Debug.Assert(src.Enabled == dst.Enabled);
            Debug.Assert(src.Name == dst.Name);
        }
コード例 #2
0
        static void Main()
        {
            // Get runtime schemas for two "versions" of Example schema.
            // When using untagged protocols the consumer must have access to runtime schema of the data.
            var schema1 = Schema <Example1> .RuntimeSchema;
            var schema2 = Schema <Example2> .RuntimeSchema;

            // Create and cache deserializers for objects of type Example2 from payloads using the two schemas
            var deserializers = new Dictionary <string, Deserializer <SimpleBinaryReader <InputBuffer> > >
            {
                { "Example1", new Deserializer <SimpleBinaryReader <InputBuffer> >(typeof(Example2), schema1) },
                { "Example2", new Deserializer <SimpleBinaryReader <InputBuffer> >(typeof(Example2), schema2) }
            };

            // Create payload serializing an instance of Example1
            var src = new Example1
            {
                Enabled = true,
                Name    = "Foo"
            };

            var output = new OutputBuffer();
            var writer = new SimpleBinaryWriter <OutputBuffer>(output);

            Serialize.To(writer, src);

            var input  = new InputBuffer(output.Data);
            var reader = new SimpleBinaryReader <InputBuffer>(input);

            // Use the precreated deserializer to deserialize an instance of Example2 schema for Example1
            var dst = deserializers["Example1"].Deserialize <Example2>(reader);

            Debug.Assert(src.Enabled == dst.Enabled);
            Debug.Assert(src.Name == dst.Name);
        }
コード例 #3
0
 static void Main(string[] args)
 {
     Example1.Run();
     Console.WriteLine("All tests have been completed.");
     Console.ReadKey();
 }
コード例 #4
0
        static void Main(string[] args)
        {
            string exampleFileName = "";
            string exampleFileExt  = "kml";
            geKML  kml;

            Console.Write("Please type the number of example that you would like to run: ");
            string example = Console.ReadLine();

            Console.Write("Would you like to use compression? (.kmz): [y/n]");
            string kmz = Console.ReadLine();


            if (kmz.ToUpper() == "Y")
            {
                exampleFileExt = "kmz";
            }

            exampleFileName = "C:\\ge-kml_Example-" + example + "." + exampleFileExt;

            switch (example)
            {
            case "1":
                kml = Example1.RunExample(exampleFileName);
                break;

            case "2":
                kml = Example2.RunExample(exampleFileName);
                break;

            case "3":
                kml = Example3.RunExample(exampleFileName);
                break;

            case "4":
                kml = Example4.RunExample(exampleFileName);
                break;

            case "5":
                kml = Example5.RunExample(exampleFileName);
                break;

            case "6":
                kml = Example6.RunExample(exampleFileName);
                break;

            default:
                throw new Exception("Invalid Example Number");
            }

            if (exampleFileExt == "kml")
            {
                File.WriteAllBytes(exampleFileName, kml.ToKML());
                ProcessStartInfo psInfNotepad = new ProcessStartInfo("notepad.exe", exampleFileName);
                Process.Start(psInfNotepad);
            }
            else
            {
                File.WriteAllBytes(exampleFileName, kml.ToKMZ());
            }


            ProcessStartInfo psInfGE = new ProcessStartInfo(@"C:\Program Files\Google\Google Earth\client\googleearth.exe", exampleFileName);

            Process.Start(psInfGE);
        }