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); }
// list into CV the variables needed for the condition entry list public void IndicateValuesNeeded(ref Variables vr) { foreach (ConditionEntry fd in fields) { if (!ConditionEntry.IsNullOperation(fd.matchtype) && !fd.itemname.Contains("%")) // nulls need no data.. nor does anything with expand in { vr[fd.itemname] = null; } } }
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) + ", "; if (ActionVars.Count == 0) { ret += "\"\", "; } else { string v = ActionVars.ToString(); if (v.Contains("\"") || v.Contains(",")) { ret += "\"" + v.Replace("\"", "\\\"") + "\", "; // verified 12/06/2020 } else { ret += v + ", "; } } } for (int i = 0; Fields != null && i < Fields.Count; i++) { if (i > 0) { ret += " " + InnerCondition.ToString() + " "; } if (ConditionEntry.IsNullOperation(Fields[i].MatchCondition)) { ret += "Condition " + ConditionEntry.OperatorNames[(int)Fields[i].MatchCondition]; } 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].MatchCondition]; if (!ConditionEntry.IsUnaryOperation(Fields[i].MatchCondition)) { ret += " " + Fields[i].MatchString.QuoteString(bracket: multi); // commas do not need quoting.. } } } return(ret); }
// 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"); } } } }
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"); } } } }