// Sees if two conditions are equal. Case insensitivity only for groupbname,eventname,action. Others the case is significant (variables, condition) public bool Equals(Condition c, StringComparison ci = StringComparison.InvariantCultureIgnoreCase) { return(GroupName.HasChars() && GroupName.Equals(c.GroupName, ci) && // groupname can be null EventName.Equals(c.EventName, ci) && Action.Equals(c.Action, ci) && ActionVars.ToString() == c.ActionVars.ToString() && ToString(false) == c.ToString(false)); }
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 field is empty/null, not considered. wildcard match of any of the fields public bool WildCardMatch(string groupname, string eventname, string actionstr, string actionvarstr, string condition, bool caseinsensitive = true) { if ((groupname.HasChars() && GroupName.HasChars() && GroupName.WildCardMatch(groupname, caseinsensitive)) || // groupname can be null (eventname.HasChars() && EventName.WildCardMatch(eventname, caseinsensitive)) || (actionstr.HasChars() && Action.WildCardMatch(actionstr, caseinsensitive)) || (actionvarstr.HasChars() && ActionVars.ToString().WildCardMatch(actionvarstr, caseinsensitive))) { return(true); } if (condition.HasChars()) { string cond = ToString(false); if (cond.WildCardMatch(condition, caseinsensitive)) { return(true); } } return(false); }