Esempio n. 1
0
        public int ActionRun(string triggername, string triggertype, HistoryEntry he = null, ConditionVariables additionalvars = null,
                             string flagstart = null, bool now = false)                                         //set flagstart to be the first flag of the actiondata..
        {
            List <ActionFileList.MatchingSets> ale = actionfiles.GetMatchingConditions(triggername, flagstart); // look thru all actions, find matching ones

            if (ale.Count > 0)
            {
                ConditionVariables eventvars = new ConditionVariables();
                Actions.ActionVars.TriggerVars(eventvars, triggername, triggertype);
                Actions.ActionVars.HistoryEventVars(eventvars, he, "Event");                      // if HE is null, ignored
                Actions.ActionVars.ShipBasicInformation(eventvars, he?.ShipInformation, "Event"); // if He null, or si null, ignore
                Actions.ActionVars.SystemVars(eventvars, he?.System, "Event");
                eventvars.Add(additionalvars);                                                    // adding null is allowed

                ConditionVariables testvars = new ConditionVariables(globalvariables);
                testvars.Add(eventvars);

                ConditionFunctions functions = new ConditionFunctions(testvars, null);

                if (actionfiles.CheckActions(ale, he?.journalEntry, testvars, functions) > 0)
                {
                    actionfiles.RunActions(now, ale, actionrunasync, eventvars); // add programs to action run

                    actionrunasync.Execute();                                    // See if needs executing
                }
            }

            return(ale.Count);
        }
Esempio n. 2
0
        public int ActionRun(ActionEvent ev, HistoryEntry he = null, ConditionVariables additionalvars = null,
                             string flagstart = null, bool now = false)                                            //set flagstart to be the first flag of the actiondata..
        {
            List <ActionFileList.MatchingSets> ale = actionfiles.GetMatchingConditions(ev.TriggerName, flagstart); // look thru all actions, find matching ones

            if (ale.Count > 0)
            {
                ConditionVariables eventvars = new ConditionVariables();
                Actions.ActionVars.TriggerVars(eventvars, ev.TriggerName, ev.TriggerType);
                Actions.ActionVars.HistoryEventVars(eventvars, he, "Event");                      // if HE is null, ignored
                Actions.ActionVars.ShipBasicInformation(eventvars, he?.ShipInformation, "Event"); // if He null, or si null, ignore
                Actions.ActionVars.SystemVars(eventvars, he?.System, "Event");
                eventvars.Add(additionalvars);                                                    // adding null is allowed

                //System.Diagnostics.Debug.WriteLine("Dispatch Program with" + Environment.NewLine + eventvars.ToString(prefix:".. ", separ: Environment.NewLine));

                ConditionVariables testvars = new ConditionVariables(Globals);
                testvars.Add(eventvars);

                ConditionFunctions functions = new ConditionFunctions(testvars, null);

                if (actionfiles.CheckActions(ale, he?.journalEntry, testvars, functions) > 0)
                {
                    actionfiles.RunActions(now, ale, actionrunasync, eventvars); // add programs to action run

                    actionrunasync.Execute();                                    // See if needs executing
                }
            }

            return(ale.Count);
        }
Esempio n. 3
0
 public ActionFile(ConditionLists c, ActionProgramList p, string f, string n, bool e, ConditionVariables ivar = null)
 {
     actionfieldfilter = c;
     actionprogramlist = p;
     filepath          = f;
     name    = n;
     enabled = e;
     installationvariables = new ConditionVariables();
     if (ivar != null)
     {
         installationvariables.Add(ivar);
     }
 }
Esempio n. 4
0
        // now = true run immediately, else defer to current programs
        public void RunActions(bool now, List <Actions.ActionFileList.MatchingSets> ale, ActionRun run, ConditionVariables inputparas)
        {
            foreach (Actions.ActionFileList.MatchingSets ae in ale)                       // for every file which passed..
            {
                foreach (ConditionLists.Condition fe in ae.passed)                        // and every condition..
                {
                    Tuple <ActionFile, ActionProgram> ap = FindProgram(fe.action, ae.af); // find program using this name, prefer this action file first

                    if (ap != null)                                                       // program got,
                    {
                        ConditionVariables adparas = new ConditionVariables();
                        string             flags;
                        adparas.FromActionDataString(fe.actiondata, out flags);

                        inputparas.Add(adparas);

                        run.Run(now, ap.Item1, ap.Item2, inputparas);
                    }
                }
            }
        }
Esempio n. 5
0
        // triage found actions and see which ones are runnable
        // cls = object from which to get any needed values from, can be null
        // if se is set passed enabled string expansion of arguments in condition of event..

        public int CheckActions(List <Actions.ActionFileList.MatchingSets> ale, Object cls, ConditionVariables othervars,
                                ConditionFunctions se = null)
        {
            ConditionVariables valuesneeded = new ConditionVariables();

            if (cls != null)
            {
                foreach (MatchingSets ae in ale)                   // for all files
                {
                    foreach (ConditionLists.Condition fe in ae.cl) // find all values needed
                    {
                        fe.IndicateValuesNeeded(ref valuesneeded);
                    }
                }

                valuesneeded.GetValuesIndicated(cls);     // get the values needed for the conditions
            }

            valuesneeded.Add(othervars);

            int progs = 0;

            ConditionFunctions cf = new ConditionFunctions(valuesneeded, null);

            foreach (MatchingSets ae in ale)       // for all files
            {
                string errlist = null;
                ae.passed = new List <ConditionLists.Condition>();

                //System.Diagnostics.Debug.WriteLine("Check `" + ae.af.name + ae.af.actionfieldfilter.ToString() + "`");
                //ActionData.DumpVars(valuesneeded, " Test var:");

                ae.af.actionfieldfilter.CheckConditions(ae.cl, valuesneeded, out errlist, ae.passed, cf);   // indicate which ones passed
                progs += ae.passed.Count;
            }

            return(progs);
        }
Esempio n. 6
0
 public void Add(ConditionVariables v)
 {
     currentvars.Add(v);
 }
        //special call for execute, needs to pass back more data
        public bool ExecuteCallAction(ActionProgramRun ap, out string progname, out ConditionVariables vars)
        {
            Dictionary <string, string> altops;

            if (FromString(UserData, out progname, out vars, out altops) && progname.Length > 0)
            {
                List <string>      wildcards = new List <string>();
                ConditionVariables newitems  = new ConditionVariables();

                foreach (string key in vars.NameEnumuerable)
                {
                    int asterisk = key.IndexOf('*');
                    if (asterisk >= 0)                                    // SEE if any wildcards, if so, add to newitems
                    {
                        bool noexpand = altops[key].Contains("$");        // wildcard operator determines expansion state

                        wildcards.Add(key);
                        string prefix = key.Substring(0, asterisk);

                        foreach (string jkey in ap.variables.NameEnumuerable)
                        {
                            if (jkey.StartsWith(prefix))
                            {
                                if (noexpand)
                                {
                                    newitems[jkey] = ap[jkey];
                                }
                                else
                                {
                                    string res;
                                    if (ap.functions.ExpandString(ap[jkey], out res) == ConditionFunctions.ExpandResult.Failed)
                                    {
                                        ap.ReportError(res);
                                        return(false);
                                    }

                                    newitems[jkey] = res;
                                }
                            }
                        }
                    }
                }

                foreach (string w in wildcards)     // remove wildcards
                {
                    vars.Delete(w);
                }

                //foreach ( stKeyValuePair<string,string> k in vars.values)          // for the rest, before we add in wildcards, expand
                foreach (string k in vars.NameEnumuerable.ToList())     // for the rest, before we add in wildcards, expand. Note ToList
                {
                    bool noexpand = altops[k].Contains("$");            // when required

                    if (!noexpand)
                    {
                        string res;
                        if (ap.functions.ExpandString(vars[k], out res) == ConditionFunctions.ExpandResult.Failed)
                        {
                            ap.ReportError(res);
                            return(false);
                        }

                        vars[k] = res;
                    }
                }

                vars.Add(newitems);         // finally assemble the variables

                return(true);
            }
            else
            {
                ap.ReportError("Call not configured");
                return(false);
            }
        }