Exemplo n.º 1
0
        void Test_XmlImport()
        {
            var frame       = new EmberSequence(new BerTag(BerClass.Application, 1));
            var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
            var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);

            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

            Console.WriteLine("\r\n------------------------ XML Import");
            var xml1 = GetXml(frame);

            using (var stream = new StringReader(xml1))
                using (var reader = new XmlTextReader(stream))
                {
                    var root = XmlImport.Import(reader, this);
                    var xml2 = GetXml(root);

                    Console.WriteLine(xml2);

                    Debug.Assert(xml1 == xml2);
                }
        }
Exemplo n.º 2
0
        void Test_XmlImport()
        {
            var frame       = new EmberSequence(new BerTag(BerClass.Application, 1));
            var appDefined1 = EmberApplicationInterface.CreateApplicationDefinedSet(new BerTag(BerClass.ContextSpecific, 444), 1, frame);
            var appDefined2 = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.ContextSpecific, 445), 2, appDefined1);

            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 1), -1);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 2), true);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 3), false);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 4), 12345.6789);
            appDefined2.Insert(new BerTag(BerClass.ContextSpecific, 5), "wasgehtäb?");

            Console.WriteLine("\r\n------------------------ XML Import");
            DumpXml(frame);

            var buffer = new StringBuilder();

            using (var writer = XmlWriter.Create(buffer))
                XmlExport.Export(frame, writer);

            using (var stream = new StringReader(buffer.ToString()))
                using (var reader = new XmlTextReader(stream))
                {
                    var root = XmlImport.Import(reader, this);

                    DumpXml(root);
                }
        }
Exemplo n.º 3
0
        void Test_DOM()
        {
            Console.WriteLine("\r\n------------------------ DOM");

            EmberContainer container1;
            EmberContainer frame = new EmberFrame();

            container1 = new EmberSet(new BerTag(DefaultClass, 0));
            container1.Insert(new BerTag(DefaultClass, 0), -1);
            container1.Insert(new BerTag(DefaultClass, 1), 128);
            container1.Insert(new BerTag(DefaultClass, 2), -128);
            container1.Insert(new BerTag(DefaultClass, 3), 255);
            container1.Insert(new BerTag(DefaultClass, 4), -255);
            container1.Insert(new BerTag(DefaultClass, 5), 12345);
            container1.Insert(new BerTag(DefaultClass, 6), -12345);
            container1.Insert(new BerTag(DefaultClass, 7), 16384);
            container1.Insert(new BerTag(DefaultClass, 8), -16384);
            container1.Insert(new BerTag(DefaultClass, 9), 65535);
            container1.Insert(new BerTag(DefaultClass, 10), -65535);
            container1.Insert(new BerTag(DefaultClass, 11), 0);
            container1.Insert(new BerTag(DefaultClass, 12), 127);
            container1.Insert(new BerTag(DefaultClass, 13), -127);
            container1.Insert(new BerTag(DefaultClass, 1111222), 0xFFFFFFFF);
            container1.InsertOid(new BerTag(DefaultClass, 14), new int[] { 1, 3, 6, 0 });
            container1.InsertOid(new BerTag(DefaultClass, 15), new int[] { 1 });
            container1.InsertRelativeOid(new BerTag(DefaultClass, 16), new int[] { 1, 2, 3, 4, 5, 6 });
            frame.Insert(container1);

            container1 = new EmberSequence(new BerTag(DefaultClass, 1));
            container1.Insert(new BerTag(DefaultClass, 3), -0.54321);
            container1.Insert(new BerTag(DefaultClass, 5), "Wuppdich");

            var appDefined = EmberApplicationInterface.CreateApplicationDefinedSequence(new BerTag(BerClass.Application, 889), 2, container1);

            appDefined.Insert(new BerTag(DefaultClass, 100), true);

            frame.Insert(container1);

            var xml1 = GetXml(frame);

            var output = new BerMemoryOutput();

            frame.Encode(output);

            var memory = output.ToArray();

            using (var stream = new FileStream(@"N:\Temp\test.ber", FileMode.Create, FileAccess.Write))
                stream.Write(memory, 0, memory.Length);

            var input = new BerMemoryInput(memory);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var asyncReader = new AsyncFrameReader(this);

            asyncReader.ReadBytes(output.Memory);
            var loadedFrame = asyncReader.DetachRoot();

            stopwatch.Stop();
            Console.WriteLine("load tree: {0}ms", stopwatch.ElapsedMilliseconds);

            var xml2 = GetXml(loadedFrame);

            Console.WriteLine(xml1);
            Console.WriteLine(xml2);

            Debug.Assert(xml1 == xml2);
        }