Ejemplo n.º 1
0
 public Condition(string e, string a, Variables ad, List <ConditionEntry> f, ConditionEntry.LogicalCondition i = ConditionEntry.LogicalCondition.Or, ConditionEntry.LogicalCondition o = ConditionEntry.LogicalCondition.Or)
 {
     eventname      = e;
     action         = a;
     actionvars     = new Variables(ad);
     innercondition = i;
     outercondition = o;
     fields         = f;
 }
Ejemplo n.º 2
0
 public Condition(string e, string a, string ad, List <ConditionEntry> f, ConditionEntry.LogicalCondition i = ConditionEntry.LogicalCondition.Or, ConditionEntry.LogicalCondition o = ConditionEntry.LogicalCondition.Or)
 {
     eventname      = e;
     action         = a;
     actiondata     = ad;
     innercondition = i;
     outercondition = o;
     fields         = f;
 }
Ejemplo n.º 3
0
        public bool FromJSON(JObject jo)        // rechecked 31/7/2020 with quickjson
        {
            try
            {
                Clear();

                JArray jf = (JArray)jo["FilterSet"];

                foreach (JObject j in jf)
                {
                    // verified 31/7/2020 with baseutils.JSON.   If object not present, returns JNotPresent and Str() returns default
                    string evname = (string)j["EventName"];
                    ConditionEntry.LogicalCondition ftinner = (ConditionEntry.LogicalCondition)Enum.Parse(typeof(ConditionEntry.LogicalCondition), j["ICond"].Str("Or"));
                    ConditionEntry.LogicalCondition ftouter = (ConditionEntry.LogicalCondition)Enum.Parse(typeof(ConditionEntry.LogicalCondition), j["OCond"].Str("Or"));
                    string act  = j["Actions"].Str();
                    string actd = j["ActionData"].Str();

                    JArray filset = (JArray)j["Filters"];

                    List <ConditionEntry> fieldlist = new List <ConditionEntry>();

                    foreach (JObject j2 in filset)
                    {
                        string item      = (string)j2["Item"];
                        string content   = (string)j2["Content"];
                        string matchtype = (string)j2["Matchtype"];

                        fieldlist.Add(new ConditionEntry()
                        {
                            itemname    = item,
                            matchstring = content,
                            matchtype   = (ConditionEntry.MatchType)Enum.Parse(typeof(ConditionEntry.MatchType), matchtype)
                        });
                    }

                    conditionlist.Add(new Condition()
                    {
                        eventname      = evname,
                        innercondition = ftinner,
                        outercondition = ftouter,
                        fields         = fieldlist,
                        action         = act,
                        actionvars     = new Variables(actd, Variables.FromMode.MultiEntryComma)
                    });
                }

                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Bad condition JSON:" + ex);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool FromJSON(JObject jo)
        {
            try
            {
                Clear();

                JArray jf = (JArray)jo["FilterSet"];

                foreach (JObject j in jf)
                {
                    string evname = (string)j["EventName"];
                    ConditionEntry.LogicalCondition ftinner = (ConditionEntry.LogicalCondition)Enum.Parse(typeof(ConditionEntry.LogicalCondition), j["ICond"].Str("Or"));
                    ConditionEntry.LogicalCondition ftouter = (ConditionEntry.LogicalCondition)Enum.Parse(typeof(ConditionEntry.LogicalCondition), j["OCond"].Str("Or"));
                    string act  = j["Actions"].Str();
                    string actd = j["ActionData"].Str();

                    JArray filset = (JArray)j["Filters"];

                    List <ConditionEntry> fieldlist = new List <ConditionEntry>();

                    foreach (JObject j2 in filset)
                    {
                        string item      = (string)j2["Item"];
                        string content   = (string)j2["Content"];
                        string matchtype = (string)j2["Matchtype"];

                        fieldlist.Add(new ConditionEntry()
                        {
                            itemname    = item,
                            matchstring = content,
                            matchtype   = (ConditionEntry.MatchType)Enum.Parse(typeof(ConditionEntry.MatchType), matchtype)
                        });
                    }

                    conditionlist.Add(new Condition()
                    {
                        eventname      = evname,
                        innercondition = ftinner,
                        outercondition = ftouter,
                        fields         = fieldlist,
                        action         = act,
                        actiondata     = actd
                    });
                }

                return(true);
            }
            catch { }

            return(false);
        }
Ejemplo n.º 5
0
        public bool Create(string e, string a, string d, string i, string o)   // i,o can have spaces inserted into enum
        {
            try
            {
                eventname      = e;
                action         = a;
                actionvars     = new Variables(a, Variables.FromMode.MultiEntryComma);
                innercondition = (ConditionEntry.LogicalCondition)Enum.Parse(typeof(ConditionEntry.LogicalCondition), i.Replace(" ", ""), true);       // must work, exception otherwise
                outercondition = (ConditionEntry.LogicalCondition)Enum.Parse(typeof(ConditionEntry.LogicalCondition), o.Replace(" ", ""), true);       // must work, exception otherwise
                return(true);
            }
            catch { }

            return(false);
        }
Ejemplo n.º 6
0
 public Condition(Condition other)   // full clone
 {
     eventname = other.eventname;
     if (other.fields != null)
     {
         fields = new List <ConditionEntry>();
         foreach (ConditionEntry e in other.fields)
         {
             fields.Add(new ConditionEntry(e));
         }
     }
     innercondition = other.innercondition;
     outercondition = other.outercondition;
     action         = other.action;
     actionvars     = new Variables(other.actionvars);
 }
Ejemplo n.º 7
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");
                }
            }
        }
Ejemplo n.º 8
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 = "";
            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");
                    }
                }
            }
        }