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"); } } }
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 = ""; 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); } } 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"); } } } }