예제 #1
0
        private void SetupApplication()
        {
            try
            {
                ROMNode node = ROMNode.LoadXML("config.xml", null);
                if (node == null)
                    return;

                ROMNode childNode = new ROMNode("Child1");
                childNode.SetAttribute("attr1", "A child attr");
                node.AddChildROMObject(childNode);
                ROMNode childNode2 = new ROMNode("Child2");
                childNode2.SetAttribute("attr2", "A child attr");
                node.AddChildROMObject(childNode2);
                ROMNode childNode3 = new ROMNode("Child3");
                childNode3.SetAttribute("attr3", "A child attr");
                childNode3.SetAttribute("attr3", "attrSub1", "A sub child attr");
                childNode3.SetAttribute("attr3", "attrSub2", "A 2nd sub child attr");
                childNode2.AddChildROMObject(childNode3);

                Debugger.RootNode = node;
                Debugger.Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        private void SetupApplication()
        {
            try
            {
                ROMNode node = ROMNode.LoadXML("config.xml", null);
                if (node == null)
                {
                    return;
                }

                ROMNode childNode = new ROMNode("Child1");
                childNode.SetAttribute("attr1", "A child attr");
                node.AddChildROMObject(childNode);
                ROMNode childNode2 = new ROMNode("Child2");
                childNode2.SetAttribute("attr2", "A child attr");
                node.AddChildROMObject(childNode2);
                ROMNode childNode3 = new ROMNode("Child3");
                childNode3.SetAttribute("attr3", "A child attr");
                childNode3.SetAttribute("attr3", "attrSub1", "A sub child attr");
                childNode3.SetAttribute("attr3", "attrSub2", "A 2nd sub child attr");
                childNode2.AddChildROMObject(childNode3);

                Debugger.RootNode = node;
                Debugger.Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void btnGet_Click(object sender, RoutedEventArgs e)
        {
            string attrName = txtName.Text;

            if (attrName.Length > 0)
            {
                TreeViewItem item = (TreeViewItem)treeCtrl.SelectedItem;
                if (item != null)
                {
                    ROMNode node = (ROMNode)item.Tag;
                    if (node != null)
                    {
                        string subAttrName = "value";
                        int    index       = attrName.IndexOf(':');
                        if (index >= 0)
                        {
                            subAttrName = attrName.Substring(index + 1);
                            attrName    = attrName.Substring(0, index);
                        }
                        bool   immediate = (bool)checkImmediate.IsChecked;
                        string value     = node.GetAttribute(attrName, subAttrName, immediate);
                        txtValue.Text = value;
                    }
                }
            }
        }
예제 #4
0
        private void btnSet_Click(object sender, RoutedEventArgs e)
        {
            string attrName  = txtName.Text;
            string attrValue = txtValue.Text;

            if (attrName.Length > 0)
            {
                TreeViewItem item = (TreeViewItem)treeCtrl.SelectedItem;
                if (item != null)
                {
                    ROMNode node = (ROMNode)item.Tag;
                    if (node != null)
                    {
                        string subAttrName = "value";
                        int    index       = attrName.IndexOf(':');
                        if (index >= 0)
                        {
                            subAttrName = attrName.Substring(index + 1);
                            attrName    = attrName.Substring(0, index);
                        }
                        node.SetAttribute(attrName, subAttrName, attrValue);
                        if (rbAttr.IsChecked == true)
                        {
                            DisplayAttributeGrid(item);
                        }
                        else
                        {
                            DisplayXML(item);
                        }
                    }
                }
            }
        }
예제 #5
0
        public void AddBranchAndChildren(TreeViewItem parent, ROMNode node)
        {
            string caption = node.GetROMObjectID();
            TreeViewItem current = null;
            if (parent != null)
            {
                current = new TreeViewItem();
                current.Header = caption;
                current.Tag = node;
                current.Name = "_" + node.GetROMGUID().Replace('-', '_');
                try
                {
                    treeCtrl.UnregisterName(current.Name);
                }
                catch { }
                treeCtrl.RegisterName(current.Name, current);
                parent.Items.Add(current);
            }

            ROMNode[] children = node.GetAllChildren(false);
            if (children != null) foreach (ROMNode child in children)
                {
                    AddBranchAndChildren(current, child);
                }
        }
예제 #6
0
파일: Form1.cs 프로젝트: e1d1s1/Logician
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "XML files (*.xml)|*.xml";
            dialog.Title = "Open XML file";

            if (dialog.ShowDialog() == DialogResult.Cancel)
                return;

            //string contents = null;
            //using (StreamReader reader = new StreamReader(dialog.FileName))
            //{
            //    while (!reader.EndOfStream)
            //    {
            //        contents = reader.ReadToEnd();
            //    }
            //}

            //reload
            if (!string.IsNullOrEmpty(dialog.FileName))
            {
                var newNode = ROMNode.LoadXML(dialog.FileName, null);
                if (newNode != null)
                {
                    newNode.Rules = m_rules;
                    m_rootNode = newNode;
                    m_engine = new LinearEngine(m_rootNode, "HydraulicCylinderDictionary");
                    m_engine.EvaluateAll();

                    UpdateControls();
                }
            }
        }
예제 #7
0
        public void AddBranchAndChildren(TreeViewItem parent, ROMNode node)
        {
            string       caption = node.GetROMObjectID();
            TreeViewItem current = null;

            if (parent != null)
            {
                current        = new TreeViewItem();
                current.Header = caption;
                current.Tag    = node;
                current.Name   = "_" + node.GetROMGUID().Replace('-', '_');
                try
                {
                    treeCtrl.UnregisterName(current.Name);
                }
                catch { }
                treeCtrl.RegisterName(current.Name, current);
                parent.Items.Add(current);
            }

            ROMNode[] children = node.GetAllChildren(false);
            if (children != null)
            {
                foreach (ROMNode child in children)
                {
                    AddBranchAndChildren(current, child);
                }
            }
        }
예제 #8
0
파일: Form1.cs 프로젝트: e1d1s1/Logician
        private void SetupApplication()
        {
            string rulesPath = "HydraulicCylinderRules.xml";

            m_rules = new EDSEngine(rulesPath);

            m_rootNode = new ROMNode("HydraulicCylinder");

            if (!m_rules.IsOpen())
            {
                MessageBox.Show("Error loading rules file");
                Close();
            }

            m_rules.InputGetterDelegate = delegate(string name, object obj)
            {
                return(((ROMNode)obj).GetAttribute(name, false));
            };

            m_rootNode.Rules = m_rules;
            m_engine         = new LinearEngine(m_rootNode, "HydraulicCylinderDictionary");
            m_engine.EvaluateAll();

            UpdateControls();
        }
예제 #9
0
 private void DisplayXML(TreeViewItem item)
 {
     text.Text = "";
     if (item != null)
     {
         ROMNode node = (ROMNode)item.Tag;
         string  xml  = node.SaveXML(true);
         text.Text = xml;
     }
 }
예제 #10
0
        private static void CreateChildNodes(ROMNode rootNode)
        {
            Log("Creating a child object");
            ROMNode childNode = ObjectFactory("DerivedObject");

            rootNode.AddChildROMObject(childNode);
            childNode.SetAttribute("childAttr", "some value of value");
            //setting a value on the Object Node
            childNode.SetROMObjectValue("valueTest", "myValue");
            ROMNode childOfChild = ObjectFactory("DerivedObject2");

            childNode.AddChildROMObject(childOfChild);
        }
예제 #11
0
        private void DisplayAttributeGrid(TreeViewItem item)
        {
            grid.ItemsSource = null;
            if (item != null)
            {
                ROMNode node = (ROMNode)item.Tag;
                if (node != null)
                {
                    List <ROMAttrData> table = new List <ROMAttrData>();
                    Dictionary <string, Dictionary <string, string> > allAttrs = node.GetAllAttributes();

                    SortedDictionary <string, KeyValuePair <string, Dictionary <string, string> > > sorted = new SortedDictionary <string, KeyValuePair <string, Dictionary <string, string> > >();
                    foreach (KeyValuePair <string, Dictionary <string, string> > kvp in allAttrs)
                    {
                        sorted.Add(kvp.Key, kvp);
                    }

                    foreach (string attr in sorted.Keys)
                    {
                        ROMAttrData row = new ROMAttrData();
                        Dictionary <string, string> attrValuePair = allAttrs[attr];
                        row.Attribute = attr;
                        row.Value     = attrValuePair["value"];
                        foreach (KeyValuePair <string, string> kvp in attrValuePair)
                        {
                            if (kvp.Key != "value")
                            {
                                if (row.SubValues == null)
                                {
                                    row.SubValues = new ObservableCollection <string>();
                                }
                                row.SubValues.Add(kvp.Key + ": " + kvp.Value);
                            }
                        }
                        table.Add(row);
                    }

                    FillGrid(table);
                }
            }
        }
예제 #12
0
        public void Update()
        {
            if (m_rootNode == null)
            {
                return;
            }

            m_bLoading = true;
            ROMNode      node = null;
            TreeViewItem item = (TreeViewItem)treeCtrl.SelectedItem;

            if (item != null)
            {
                node = (ROMNode)item.Tag;
            }

            BuildTree();
            item = null;
            if (node != null)
            {
                item = (TreeViewItem)treeCtrl.FindName("_" + node.GetROMGUID().Replace('-', '_'));
            }

            if (item != null)
            {
                item.IsSelected = true;
                DisplayAttributeGrid(item);
            }
            else
            {
                if (treeCtrl.Items.Count > 0)
                {
                    ((TreeViewItem)treeCtrl.Items[0]).IsSelected = true;
                    DisplayAttributeGrid((TreeViewItem)treeCtrl.Items[0]);
                }
            }
            m_bLoading = false;
        }
예제 #13
0
파일: Form1.cs 프로젝트: e1d1s1/Logician
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "XML files (*.xml)|*.xml";
            dialog.Title  = "Open XML file";

            if (dialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            //string contents = null;
            //using (StreamReader reader = new StreamReader(dialog.FileName))
            //{
            //    while (!reader.EndOfStream)
            //    {
            //        contents = reader.ReadToEnd();
            //    }
            //}

            //reload
            if (!string.IsNullOrEmpty(dialog.FileName))
            {
                var newNode = ROMNode.LoadXML(dialog.FileName, null);
                if (newNode != null)
                {
                    newNode.Rules = m_rules;
                    m_rootNode    = newNode;
                    m_engine      = new LinearEngine(m_rootNode, "HydraulicCylinderDictionary");
                    m_engine.EvaluateAll();

                    UpdateControls();
                }
            }
        }
예제 #14
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            frm        = new MainForm();
            frm.Shown += delegate(object sender, EventArgs e)
            {
                long      start = 0, elapsed = 0, testROMNodeStart = 0, testROMNodeEnd = 0;
                string    msg;
                const int iMax      = 1000;
                string    filename  = "test_project.gz";
                string    rulesPath = "..\\..\\..\\..\\..\\EDSEngine\\EDSEngineTestApp\\" + filename;
                if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
                {
                    rulesPath = args[0];
                }

                Log("Creating the root node");
                ROMNode rootNode = new ApplicationObject("TestApplication", ObjectFactory);
                Log("Root created");

                Log("Setting some attributes");
                rootNode.SetAttribute("inputAttr1", "some value of test1");
                rootNode.SetAttribute("inputAttr2", "some value of test2");
                rootNode.SetAttribute("inputAttr3", "some value of test3");
                rootNode.SetAttribute("inputAttr3", "test3a", "some sub value of attr3_a");
                rootNode.SetAttribute("inputAttr3", "test3b", "some sub value of attr3_b");
                Log("Attrs set");

                CreateChildNodes(rootNode);
                ROMNode[] findTest       = rootNode.FindAllObjectsByID("DerivedObject", true);
                ROMNode[] findTestXPATH  = rootNode.FindObjects("//Object[@id='DerivedObject']");
                ROMNode[] findTestXPATH2 = rootNode.FindObjects("//Object[@id='DerivedObject2']");
                if (findTest.Length == 1 && findTestXPATH.Length == 1 && findTestXPATH2.Length == 1 &&
                    findTest[0].GetROMGUID() == findTestXPATH[0].GetROMGUID() &&
                    findTestXPATH2[0].GetROMObjectID() == "DerivedObject2")
                {
                    Log("OK");
                }
                else
                {
                    Log("FAILURE creating/obtaining child object");
                }

                Log("Dump current xml state");
                string s = rootNode.SaveXML(true);
                Log(s);

                Log("Cloning the root object");
                var    clonedObj     = rootNode.Clone();
                string testClone     = clonedObj.SaveXML(true);
                var    rootChildCnt  = rootNode.GetAllChildren(true).Length;
                var    cloneChildCnt = clonedObj.GetAllChildren(true).Length;
                if (s.Length == testClone.Length &&
                    rootChildCnt == cloneChildCnt)
                {
                    Log("Clone OK");
                }
                else
                {
                    Log("FAILURE Cloning root");
                }

                Log("Test the object factory and inheritence pattern on the clone");
                ApplicationObject rootTest  = (ApplicationObject)clonedObj.FindAllObjectsByID("TestApplication", true)[0];
                DerivedObject2    childTest = (DerivedObject2)clonedObj.FindObjects("//Object[@id='DerivedObject2']")[0];
                if (rootTest.GetAttribute("CLASS", true) == "ApplicationObject" &&
                    childTest.GetAttribute("CLASS", true) == "DerivedObject2")
                {
                    Log("inheritence OK");
                }
                else
                {
                    Log("FAILURE in inheritence pattern of cloned object");
                }

                Log("Test loading from xml");
                ROMNode loadedObj  = ROMNode.LoadXMLFromString(s, ObjectFactory);
                string  testLoaded = loadedObj.SaveXML(true);
                if (s.Length == testLoaded.Length &&
                    rootNode.GetAllChildren(true).Length == loadedObj.GetAllChildren(true).Length)
                {
                    Log("XML loading OK");
                }
                else
                {
                    Log("FAILURE loading from xml");
                }

                Log("Test the object factory and inheritence pattern of loaded xml");
                rootTest  = (ApplicationObject)loadedObj.FindAllObjectsByID("TestApplication", true)[0];
                childTest = (DerivedObject2)loadedObj.FindObjects("//Object[@id='DerivedObject2']")[0];
                if (rootTest.GetAttribute("CLASS", true) == "ApplicationObject" &&
                    childTest.GetAttribute("CLASS", true) == "DerivedObject2")
                {
                    Log("inheritence OK");
                }
                else
                {
                    Log("FAILURE in inheritence pattern of loaded xml");
                }

                Log("Test for equlity");
                DerivedObject2 childTest2 = (DerivedObject2)loadedObj.FindObjects("//Object[@id='DerivedObject2']")[0];
                if (childTest == childTest2 && childTest != rootTest)
                {
                    Log("equality test OK");
                }
                else
                {
                    Log("FAILURE equality test");
                }

                Log("Setting attrs to test eval, inputAttr1 = A, inputAttr2 = 10, outsideAttr1 = 28");
                rootNode.SetAttribute("inputAttr1", "A");
                rootNode.SetAttribute("inputAttr2", "10");
                rootNode.SetAttribute("outsideAttr1", "28");
                Log("loading rules: " + rulesPath);

                EDSNET.EDSEngine rules = new EDSNET.EDSEngine(rulesPath);
                if (!rules.IsOpen())
                {
                    rules = new EDSNET.EDSEngine(filename);
                }
                if (rules.IsOpen())
                {
                    rules.DebugDelegate = DebugMessage;
                    rules.EnableRemoteDebugger(false);
                    EDSNET.InputValueGetterDelegate getValueDelegate = (string attrName, object context) =>
                    {
                        ROMNode objContext = (ROMNET.ROMNode)context;
                        return(objContext.GetAttribute(attrName, false));
                    };
                    rules.InputGetterDelegate = getValueDelegate;

                    rootNode.Rules = rules;

                    Log("...loaded");
                    Log("Evaluating table testtable1");
                    string[] res = rootNode.EvaluateTable("testtable1", "outputAttr1", true);
                    foreach (string str in res)
                    {
                        Log(str);
                    }
                    Log("Evaluation complete");

                    Log("Evaluating table testtable2: out1");
                    string[] res2 = rootNode.EvaluateTable("testtable2", "out1", true);
                    foreach (string str in res2)
                    {
                        Log(str);
                    }
                    Log("Evaluation complete");

                    Log("Testing the LinearEngine class");
                    LinearEngine engine = new LinearEngine(rootNode, "Dictionary");
                    engine.InitializeEngine();

                    Log("Checking dictionary size");
                    Dictionary <string, ROMDictionaryAttribute> attrs = engine.GetAllDictionaryAttrs();
                    if (attrs.Count == 6)
                    {
                        Log("size ok");
                    }
                    else
                    {
                        Log("FAILURE loading dictionary");
                    }

                    ROMDictionaryAttribute[] order = engine.GetEvalList();
                    if (order != null && order.Length == 6 &&
                        order[0].Name == "cDictAttr1" &&
                        order[1].Name == "dDictAttr2" &&
                        order[2].Name == "aDictAttr3" &&
                        order[3].Name == "bDictAttr4" &&
                        order[4].Name == "eDictAttr5" &&
                        order[5].Name == "eDictAttr6")
                    {
                        Log("Order OK");
                    }
                    else
                    {
                        Log("FAILURE to assess the evaluation order");
                    }

                    Dictionary <string, string[]> triggers = engine.GetTriggers();
                    if (triggers.Count == 3 &&
                        triggers["aDictAttr3"].Length == 2 &&
                        triggers["aDictAttr3"][0] == "bDictAttr4" &&
                        triggers["aDictAttr3"][1] == "eDictAttr5")
                    {
                        Log("Triggers OK");
                    }
                    else
                    {
                        Log("FAILURE to assess the triggers");
                    }

                    Log("Testing evaluation");
                    engine.EvaluateAll();
                    ROMDictionaryAttribute attr1 = engine.GetDictionaryAttr("cDictAttr1");
                    ROMDictionaryAttribute attr2 = engine.GetDictionaryAttr("dDictAttr2");
                    if (attr2.AvailableValues.Length == 0 && attr2.PossibleValues.Length == 3 &&
                        attr1.AvailableValues.Length == 4)
                    {
                        Log("Default Eval OK");
                    }
                    else
                    {
                        Log("FAILURE to initially evaluate an attribute");
                    }

                    engine.EvaluateForAttribute("cDictAttr1", attr1.AvailableValues[0]);
                    string val_pick1  = rootNode.GetAttribute("dDictAttr2");
                    string val_bool1  = rootNode.GetAttribute("aDictAttr3");
                    string val_multi1 = rootNode.GetAttribute("bDictAttr4");
                    string edit1      = rootNode.GetAttribute("eDictAttr5");
                    engine.EvaluateForAttribute("cDictAttr1", attr1.AvailableValues[1]);
                    string val_pick2 = rootNode.GetAttribute("dDictAttr2");
                    string val_bool2 = rootNode.GetAttribute("aDictAttr3");
                    engine.EvaluateForAttribute("cDictAttr1", attr1.AvailableValues[2]);
                    string val_bool3  = rootNode.GetAttribute("aDictAttr3");
                    string val_multi3 = rootNode.GetAttribute("bDictAttr4");
                    engine.EvaluateForAttribute("eDictAttr5", "999");
                    string edit4 = rootNode.GetAttribute("eDictAttr5");
                    if (val_pick1 == "ResultByOption1" && val_pick2 == "Result2" &&
                        val_bool1 == "Y" && val_bool2 == "Y" && val_bool3 == "N" &&
                        val_multi1 == "Selection2|Selection3" && val_multi3 == "Selection2" &&
                        edit1 == "10" && edit4 == "50")
                    {
                        Log("Evaluation of attributes ok");
                    }
                    else
                    {
                        Log("FAILURE to evaluate an attribute");
                    }

                    start            = Environment.TickCount;
                    testROMNodeStart = start;
                    Log("Stress Testing...");
                    Log("Setting a bunch of values...");
                    for (int i = 0; i < iMax; i++)
                    {
                        string attrToSet = "attr";
                        attrToSet += i.ToString();
                        rootNode.SetAttribute(attrToSet, i.ToString());
                    }
                    Log("Retrieving a bunch of values...");
                    for (int i = 0; i < iMax; i++)
                    {
                        string attrToGet = "attr";
                        attrToGet += i.ToString();;
                        rootNode.GetAttribute(attrToGet);
                    }
                    elapsed = Environment.TickCount - start;
                    msg     = "attribute test complete in ";
                    msg    += elapsed.ToString();
                    msg    += "ms";
                    Log(msg);

                    start = Environment.TickCount;
                    Log("Create a large object heierarchy for querey testing");
                    for (int i = 0; i < iMax; i++)
                    {
                        string objectToCreate = "SubLevel1Object";
                        objectToCreate += i.ToString();
                        ROMNode newNode = new ROMNode(objectToCreate);
                        rootNode.AddChildROMObject(newNode);

                        objectToCreate  = "SubLevel2Object";
                        objectToCreate += i.ToString();
                        ROMNode newNode2 = new ROMNode(objectToCreate);
                        newNode.AddChildROMObject(newNode2);
                        newNode2.SetAttribute("sumtester", "1");
                        newNode2.SetAttribute("sumtester2", "2");
                        newNode2.SetAttribute("sumtester3", "3");
                        newNode2.SetAttribute("testvalue", "value found");
                    }
                    elapsed = Environment.TickCount - start;
                    msg     = "objects created in ";
                    msg    += elapsed.ToString();
                    msg    += "ms";
                    Log(msg);

                    Log("Performing queries");
                    start = Environment.TickCount;
                    long   queryTime = start;
                    string xpath     = "sum(//Attribute[@id='sumtester']/@value)";
                    string xpathRes  = rootNode.EvaluateXPATH(xpath);
                    elapsed = Environment.TickCount - start;
                    Log(xpath + " result: " + xpathRes);
                    msg  = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    start = Environment.TickCount;
                    string xpath2    = "sum(//Attribute[@id='sumtester2']/@value)";
                    string xpathRes2 = rootNode.EvaluateXPATH(xpath2);
                    elapsed = Environment.TickCount - start;
                    Log(xpath2 + " result: " + xpathRes2);
                    msg  = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    Log("altering the object state");
                    rootNode.SetAttribute("Change", "Y");

                    start = Environment.TickCount;
                    string xpath3    = "sum(//Attribute[@id='sumtester3']/@value)";
                    string xpathRes3 = rootNode.EvaluateXPATH(xpath3);
                    elapsed = Environment.TickCount - start;
                    Log(xpath3 + " result: " + xpathRes3);
                    msg  = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    start = Environment.TickCount;
                    string xpath4    = "//Object[@id='SubLevel2Object10']/Attribute[@id='testvalue']/@value";
                    string xpathRes4 = rootNode.EvaluateXPATH(xpath4);
                    long   finished  = Environment.TickCount;
                    testROMNodeEnd = finished;
                    elapsed        = finished - start;
                    Log(xpath4 + " result: " + xpathRes4);
                    msg  = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);
                    elapsed = finished - queryTime;
                    msg     = "All object query tests completed in ";
                    msg    += elapsed.ToString();
                    msg    += "ms";
                    Log(msg);

                    msg     = "stress test total time: ";
                    elapsed = testROMNodeEnd - testROMNodeStart;
                    msg    += elapsed.ToString();
                    msg    += "ms";
                    Log(msg);
                }
                else
                {
                    Log("Could not load rules");
                }

                Log("Testing complete...press any key to exit");
                Console.ReadLine();
            };

            Application.Run(frm);
        }
예제 #15
0
        private void buttonQuery_Click(object sender, RoutedEventArgs e)
        {
            string query = txtQuery.Text;

            if (query.Length > 0)
            {
                TreeViewItem item = (TreeViewItem)treeCtrl.SelectedItem;
                if (item != null)
                {
                    ROMNode node = (ROMNode)item.Tag;
                    if (node != null)
                    {
                        try
                        {
                            if (checkQueryValue.IsChecked == true) //rule table input type attr query
                            {
                                ROMNode[] results = node.FindObjects(query);
                                string    msg     = results.Length.ToString() + " Objects Found";
                                MessageBox.Show(msg, "XPATH Result", MessageBoxButton.OK);

                                //highlight the objects in the tree
                                foreach (ROMNode nodeRes in results)
                                {
                                    item = (TreeViewItem)treeCtrl.FindName("_" + nodeRes.GetROMGUID().Replace('-', '_'));
                                    if (item != null)
                                    {
                                        item.IsSelected = true;
                                        item.Foreground = new SolidColorBrush(Colors.Red);
                                        object       newParent = item.Parent;
                                        TreeViewItem parent    = null;
                                        if (newParent != null && newParent is TreeViewItem)
                                        {
                                            parent = (TreeViewItem)newParent;
                                        }
                                        while (parent != null)
                                        {
                                            parent.IsExpanded = true;
                                            newParent         = parent.Parent;
                                            if (newParent != null && newParent is TreeViewItem)
                                            {
                                                parent = (TreeViewItem)newParent;
                                            }
                                            else
                                            {
                                                parent = null;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                string msg = "value: ";
                                msg += node.EvaluateXPATH(query);
                                MessageBox.Show(msg, "XPATH Result", MessageBoxButton.OK);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Query error", MessageBoxButton.OK);
                        }
                    }
                }
            }
        }
예제 #16
0
파일: Form1.cs 프로젝트: e1d1s1/Logician
        private void SetupApplication()
        {
            string rulesPath = "HydraulicCylinderRules.xml";
            m_rules = new EDSEngine(rulesPath);

            m_rootNode = new ROMNode("HydraulicCylinder");

            if (!m_rules.IsOpen())
            {
                MessageBox.Show("Error loading rules file");
                Close();
            }

            m_rules.InputGetterDelegate = delegate(string name, object obj)
            {
                return ((ROMNode)obj).GetAttribute(name, false);
            };

            m_rootNode.Rules = m_rules;
            m_engine = new LinearEngine(m_rootNode, "HydraulicCylinderDictionary");
            m_engine.EvaluateAll();

            UpdateControls();
        }
예제 #17
0
파일: Program.cs 프로젝트: e1d1s1/Logician
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            frm = new MainForm();
            frm.Shown += delegate(object sender, EventArgs e)
            {
                long start = 0, elapsed = 0, testROMNodeStart = 0, testROMNodeEnd = 0;
                string msg;
                const int iMax = 1000;
                string filename = "test_project.gz";
                string rulesPath = "..\\..\\..\\..\\..\\EDSEngine\\EDSEngineTestApp\\" + filename;
                if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
                    rulesPath = args[0];

                Log("Creating the root node");
                ROMNode rootNode = new ApplicationObject("TestApplication", ObjectFactory);
                Log("Root created");

                Log("Setting some attributes");
                rootNode.SetAttribute("inputAttr1", "some value of test1");
                rootNode.SetAttribute("inputAttr2", "some value of test2");
                rootNode.SetAttribute("inputAttr3", "some value of test3");
                rootNode.SetAttribute("inputAttr3", "test3a", "some sub value of attr3_a");
                rootNode.SetAttribute("inputAttr3", "test3b", "some sub value of attr3_b");
                Log("Attrs set");

                CreateChildNodes(rootNode);
                ROMNode[] findTest = rootNode.FindAllObjectsByID("DerivedObject", true);
                ROMNode[] findTestXPATH = rootNode.FindObjects("//Object[@id='DerivedObject']");
                ROMNode[] findTestXPATH2 = rootNode.FindObjects("//Object[@id='DerivedObject2']");
                if (findTest.Length == 1 && findTestXPATH.Length == 1 && findTestXPATH2.Length == 1 &&
                    findTest[0].GetROMGUID() == findTestXPATH[0].GetROMGUID() &&
                    findTestXPATH2[0].GetROMObjectID() == "DerivedObject2")
                    Log("OK");
                else
                    Log("FAILURE creating/obtaining child object");

                Log("Dump current xml state");
                string s = rootNode.SaveXML(true);
                Log(s);

                Log("Cloning the root object");
                var clonedObj = rootNode.Clone();
                string testClone = clonedObj.SaveXML(true);
                var rootChildCnt = rootNode.GetAllChildren(true).Length;
                var cloneChildCnt = clonedObj.GetAllChildren(true).Length;
                if (s.Length == testClone.Length &&
                    rootChildCnt == cloneChildCnt)
                    Log("Clone OK");
                else
                    Log("FAILURE Cloning root");

                Log("Test the object factory and inheritence pattern on the clone");
                ApplicationObject rootTest = (ApplicationObject)clonedObj.FindAllObjectsByID("TestApplication", true)[0];
                DerivedObject2 childTest = (DerivedObject2)clonedObj.FindObjects("//Object[@id='DerivedObject2']")[0];
                if (rootTest.GetAttribute("CLASS", true) == "ApplicationObject" &&
                    childTest.GetAttribute("CLASS", true) == "DerivedObject2")
                    Log("inheritence OK");
                else
                    Log("FAILURE in inheritence pattern of cloned object");

                Log("Test loading from xml");
                ROMNode loadedObj = ROMNode.LoadXMLFromString(s, ObjectFactory);
                string testLoaded = loadedObj.SaveXML(true);
                if (s.Length == testLoaded.Length &&
                    rootNode.GetAllChildren(true).Length == loadedObj.GetAllChildren(true).Length)
                    Log("XML loading OK");
                else
                    Log("FAILURE loading from xml");

                Log("Test the object factory and inheritence pattern of loaded xml");
                rootTest = (ApplicationObject)loadedObj.FindAllObjectsByID("TestApplication", true)[0];
                childTest = (DerivedObject2)loadedObj.FindObjects("//Object[@id='DerivedObject2']")[0];
                if (rootTest.GetAttribute("CLASS", true) == "ApplicationObject" &&
                    childTest.GetAttribute("CLASS", true) == "DerivedObject2")
                    Log("inheritence OK");
                else
                    Log("FAILURE in inheritence pattern of loaded xml");

                Log("Test for equlity");
                DerivedObject2 childTest2 = (DerivedObject2)loadedObj.FindObjects("//Object[@id='DerivedObject2']")[0];
                if (childTest == childTest2 && childTest != rootTest)
                    Log("equality test OK");
                else
                    Log("FAILURE equality test");

                Log("Setting attrs to test eval, inputAttr1 = A, inputAttr2 = 10, outsideAttr1 = 28");
                rootNode.SetAttribute("inputAttr1", "A");
                rootNode.SetAttribute("inputAttr2", "10");
                rootNode.SetAttribute("outsideAttr1", "28");
                Log("loading rules: " + rulesPath);

                EDSNET.EDSEngine rules = new EDSNET.EDSEngine(rulesPath);
                if (!rules.IsOpen())
                    rules = new EDSNET.EDSEngine(filename);
                if (rules.IsOpen())
                {
                    rules.DebugDelegate = DebugMessage;
                    rules.EnableRemoteDebugger(false);
                    EDSNET.InputValueGetterDelegate getValueDelegate = (string attrName, object context) =>
                    {
                        ROMNode objContext = (ROMNET.ROMNode)context;
                        return objContext.GetAttribute(attrName, false);
                    };
                    rules.InputGetterDelegate = getValueDelegate;

                    rootNode.Rules = rules;

                    Log("...loaded");
                    Log("Evaluating table testtable1");
                    string[] res = rootNode.EvaluateTable("testtable1", "outputAttr1", true);
                    foreach (string str in res)
                    {
                        Log(str);
                    }
                    Log("Evaluation complete");

                    Log("Evaluating table testtable2: out1");
                    string[] res2 = rootNode.EvaluateTable("testtable2", "out1", true);
                    foreach (string str in res2)
                    {
                        Log(str);
                    }
                    Log("Evaluation complete");

                    Log("Testing the LinearEngine class");
                    LinearEngine engine = new LinearEngine(rootNode, "Dictionary");
                    engine.InitializeEngine();

                    Log("Checking dictionary size");
                    Dictionary<string, ROMDictionaryAttribute> attrs = engine.GetAllDictionaryAttrs();
                    if (attrs.Count == 6)
                        Log("size ok");
                    else
                        Log("FAILURE loading dictionary");

                    ROMDictionaryAttribute[] order = engine.GetEvalList();
                    if (order != null && order.Length == 6 &&
                        order[0].Name == "cDictAttr1" &&
                        order[1].Name == "dDictAttr2" &&
                        order[2].Name == "aDictAttr3" &&
                        order[3].Name == "bDictAttr4" &&
                        order[4].Name == "eDictAttr5" &&
                        order[5].Name == "eDictAttr6")
                        Log("Order OK");
                    else
                        Log("FAILURE to assess the evaluation order");

                    Dictionary<string, string[]> triggers = engine.GetTriggers();
                    if (triggers.Count == 3 &&
                    triggers["aDictAttr3"].Length == 2 &&
                    triggers["aDictAttr3"][0] == "bDictAttr4" &&
                    triggers["aDictAttr3"][1] == "eDictAttr5")
                        Log("Triggers OK");
                    else
                        Log("FAILURE to assess the triggers");

                    Log("Testing evaluation");
                    engine.EvaluateAll();
                    ROMDictionaryAttribute attr1 = engine.GetDictionaryAttr("cDictAttr1");
                    ROMDictionaryAttribute attr2 = engine.GetDictionaryAttr("dDictAttr2");
                    if (attr2.AvailableValues.Length == 0 && attr2.PossibleValues.Length == 3 &&
                        attr1.AvailableValues.Length == 4)
                        Log("Default Eval OK");
                    else
                        Log("FAILURE to initially evaluate an attribute");

                    engine.EvaluateForAttribute("cDictAttr1", attr1.AvailableValues[0]);
                    string val_pick1 = rootNode.GetAttribute("dDictAttr2");
                    string val_bool1 = rootNode.GetAttribute("aDictAttr3");
                    string val_multi1 = rootNode.GetAttribute("bDictAttr4");
                    string edit1 = rootNode.GetAttribute("eDictAttr5");
                    engine.EvaluateForAttribute("cDictAttr1", attr1.AvailableValues[1]);
                    string val_pick2 = rootNode.GetAttribute("dDictAttr2");
                    string val_bool2 = rootNode.GetAttribute("aDictAttr3");
                    engine.EvaluateForAttribute("cDictAttr1", attr1.AvailableValues[2]);
                    string val_bool3 = rootNode.GetAttribute("aDictAttr3");
                    string val_multi3 = rootNode.GetAttribute("bDictAttr4");
                    engine.EvaluateForAttribute("eDictAttr5", "999");
                    string edit4 = rootNode.GetAttribute("eDictAttr5");
                    if (val_pick1 == "ResultByOption1" && val_pick2 == "Result2" &&
                        val_bool1 == "Y" && val_bool2 == "Y" && val_bool3 == "N" &&
                        val_multi1 == "Selection2|Selection3" && val_multi3 == "Selection2" &&
                        edit1 == "10" && edit4 == "50")
                        Log("Evaluation of attributes ok");
                    else
                        Log("FAILURE to evaluate an attribute");

                    start = Environment.TickCount;
                    testROMNodeStart = start;
                    Log("Stress Testing...");
                    Log("Setting a bunch of values...");
                    for (int i = 0; i < iMax; i++)
                    {
                        string attrToSet = "attr";
                        attrToSet += i.ToString();
                        rootNode.SetAttribute(attrToSet, i.ToString());
                    }
                    Log("Retrieving a bunch of values...");
                    for (int i = 0; i < iMax; i++)
                    {
                        string attrToGet = "attr";
                        attrToGet += i.ToString(); ;
                        rootNode.GetAttribute(attrToGet);
                    }
                    elapsed = Environment.TickCount - start;
                    msg = "attribute test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    start = Environment.TickCount;
                    Log("Create a large object heierarchy for querey testing");
                    for (int i = 0; i < iMax; i++)
                    {
                        string objectToCreate = "SubLevel1Object";
                        objectToCreate += i.ToString();
                        ROMNode newNode = new ROMNode(objectToCreate);
                        rootNode.AddChildROMObject(newNode);

                        objectToCreate = "SubLevel2Object";
                        objectToCreate += i.ToString();
                        ROMNode newNode2 = new ROMNode(objectToCreate);
                        newNode.AddChildROMObject(newNode2);
                        newNode2.SetAttribute("sumtester", "1");
                        newNode2.SetAttribute("sumtester2", "2");
                        newNode2.SetAttribute("sumtester3", "3");
                        newNode2.SetAttribute("testvalue", "value found");
                    }
                    elapsed = Environment.TickCount - start;
                    msg = "objects created in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    Log("Performing queries");
                    start = Environment.TickCount;
                    long queryTime = start;
                    string xpath = "sum(//Attribute[@id='sumtester']/@value)";
                    string xpathRes = rootNode.EvaluateXPATH(xpath);
                    elapsed = Environment.TickCount - start;
                    Log(xpath + " result: " + xpathRes);
                    msg = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    start = Environment.TickCount;
                    string xpath2 = "sum(//Attribute[@id='sumtester2']/@value)";
                    string xpathRes2 = rootNode.EvaluateXPATH(xpath2);
                    elapsed = Environment.TickCount - start;
                    Log(xpath2 + " result: " + xpathRes2);
                    msg = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    Log("altering the object state");
                    rootNode.SetAttribute("Change", "Y");

                    start = Environment.TickCount;
                    string xpath3 = "sum(//Attribute[@id='sumtester3']/@value)";
                    string xpathRes3 = rootNode.EvaluateXPATH(xpath3);
                    elapsed = Environment.TickCount - start;
                    Log(xpath3 + " result: " + xpathRes3);
                    msg = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    start = Environment.TickCount;
                    string xpath4 = "//Object[@id='SubLevel2Object10']/Attribute[@id='testvalue']/@value";
                    string xpathRes4 = rootNode.EvaluateXPATH(xpath4);
                    long finished = Environment.TickCount;
                    testROMNodeEnd = finished;
                    elapsed = finished - start;
                    Log(xpath4 + " result: " + xpathRes4);
                    msg = "object query test complete in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);
                    elapsed = finished - queryTime;
                    msg = "All object query tests completed in ";
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);

                    msg = "stress test total time: ";
                    elapsed = testROMNodeEnd - testROMNodeStart;
                    msg += elapsed.ToString();
                    msg += "ms";
                    Log(msg);
                }
                else
                    Log("Could not load rules");

                Log("Testing complete...press any key to exit");
                Console.ReadLine();
            };

            Application.Run(frm);
        }
예제 #18
0
파일: Program.cs 프로젝트: e1d1s1/Logician
 private static void CreateChildNodes(ROMNode rootNode)
 {
     Log("Creating a child object");
     ROMNode childNode = ObjectFactory("DerivedObject");
     rootNode.AddChildROMObject(childNode);
     childNode.SetAttribute("childAttr", "some value of value");
     //setting a value on the Object Node
     childNode.SetROMObjectValue("valueTest", "myValue");
     ROMNode childOfChild = ObjectFactory("DerivedObject2");
     childNode.AddChildROMObject(childOfChild);
 }