Esempio n. 1
0
        //收集各个item(TextBox/RadioButton)的值生成ConfTree
        public virtual ConfTree Generate(string tag = null)
        {
            var conf = new ConfTree(GetType().Name);

            Traverse(Controls, (control) =>
            {
                if (control is TextBox)
                {
                    var tb = control as TextBox;
                    conf.Add(new ConfItem(tb.Name, tb.Text));
                }
                else if (control is ComboBox)
                {
                    var cb = control as ComboBox;
                    conf.Add(new ConfItem(cb.Name, cb.Text));
                }
                else if (control is RadioButton)
                {
                    var rb = control as RadioButton;
                    if (rb.Checked)
                    {
                        var values = rb.Name.Split('_');
                        var name   = values[0];
                        var value  = values[1];
                        var item   = new ConfItem(name, value);
                        item.Attributes.Add("guitype", "RadioButton");
                        conf.Add(item);
                    }
                }
            });

            CurrentConf = conf;

            return(conf);
        }
        public void TestConfNodeEditor_AddNode_ToTagParent()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/DefaultSpec.xml");

            conf.Save($@"{GlobalVar.ResultPath}\root.xml");
            conf = Builder.Xml.Generate($@"{GlobalVar.ResultPath}\root.xml");

            var node = conf.Find(@"Specs/BR", new List <string>()
            {
                "HighTemp"
            });

            Assert.IsTrue(node == null);

            ConfTree newnode = new ConfTree("BR");

            newnode.Add(new ConfItem("Max", "10"));
            newnode.Add(new ConfItem("Min", "0"));
            var tree = conf.GetItem(@"HighTemp:Specs") as ConfTree;

            tree.AddNode(newnode);
            conf.Save();

            conf = Builder.Xml.Generate($@"{GlobalVar.ResultPath}\root.xml");
            node = conf.Find(@"Specs/BR", new List <string>()
            {
                "HighTemp"
            });
            Assert.IsTrue(node != null);
        }
Esempio n. 3
0
        public void TestConfTree_Clone_Modify_Save()
        {
            ConfTree conf1 = Builder.Generate(new Dictionary <string, string> {
                { "Item1", "Value1" },
                { "Item2", "Value2" },
            }, "DictionaryConf");

            Builder.Xml.Save(conf1, $"{GlobalVar.ResultPath}/Conf.xml");
            GlobalVar.Log.Debug(conf1.ShowAll());

            ConfTree conf2 = conf1.Clone("new") as ConfTree;

            Builder.Xml.Save(conf2 as ConfTree);

            conf1["Item1"] = "Value3";
            Builder.Xml.Save(conf1 as ConfTree);

            Debug.WriteLine(conf2.ToString());
            conf2["Item2"] = "Value4";
            Builder.Xml.Save(conf2 as ConfTree);

            ConfTree readback = Builder.Xml.Generate($"{GlobalVar.ResultPath}/Conf.xml");

            Debug.WriteLine(readback.ToString());
            JbAssert.Equal(readback["Default:Item1"], "Value3");
            JbAssert.Equal(readback["Default:Item2"], "Value2");
            JbAssert.Equal(readback["new:Item1"], "Value1");
            JbAssert.Equal(readback["new:Item2"], "Value4");
        }
Esempio n. 4
0
        public void TestConfTree_AddMixToTree2()
        {
            ConfTree tree1 = new ConfTree("Tree1");

            tree1.Add(new ConfItem("Item1-1", "Value1-1"));

            ConfTree tree2 = new ConfTree("Tree2");

            tree2.Add(new ConfItem("Item2-1", "Value2-1"));
            tree2.Add(new ConfItem("Item2-2", "Value2-2"));

            ConfTree tree3 = new ConfTree("Tree3");

            tree3.Add(new ConfItem("Item3-1", "Value3-1"));
            tree3.Add(new ConfItem("Item3-2", "Value3-2"));

            tree1.Add(tree2);
            tree2.Add(tree3);

            Assert.IsTrue(tree1.Find("Item1-1").Path == "/Tree1");
            Assert.IsTrue(tree1.Find("Tree2").Path == "/Tree1");
            Assert.IsTrue(tree1.Find("Item2-1").Path == "/Tree1/Tree2");
            Assert.IsTrue(tree1.Find("Tree3").Path == "/Tree1/Tree2");
            Assert.IsTrue(tree1.Find("Item3-1").Path == "/Tree1/Tree2/Tree3");
            Assert.IsTrue(tree1.Find("Item3-2").Path == "/Tree1/Tree2/Tree3");

            GlobalVar.Log.Debug(tree1.ShowAll());
        }
Esempio n. 5
0
        public void TestConfTreeFind_Conflict()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/MultiLevel.xml");

            GlobalVar.Log.Debug(conf.ShowAll());

            JbAssert.Equal(conf[@"Level1/Item"], "1.0");
            JbAssert.Equal(conf[@"Level1/Item1"], "1.1");
            JbAssert.Equal(conf[@"Level2/Item"], "2.0");
            JbAssert.Equal(conf[@"Level2/Item2"], "2.1");
            JbAssert.Equal(conf[@"Level2/Item22"], "2.2");
            JbAssert.Equal(conf[@"Level1/Level2/Item"], "2.0");
            JbAssert.Equal(conf[@"Level1/Level2/Item2"], "2.1");
            JbAssert.Equal(conf[@"Level1/Level2/Item22"], "2.2");
            JbAssert.Equal(conf[@"Level3/Item"], "3.0");
            JbAssert.Equal(conf[@"Level3/Item3"], "3.1");
            JbAssert.Equal(conf[@"Level2/Level3/Item"], "3.0");
            JbAssert.Equal(conf[@"Level2/Level3/Item3"], "3.1");
            JbAssert.Equal(conf[@"Level1/Level2/Level3/Item"], "3.0");
            JbAssert.Equal(conf[@"Level1/Level2/Level3/Item3"], "3.1");
            JbAssert.Equal(conf[@"Level4/Item"], "4.0");

            JbAssert.Equal(conf.FindStrict("Item", null, false).Value, "1.0");
            JbAssert.Equal(conf.FindStrict(@"Level1/Item").Value, "1.0");
            Assert.ThrowsException <Exception>(() => { conf.FindStrict("Item"); });
        }
Esempio n. 6
0
        public void TestConfTree_Clone_SaveToDiffFile()
        {
            ConfTree conf1 = Builder.Generate(new Dictionary <string, string> {
                { "Item1", "Value1" },
                { "Item2", "Value2" },
            }, "DictionaryConf");

            Assert.IsTrue(conf1.XmlDoc == null);
            Builder.Xml.Save(conf1, $"{GlobalVar.ResultPath}/Conf1.xml");
            JbAssert.PathEqual((conf1.XmlDoc as XmlDocument).BaseURI, $"file:///{GlobalVar.ResultPath}/Conf1.xml");

            var conf2 = conf1.Clone("new");

            Debug.WriteLine(conf2.ToString());
            Assert.IsTrue((conf2 as ConfTree).XmlDoc == null);
            Builder.Xml.Save(conf2 as ConfTree, $"{GlobalVar.ResultPath}/Conf2.xml");
            JbAssert.PathEqual(((conf2 as ConfTree).XmlDoc as XmlDocument).BaseURI, $"file:///{GlobalVar.ResultPath}/Conf2.xml");

            ConfTree conf = new ConfTree("DictionaryConf");

            conf.Add(conf1);
            conf.Add(conf2);
            Debug.WriteLine(conf.ToString());
            Builder.Xml.Save(conf as ConfTree, $"{GlobalVar.ResultPath}/Conf.xml");
            JbAssert.PathEqual(((conf as ConfTree).XmlDoc as XmlDocument).BaseURI, $"file:///{GlobalVar.ResultPath}/Conf.xml");

            var conf4 = conf.Clone("conf4");

            ConfTree super = new ConfTree("SuperConf");

            super.Add(conf);
            super.Add(conf4);
            Builder.Xml.Save(super, $"{GlobalVar.ResultPath}/Super.xml");
            JbAssert.PathEqual(((super as ConfTree).XmlDoc as XmlDocument).BaseURI, $"file:///{GlobalVar.ResultPath}/Super.xml");
        }
Esempio n. 7
0
        public void TestBuild_Xml_Attribute_Save()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/Attribute.xml");

            Debug.WriteLine(conf.ToString());
            Builder.Xml.Save(conf, $@"{GlobalVar.ResultPath}/Attribute.xml");
        }
Esempio n. 8
0
 private void SwitchConf(ConfTree conf)
 {
     if (IsBinded)
     {
         confView1.LoadConf(conf, CMB_ShowLevel.Visible ? (CMB_ShowLevel.SelectedIndex + 1).ToString() : null);
         OnUpdate?.Invoke();
     }
 }
Esempio n. 9
0
        public void TestBuild_Xml_Tag_FindItem()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/Tag.xml");

            JbAssert.Equal(conf[@"Default:Item1"], "0");
            JbAssert.Equal(conf[@"Tag1:Item1"], "1.1");
            JbAssert.Equal(conf[@"Tag2:Item1"], "2.1");
        }
Esempio n. 10
0
        public ConfEditForm(ConfTree root, ConfItem item, Action onChange)
        {
            InitializeComponent();

            confEditor1.Bind(root, item, () => {
                onChange.Invoke();
            });
        }
Esempio n. 11
0
        public void TestBuild_Xml_Tag()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/Tag.xml");

            Debug.WriteLine(conf.ToString());
            JbAssert.Equal(conf[@"Default:Func/Item1"], "0");
            JbAssert.Equal(conf[@"Tag1:Func/Item1"], "1.1");
            JbAssert.Equal(conf[@"Tag2:Func/Item1"], "2.1");
        }
Esempio n. 12
0
        public void TestBuild_Xml_SameItemName()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/SameItemName.xml");

            Debug.WriteLine(conf.ToString());
            JbAssert.Equal(conf[@"Function1/Item1"], "Value1");
            JbAssert.Equal(conf[@"Function2/Item1"], "Func2-1");
            JbAssert.Equal(conf[@"Function3/Item1"], "Func3-1");
        }
Esempio n. 13
0
        public void TestBuild_Xml_Attribute()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/Attribute.xml");

            Debug.WriteLine(conf.ToString());

            JbAssert.Equal(conf[@"CW/Ith.Min"], "0");
            JbAssert.Equal(conf[@"CW/Ith.Max"], "10000");
        }
Esempio n. 14
0
        public ConfView(ConfTree conf)
        {
            InitializeComponent();
            Dock = DockStyle.Fill;

            _log.Debug("Load ConfTree");
            Conf = conf;
            DGV_ConfigItems.DataSource = UiSupport.ConvertToTable(Conf);
            DGV_ConfigItems.Columns[DGV_ConfigItems.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
Esempio n. 15
0
        public void TestBuild_Xml_MultiTagWithDefault()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/MultiTagWithDefault.xml");

            Debug.WriteLine(conf.ToString());

            JbAssert.Equal(conf[@"T1.1:Item1"], "1.1.1.1");
            JbAssert.Equal(conf[@"T1.2:Item1"], "1.2.2.1");
            JbAssert.Equal(conf[@"T1.2.1:Item1"], "1.2.1.3");
        }
Esempio n. 16
0
        public void TestBuild_Xml_MultiLevel_SameItemName()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/MultiLevel.xml");

            Debug.Write(conf);

            JbAssert.Equal(conf[@"Level1/Item"], "1.0");
            JbAssert.Equal(conf[@"Level2/Item"], "2.0");
            JbAssert.Equal(conf[@"Level3/Item"], "3.0");
            JbAssert.Equal(conf[@"Level4/Item"], "4.0");
        }
Esempio n. 17
0
        public void TestConfNodeEditor_GetSonStructure()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/DefaultSpec.xml");

            conf.Save($@"{GlobalVar.ResultPath}\root.xml");
            conf = Builder.Xml.Generate($@"{GlobalVar.ResultPath}\root.xml");

            var item = (conf.GetItem(@"Specs") as ConfTree).Sons[0].Clone();

            Assert.IsTrue(item != null);
        }
Esempio n. 18
0
        public void LoadConf(ConfTree conf, string oplevel)
        {
            if (Conf == null || !Conf.Equals(conf))
            {
                _log.Debug($"Load ConfTree({conf.Name},{(oplevel != null ? "" : "null")})");

                Conf = conf;
                DGV_ConfigItems.DataSource = UiSupport.ConvertToTable(Conf, oplevel);
                DGV_ConfigItems.Columns[DGV_ConfigItems.ColumnCount - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
Esempio n. 19
0
        public ConfigFiles()
        {
            InitializeComponent();

            ConfTree conf = Builder.Xml.Generate($@"D:\DieTester\DieTester\DieTester\bin\Debug\Configs\SpecFile\DefaultSpec.xml");

            confView = new ConfView(conf);
            Controls.Add(confView);

            confView.SetLevel("1");
        }
Esempio n. 20
0
        public void TestConfTree_Compare_SimpleTreeEqual()
        {
            ConfTree tree1 = new ConfTree("Tree1");

            tree1.Add(new ConfItem("Item1-1", "Value1-1"));

            ConfTree tree2 = new ConfTree("Tree1");

            tree2.Add(new ConfItem("Item1-1", "Value1-1"));

            Assert.IsTrue(tree1.Equals(tree2));
        }
Esempio n. 21
0
        public void TestConfTree_AddItemToTree()
        {
            ConfTree conf = new ConfTree("TestBuildTree");

            Assert.IsTrue(conf.Name == "TestBuildTree");

            conf.Add(new ConfItem("Item1", "Value1"));
            Assert.IsTrue(conf["Item1"] == "Value1");
            Assert.IsTrue(conf.Find("Item1").Path == "/TestBuildTree");

            GlobalVar.Log.Debug(conf.ShowAll());
        }
Esempio n. 22
0
        public virtual void Apply(ConfTree conf)
        {
            if (conf == null)
            {
                return;
            }

            CurrentConf = conf;
            conf.Visit("Apply", (item, level) =>
            {
                if (item is ConfItem)
                {
                    if (item.Attributes.ContainsKey("guitype") && item.Attributes["guitype"] == "RadioButton")
                    {
                        var control = Controls.Find($"{item.Name}_{item.Value}", true);
                        if (control.Length > 0)
                        {
                            (control[0] as RadioButton).Checked = true;
                        }
                    }
                    else if (item.Attributes.ContainsKey("guitype") && item.Attributes["guitype"].Contains("ComboBox"))
                    {
                        var control = Controls.Find($"{item.Name}", true);
                        if (control.Length > 0)
                        {
                            var cb = (control[0] as ComboBox);

                            var type_value = item.Attributes["guitype"].Split(':');
                            if (type_value.Length > 1)
                            {
                                cb.DataSource    = type_value[1].Split(',');
                                cb.SelectedIndex = cb.Items.IndexOf(item.Value);
                            }
                            else
                            {
                                control[0].Text = item.Value;
                            }
                        }
                    }
                    else
                    {
                        var control = Controls.Find(item.Name, true);
                        if (control.Length > 0)
                        {
                            control[0].Text = item.Value;
                        }
                    }
                }

                return(false);
            });
        }
Esempio n. 23
0
        public void Bind(ConfTree conf)
        {
            _conf = conf;

            var dict = new Dictionary <string, string>();

            foreach (var kv in _conf.AllItems)
            {
                dict[kv.Name] = kv.Value;
            }

            propertyGrid1.SelectedObject = new DictionaryPropertyGridAdapter(dict);
        }
Esempio n. 24
0
        public void TestBuild_Xml_Attribute_Modify()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/Attribute.xml");

            JbAssert.Equal(conf[@"CW/Ith.Min"], "0");

            Debug.WriteLine(conf.ToString());
            conf[@"Specs/Spec/CW/Ith.Min"] = "1";
            Builder.Xml.Save(conf, $@"{GlobalVar.ResultPath}/Attribute.xml");

            conf = Builder.Xml.Generate($@"{GlobalVar.ResultPath}/Attribute.xml");
            JbAssert.Equal(conf[@"CW/Ith.Min"], "1");
        }
Esempio n. 25
0
        public void TestBuild_Xml_CheckPath()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/Basic.xml");

            JbAssert.Equal(conf.Find("Item1").Path, "/Basic(Basic)/Function1");
            JbAssert.Equal(conf.Find("Item2").Path, "/Basic(Basic)/Function1");
            JbAssert.Equal(conf.Find("Item3").Path, "/Basic(Basic)/Function2");
            JbAssert.Equal(conf.Find("Item4").Path, "/Basic(Basic)/Function2");
            JbAssert.Equal(conf.Find("Item5").Path, "/Basic(Basic)");

            conf["Item1"] = "Value5";
            JbAssert.Equal(conf.Find("Item1").Path, "/Basic(Basic)/Function1");
        }
Esempio n. 26
0
        public void TestBuild_Dictionary_Save()
        {
            ConfTree conf = Builder.Generate(new Dictionary <string, string> {
                { "Item1", "Value1" },
                { "Item2", "Value2" },
            }, "DictConf1");

            Assert.IsTrue(conf["Item1"] == "Value1");
            Assert.IsTrue(conf["Item2"] == "Value2");

            JbAssert.Equal(conf.Find("Item1").Path, "/DictConf1(Default)");
            JbAssert.Equal(conf.Find("Item2").Path, "/DictConf1(Default)");

            Builder.Xml.Save(conf, $@"{GlobalVar.ResultPath}/DictConf1.xml");
        }
Esempio n. 27
0
        public void TestBuild_Xml_MultiLevel()
        {
            ConfTree conf = Builder.Xml.Generate($@"{GlobalVar.SamplePath}/MultiLevel.xml");

            conf.Save($@"{GlobalVar.ResultPath}\root.xml");

            JbAssert.Equal(conf["Item1"], "1.1");
            JbAssert.Equal(conf[@"Level1/Item1"], "1.1");
            JbAssert.Equal(conf[@"MultiLevel/Level1/Item1"], "1.1");

            JbAssert.Equal(conf["Item2"], "2.1");
            JbAssert.Equal(conf[@"Level2/Item2"], "2.1");
            JbAssert.Equal(conf[@"MultiLevel/Level1/Level2/Item2"], "2.1");
            JbAssert.Equal(conf["Item22"], "2.2");

            JbAssert.Equal(conf["Item3"], "3.1");
            JbAssert.Equal(conf[@"Level3/Item3"], "3.1");
            JbAssert.Equal(conf[@"MultiLevel/Level1/Level2/Level3/Item3"], "3.1");
        }
Esempio n. 28
0
        public void Bind(ConfTree root, ConfItem item, Action onChange)
        {
            _root     = root;
            _tree     = item as ConfTree;
            _onChange = onChange;

            LBL_FileInfo.Text     = Path.GetFileNameWithoutExtension(root.XmlDoc.BaseURI);
            LBL_SelectedNode.Text = $"为{ExtractTopNode(item.SelfPath)}添加";

            var tree = item as ConfTree;

            if (tree != null)
            {
                DataTable table;

                var subtree = tree.Sons[0] as ConfTree;

                if (subtree != null)
                {
                    var emptynode = ((subtree as ConfTree).Clone() as ConfTree);
                    emptynode.Clear();
                    table = UiSupport.ConvertToTable(emptynode);
                }
                else
                {
                    table = new DataTable();
                    table.Columns.AddRange(new DataColumn[] {
                        new DataColumn("Item.Name"),
                        new DataColumn("Item.Value"),
                    });
                    var row = table.NewRow();
                    table.Rows.Add(row);

                    DGV_NewNodeInfo.ColumnHeadersVisible = true;
                }

                DGV_NewNodeInfo.DataSource = table;
            }
        }
Esempio n. 29
0
        public void TestConfTree_Compare_MixedTree()
        {
            ConfTree a1 = new ConfTree("Tree1");

            a1.Add(new ConfItem("Item1-1", "Value1-1"));
            ConfTree a2 = new ConfTree("Tree2");

            a2.Add(new ConfItem("Item2-1", "Value2-1"));
            a2.Add(new ConfItem("Item2-2", "Value2-2"));
            a1.Add(a2);

            ConfTree b1 = new ConfTree("Tree1");

            b1.Add(new ConfItem("Item1-1", "Value1-1"));
            ConfTree b2 = new ConfTree("Tree2");

            b2.Add(new ConfItem("Item2-1", "Value2-1"));
            b2.Add(new ConfItem("Item2-2", "Value2-2"));
            b1.Add(b2);

            Assert.IsTrue(a1.Equals(b1));
        }
Esempio n. 30
0
        public void TestConfTree_AddTreeToTree()
        {
            ConfTree tree1 = new ConfTree("Tree1");

            tree1.Add(new ConfItem("Item1", "Value1"));

            ConfTree tree2 = new ConfTree("Tree2");

            tree2.Add(new ConfItem("Item2", "Value2"));

            tree1.Add(tree2);

            Assert.IsTrue(tree1.Find("Item1").Path == "/Tree1");
            Assert.IsTrue(tree1.Find("Tree2").Path == "/Tree1");
            Assert.IsTrue(tree1.Find("Item2").Path == "/Tree1/Tree2");

            Assert.IsTrue(tree1.Find("Item1").Parent.Name == "Tree1");
            Assert.IsTrue(tree1.Find("Tree2").Parent.Name == "Tree1");
            Assert.IsTrue(tree1.Find("Item2").Parent.Name == "Tree2");

            GlobalVar.Log.Debug(tree1.ShowAll());
        }