示例#1
0
        /// <summary>
        /// 让设计器加载指定的文档对象
        /// </summary>
        /// <param name="designer"></param>
        /// <param name="document"></param>
        public static void BindDocument(this ModelingDesigner designer, ODMLDocument document)
        {
            DocumentBinder.BindDocument(designer, document);

            //绑定新的文档时,需要清空文件路径。
            designer.ClearValue(CurrentOdmlFileProperty);
        }
示例#2
0
        /// <summary>
        /// 加载某个 xml 文件。
        /// </summary>
        /// <param name="odmlFile"></param>
        public static void LoadDocument(this ModelingDesigner designer, string odmlFile)
        {
            var xml = File.ReadAllText(odmlFile);
            var doc = string.IsNullOrEmpty(xml) ? new ODMLDocument() : ODMLDocument.Parse(xml);

            DocumentBinder.BindDocument(designer, doc);

            SetCurrentOdmlFile(designer, odmlFile);
        }
示例#3
0
        public void ListDataTest()
        {
            using (FileStream fileStream = new FileStream("ListData.json", FileMode.Create))
            {
                JsonSerializer.Serialize(fileStream, _documentBinder);
            }

            using (FileStream fileStream = new FileStream("ListData.json", FileMode.Open))
            {
                _documentBinderDeserialized = JsonSerializer.Deserialize <DocumentBinder>(fileStream);
            }

            Assert.IsNotNull(_documentBinderDeserialized);
            Assert.AreNotSame(_documentBinder, _documentBinderDeserialized);

            CollectionAssert.AreEqual(_documentBinder.Documents, _documentBinderDeserialized.Documents);
            CollectionAssert.AreEqual(_documentBinder.Aliases, _documentBinderDeserialized.Aliases);
        }
示例#4
0
        public void TestListSerialization()
        {
            using (FileStream fileStream = new FileStream("ListData.txt", FileMode.Create))
            {
                serializer.Serialize(fileStream, _documentBinder);
            }

            using (FileStream fileStream = new FileStream("ListData.txt", FileMode.Open))
            {
                _documentBinderDeserialized = (DocumentBinder)serializer.Deserialize(fileStream);
            }

            Assert.IsNotNull(_documentBinderDeserialized);
            Assert.AreNotSame(_documentBinder, _documentBinderDeserialized);

            CollectionAssert.AreEqual(_documentBinder.Documents, _documentBinderDeserialized.Documents);
            CollectionAssert.AreEqual(_documentBinder.Aliases, _documentBinderDeserialized.Aliases);
        }
示例#5
0
        public void TestInitialize()
        {
            _class1 = new Class1("Text", DateTime.Now, 3.012);
            _class2 = new Class2("Text2", DateTime.Now);
            _class3 = new Class3("Text3", DateTime.Now);

            _class1.Class2 = _class2;
            _class1.Class3 = _class3;

            _class2.Class1 = _class1;
            _class2.Class3 = _class3;

            _class3.Class1 = _class1;
            _class3.Class2 = _class2;

            List <Document> documents = new List <Document> {
                new Document(123, "342"),
                new Document(23, "sdsd")
            };

            _documentBinder = new DocumentBinder(documents, new Alias[] { new Alias("A1"), new Alias("A2") });
        }
 public PocketmodiserWindow()
 {
     InitializeComponent();
     documentBinder = new DocumentBinder();
     DataContext = documentBinder;
 }
示例#7
0
        static void Main(string[] args)
        {
            MySerializer serializer = new MySerializer();

            Console.WriteLine("Available operations: ");
            Console.WriteLine(
                "[0] Serialize graph \n[1] Deserialize graph\n" +
                "[2] Serialize list \n[3] Deserialize list\n" +
                "[4] Serialize graph to JSON\n[5] Deserialize graph from JSON\n" +
                "[6] Validate JSON (List)\n[7] Serialize List to JSON\n[8] Deserialize List from JSON\n[9] Exit");
            int choice = 0;

            Class1 class1 = new Class1("Text", DateTime.Now, 5.5);
            Class2 class2 = new Class2("Text2", DateTime.Now);
            Class3 class3 = new Class3("Text3", DateTime.Now);

            class1.Class2 = class2;
            class1.Class3 = class3;

            class3.Class1 = class1;
            class3.Class2 = class2;

            class2.Class1 = class1;
            class2.Class3 = class3;

            List <Document> documents = new List <Document>
            {
                new Document(123, "342"),
                new Document(23, "sdsd")
            };

            DocumentBinder binder = new DocumentBinder(documents, new Alias[] { new Alias("A1"), new Alias("A2") });

            while (choice != 10)
            {
                choice = Console.Read() - '0';
                switch (choice)
                {
                case 0:
                    using (FileStream fileStream = new FileStream("serializationGraph.txt", FileMode.Create))
                    {
                        serializer.Serialize(fileStream, class1);
                        Console.WriteLine("Object serialized");
                        Console.WriteLine("Path: " + Directory.GetCurrentDirectory());
                    }

                    break;

                case 1:
                    using (FileStream fileStream = new FileStream("serializationGraph.txt", FileMode.Open))
                    {
                        serializer.Deserialize(fileStream);
                        Console.WriteLine("Object deserialized");
                    }

                    break;

                case 2:
                    using (FileStream fileStream = new FileStream("serializationList.txt", FileMode.Create))
                    {
                        serializer.Serialize(fileStream, binder);
                        Console.WriteLine("Object serialized");
                        Console.WriteLine("Path: " + Directory.GetCurrentDirectory());
                    }

                    break;

                case 3:
                    using (FileStream fileStream = new FileStream("serializationList.txt", FileMode.Open))
                    {
                        serializer.Deserialize(fileStream);
                        Console.WriteLine("Object deserialized");
                    }

                    break;

                case 4:
                    using (FileStream fileStream = new FileStream("serializationGraph.json", FileMode.Create))
                    {
                        JsonSerializer.Serialize(fileStream, class1);
                        Console.WriteLine("Object serialized");
                        Console.WriteLine("Path: " + Directory.GetCurrentDirectory());
                    }

                    break;

                case 5:
                    using (FileStream fileStream = new FileStream("serializationGraph.json", FileMode.Open))
                    {
                        Class1 deserialize = JsonSerializer.Deserialize <Class1>(fileStream);
                        Console.WriteLine("Object deserialized");
                    }

                    break;

                case 6:
                    using (FileStream fileStream = new FileStream("serializationList.json", FileMode.Open))
                    {
                        string json;
                        using (StreamReader reader = new StreamReader(fileStream))
                        {
                            json = reader.ReadToEnd();
                        }

                        JSchemaGenerator generator = new JSchemaGenerator();
                        Console.WriteLine(JsonSerializer.Validate(generator.Generate(typeof(DocumentBinder)), json)
                                ? "Valid"
                                : "InValid");
                    }

                    break;

                case 7:
                    using (FileStream fileStream = new FileStream("serializationList.json", FileMode.Create))
                    {
                        JsonSerializer.Serialize(fileStream, binder);
                        Console.WriteLine("Object serialized");
                        Console.WriteLine("Path: " + Directory.GetCurrentDirectory());
                    }

                    break;

                case 8:
                    using (FileStream fileStream = new FileStream("serializationList.json", FileMode.Open))
                    {
                        DocumentBinder deserialize = JsonSerializer.Deserialize <DocumentBinder>(fileStream);
                        Console.WriteLine("Object deserialized");
                    }

                    break;

                case 9:
                    Environment.Exit(0);
                    break;
                }
            }
        }
 public DocumentBinderTests()
 {
     this.binder = new DocumentBinder(this.binderProvider);
 }