Exemplo n.º 1
0
        public string ToString(bool includeaction = false, bool multi = false)          // multi means quoting needed for ) as well as comma space
        {
            string ret = "";

            if (includeaction)
            {
                ret += eventname.QuoteString(comma: true) + ", " + action.QuoteString(comma: true) + ", " + actiondata.QuoteString(comma: true) + ", ";
            }

            for (int i = 0; fields != null && i < fields.Count; i++)
            {
                if (i > 0)
                {
                    ret += " " + innercondition.ToString() + " ";
                }

                if (ConditionEntry.IsNullOperation(fields[i].matchtype))
                {
                    ret += "Condition " + ConditionEntry.OperatorNames[(int)fields[i].matchtype];
                }
                else
                {
                    ret += (fields[i].itemname).QuoteString(bracket: multi) +               // commas do not need quoting as conditions at written as if always at EOL.
                           " " + ConditionEntry.OperatorNames[(int)fields[i].matchtype];

                    if (!ConditionEntry.IsUnaryOperation(fields[i].matchtype))
                    {
                        ret += " " + fields[i].matchstring.QuoteString(bracket: multi);     // commas do not need quoting..
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
        public string Read(string line)         // decode a set of multi conditions (<cond> Or <cond>) Outer (<cond> And <cond>) etc
        {
            StringParser sp = new StringParser(line);

            bool multi = false;

            string delimchars = " ";

            if (sp.IsCharMoveOn('('))
            {
                multi      = true;
                delimchars = ") ";
            }

            List <Condition> cllist = new List <Condition>();

            ConditionEntry.LogicalCondition outercond = ConditionEntry.LogicalCondition.Or;         // first outer condition is ignored in a list.  Or is the default.

            while (true)
            {
                Condition c = new Condition();

                string err = c.Read(sp, delimchars: delimchars);
                if (err.Length > 0)
                {
                    return(err);
                }

                c.outercondition = outercond;
                cllist.Add(c);            // add..

                if (sp.IsCharMoveOn(')')) // if closing bracket..
                {
                    if (!multi)
                    {
                        return("Closing condition bracket found but no opening bracket present");
                    }

                    if (sp.IsEOL)  // EOL, end of  (cond..cond) outercond ( cond cond)
                    {
                        conditionlist = cllist;
                        return(null);
                    }
                    else
                    {
                        err = ConditionEntry.GetLogicalCondition(sp, delimchars, out outercond);
                        if (err.Length > 0)
                        {
                            return(err + " for outer condition");
                        }

                        if (!sp.IsCharMoveOn('(')) // must have another (
                        {
                            return("Missing opening bracket in multiple condition list after " + outercond.ToString());
                        }
                    }
                }
                else if (sp.IsEOL) // last condition
                {
                    if (multi)
                    {
                        return("Missing closing braket in multiple condition list");
                    }

                    conditionlist = cllist;
                    return(null);
                }
                else
                {
                    return("Extra characters beyond expression");
                }
            }
        }