示例#1
0
        // if includeevent is set, it must be there..
        // demlimchars is normally space, but can be ") " if its inside a multi.

        public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ")
        {
            Fields         = new List <ConditionEntry>();
            InnerCondition = OuterCondition = LogicalCondition.Or;
            EventName      = ""; Action = "";
            ActionVars     = new Variables();

            if (includeevent)
            {
                string actionvarsstr;
                if ((EventName = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (Action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (actionvarsstr = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(','))
                {
                    return("Incorrect format of EVENT data associated with condition");
                }

                if (actionvarsstr.HasChars())
                {
                    ActionVars = new Variables(actionvarsstr, Variables.FromMode.MultiEntryComma);
                }
            }

            LogicalCondition?ic = null;

            while (true)
            {
                string var = sp.NextQuotedWord(delimchars);             // always has para cond
                if (var == null)
                {
                    return("Missing parameter (left side) of condition");
                }

                string cond = sp.NextQuotedWord(delimchars);
                if (cond == null)
                {
                    return("Missing condition operator");
                }

                ConditionEntry.MatchType mt;
                if (!ConditionEntry.MatchTypeFromString(cond, out mt))
                {
                    return("Condition operator " + cond + " is not recognised");
                }

                string value = "";

                if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..)
                {
                    if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return("Condition must preceed fixed result operator");
                    }
                    var = "Condition";                         // fix case..
                }
                else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side
                {
                    value = sp.NextQuotedWord(delimchars);
                    if (value == null)
                    {
                        return("Missing value part (right side) of condition");
                    }
                }

                ConditionEntry ce = new ConditionEntry()
                {
                    ItemName = var, MatchCondition = mt, MatchString = value
                };
                Fields.Add(ce);

                if (sp.IsEOL || sp.PeekChar() == ')')           // end is either ) or EOL
                {
                    InnerCondition = (ic == null) ? LogicalCondition.Or : ic.Value;
                    return("");
                }
                else
                {
                    LogicalCondition nic;
                    string           err = GetLogicalCondition(sp, delimchars, out nic);
                    if (err.Length > 0)
                    {
                        return(err + " for inner condition");
                    }

                    if (ic == null)
                    {
                        ic = nic;
                    }
                    else if (ic.Value != nic)
                    {
                        return("Cannot specify different inner conditions between expressions");
                    }
                }
            }
        }
示例#2
0
        public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ") // if includeevent is set, it must be there..
        {                                                                                                 // demlimchars is normally space, but can be ") " if its inside a multi.
            fields         = new List <ConditionEntry>();
            innercondition = outercondition = ConditionEntry.LogicalCondition.Or;
            eventname      = ""; action = ""; actiondata = "";

            if (includeevent)
            {
                if ((eventname = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                    (actiondata = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(','))
                {
                    return("Incorrect format of EVENT data associated with condition");
                }
            }

            ConditionEntry.LogicalCondition?ic = null;

            while (true)
            {
                string var = sp.NextQuotedWord(delimchars);             // always has para cond
                if (var == null)
                {
                    return("Missing parameter (left side) of condition");
                }

                string cond = sp.NextQuotedWord(delimchars);
                if (cond == null)
                {
                    return("Missing condition operator");
                }

                ConditionEntry.MatchType mt;
                if (!ConditionEntry.MatchTypeFromString(cond, out mt))
                {
                    return("Condition operator " + cond + " is not recognised");
                }

                string value = "";

                if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..)
                {
                    if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return("Condition must preceed fixed result operator");
                    }
                    var = "Condition";                         // fix case..
                }
                else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side
                {
                    value = sp.NextQuotedWord(delimchars);
                    if (value == null)
                    {
                        return("Missing value part (right side) of condition");
                    }
                }

                ConditionEntry ce = new ConditionEntry()
                {
                    itemname = var, matchtype = mt, matchstring = value
                };
                fields.Add(ce);

                if (sp.IsEOL || sp.PeekChar() == ')')           // end is either ) or EOL
                {
                    innercondition = (ic == null) ? ConditionEntry.LogicalCondition.Or : ic.Value;
                    return("");
                }
                else
                {
                    ConditionEntry.LogicalCondition nic;
                    string err = ConditionEntry.GetLogicalCondition(sp, delimchars, out nic);
                    if (err.Length > 0)
                    {
                        return(err + " for inner condition");
                    }

                    if (ic == null)
                    {
                        ic = nic;
                    }
                    else if (ic.Value != nic)
                    {
                        return("Cannot specify different inner conditions between expressions");
                    }
                }
            }
        }