Exemple #1
0
        /// <summary>
        /// This constructor is called when tests are inside an element
        /// </summary>
        /// <param name="element"></param>
        /// <param name="propertyManager"></param>
        public Condition(XmlElement element, PropertyManager propertyManager)
        {
            InitializeConditionals();

            string logic = element.GetAttribute("logic");

            if (!string.IsNullOrEmpty(logic))
            {
                if (logic.Equals("OR"))
                {
                    Logic = eLogic.eOR;
                }
                else if (logic.Equals("AND"))
                {
                    Logic = eLogic.eAND;
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Unrecognized LOGIC token " + logic + " in switch component.");
                    }
                    throw new Exception("Unrecognized LOGIC token " + logic + " in switch component");
                }
            }
            else
            {
                Logic = eLogic.eAND; // default
            }

            ReaderText rtxt = new ReaderText(new StringReader(element.InnerText));

            while (rtxt.Done)
            {
                string tmp = rtxt.ReadLine().Trim();
                conditions.Add(new Condition(tmp, propertyManager));
            }
            string elName = element.Name;

            foreach (XmlNode currentNode in element.ChildNodes)
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    XmlElement condition_element = currentNode as XmlElement;
                    string     tagName           = condition_element.Name;

                    if (tagName != elName)
                    {
                        log.Error("Unrecognized tag <" + tagName + "> in the condition statement.");
                        throw new Exception("Illegal argument");
                    }
                    conditions.Add(new Condition(currentNode as XmlElement, propertyManager));
                }
            }
        }
Exemple #2
0
        public Condition(XmlElement element, PropertyManager propertyManager)
        {
            string logic;

            isGroup = true;

            InitializeConditionals();

            logic = element.GetAttribute("logic");
            if (logic.Equals("OR"))
            {
                Logic = eLogic.eOR;
            }
            else if (logic.Equals("AND"))
            {
                Logic = eLogic.eAND;
            }
            else
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Unrecognized LOGIC token " + logic + " in switch component.");
                }
                throw new Exception("Unrecognized LOGIC token " + logic + " in switch component");
            }

            foreach (XmlNode currentNode in element.ChildNodes)
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    conditions.Add(new Condition(currentNode as XmlElement, propertyManager));
                }
            }

            ReaderText rtxt = new ReaderText(new StringReader(element.InnerText));

            while (rtxt.Done)
            {
                string tmp = rtxt.ReadLine().Trim();
                conditions.Add(new Condition(tmp, propertyManager));
            }
        }
Exemple #3
0
        private void FindNumColumnsAndLines(string test_line, out int numColumns, out int numLines)
        {
            // determine number of data columns in table (first column is row lookup - don't count)
            ReaderText rtxt = new ReaderText(new StringReader(test_line));

            numLines   = 0;
            numColumns = 0;
            while (rtxt.Done)
            {
                string tmp = rtxt.ReadLine().Trim();
                if (tmp.Length != 0)
                {
                    // determine number of data columns in table (first column is row lookup - don't count)
                    if (numColumns == 0)
                    {
                        ReaderText rcnt = new ReaderText(new StringReader(tmp));
                        while (rcnt.Done)
                        {
                            rcnt.ReadDouble();
                            if (rcnt.Done)
                            {
                                numColumns++;
                            }
                        }
                    }
                    numLines++;
                }
            }

            /*
             * int position=0;
             * int nCols=0;
             * while ((position = test_line.find_first_not_of(" \t", position)) != string::npos) {
             *  nCols++;
             *  position = test_line.find_first_of(" \t", position);
             * }
             * return nCols;
             */
        }
Exemple #4
0
        public Switch(FlightControlSystem fcs, XmlElement element)
            : base(fcs, element)
        {
            string     value, logic;
            TestSwitch current_test;

            foreach (XmlNode currentNode in element.ChildNodes)
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    XmlElement currentElement = (XmlElement)currentNode;

                    current_test = new TestSwitch();
                    if (currentElement.LocalName.Equals("default"))
                    {
                        tests.Add(current_test);
                        current_test.Logic = eLogic.eDefault;
                    }
                    else if (currentElement.LocalName.Equals("test"))
                    {
                        tests.Add(current_test);
                        logic = currentElement.GetAttribute("logic");
                        if (logic.Equals("OR"))
                        {
                            current_test.Logic = eLogic.eOR;
                        }
                        else if (logic.Equals("AND"))
                        {
                            current_test.Logic = eLogic.eAND;
                        }
                        else if (logic.Length == 0)
                        {
                            current_test.Logic = eLogic.eAND; // default
                        }
                        else
                        { // error
                            if (log.IsErrorEnabled)
                            {
                                log.Error("Unrecognized LOGIC token " + logic + " in switch component: " + name);
                            }
                        }

                        ReaderText rtxt = new ReaderText(new StringReader(currentElement.InnerText));
                        while (rtxt.Done)
                        {
                            string tmp = rtxt.ReadLine().Trim();
                            if (tmp.Length != 0)
                            {
                                current_test.conditions.Add(new Condition(tmp, propertyManager));
                            }
                        }

                        foreach (XmlNode currentNode2 in currentElement.ChildNodes)
                        {
                            if (currentNode2.NodeType == XmlNodeType.Element)
                            {
                                current_test.conditions.Add(new Condition(currentNode2 as XmlElement, propertyManager));
                            }
                        }
                    }

                    if (!currentElement.LocalName.Equals("output"))
                    {
                        value = currentElement.GetAttribute("value");
                        if (value.Length == 0)
                        {
                            if (log.IsErrorEnabled)
                            {
                                log.Error("No VALUE supplied for switch component: " + name);
                            }
                        }
                        else
                        {
                            Match match = testRegex.Match(value);
                            if (match.Success)
                            {
                                if (match.Groups["prop"].Value == "") // if true (and execution falls into this block), "value" is a number.
                                {
                                    current_test.OutputVal = double.Parse(value, FormatHelper.numberFormatInfo);
                                }
                                else
                                {
                                    // "value" must be a property if execution passes to here.
                                    if (value[0] == '-')
                                    {
                                        current_test.sign = -1.0;
                                        value             = value.Remove(0, 1);
                                    }
                                    else
                                    {
                                        current_test.sign = 1.0;
                                    }
                                    current_test.OutputProp = propertyManager.GetPropertyNode(value);
                                }
                            }
                        }
                    }
                }
            }
            base.Bind();
        }