Esempio n. 1
0
        private void DoExecute()    // MAIN thread only..
        {
            executing = true;

            System.Diagnostics.Stopwatch timetaken = new System.Diagnostics.Stopwatch();
            timetaken.Start();

            while (true)
            {
                if (progcurrent != null)
                {
                    if (progcurrent.GetErrorList != null)       // any errors pending, handle
                    {
                        actioncontroller.LogLine("Error: " + progcurrent.GetErrorList + Environment.NewLine + StackTrace());
                        TerminateToCloseAtEnd();            // terminate up to a close at end entry, which would have started this stack
                    }
                    else if (progcurrent.IsProgramFinished) // if current program ran out, cancel it
                    {
                        // this catches a LOOP without a statement at the end..  or a DO without a WHILE at the end..
                        if (progcurrent.ExecLevel > 0 && progcurrent.LevelUp(progcurrent.ExecLevel, null)) // see if we have any pending LOOP (or a DO without a while) and continue..
                        {
                            continue;                                                                      // errors or movement causes it to go back.. errors will be picked up above
                        }
                        TerminateCurrent();
                    }
                }

                while (progcurrent == null && progqueue.Count > 0)    // if no program,but something in queue
                {
                    progcurrent = progqueue[0];
                    progqueue.RemoveAt(0);

                    if (progcurrent.variables != null)                         // if not null, its because its just been restarted after a call.. reset globals
                    {
                        progcurrent.Add(actioncontroller.Globals);             // in case they have been updated...
                        progcurrent.Add(progcurrent.actionfile.filevariables); // in case they have been updated...
                    }
                    else
                    {
                        progcurrent.PrepareToRun(
                            new Variables(progcurrent.inputvariables, actioncontroller.Globals, progcurrent.actionfile.filevariables),
                            new FunctionPersistentData(),
                            new Dictionary <string, ExtendedControls.ConfigurableForm>(), true);    // with new file handles and close at end..
                    }

                    if (progcurrent.IsProgramFinished)          // reject empty programs..
                    {
                        TerminateCurrent();
                        continue;       // and try again
                    }
                }

                if (progcurrent == null)        // Still nothing, game over
                {
                    break;
                }

                ActionBase ac = progcurrent.GetNextStep();      // get the step. move PC on.

                //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " @ " + progcurrent.Location +" Lv " + progcurrent.ExecLevel + " e " + (progcurrent.IsExecuteOn ? "1" : "0") + " up " + ac.LevelUp + " " + progcurrent.PushPos + " " + ac.Name);

                if (ac.LevelUp > 0 && progcurrent.LevelUp(ac.LevelUp, ac))         // level up..
                {
                    //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Abort Lv" + progcurrent.ExecLevel + " e " + (progcurrent.IsExecuteOn ? "1" : "0") + " up " + ac.LevelUp + ": " + progcurrent.StepNumber + " " + ac.Name + " " + ac.DisplayedUserData);
                    continue;
                }

                if (logtologline || logger != null)
                {
                    string t     = (Environment.TickCount % 10000).ToString("00000") + " ";
                    string index = string.Concat(Enumerable.Repeat(". ", progcurrent.ExecLevel));
                    string s     = progcurrent.GetLastStep().LineNumber.ToString() + (progcurrent.IsExecuteOn ? "+" : "-") + ":" + index + ac.Name + " " + ac.DisplayedUserData;
                    System.Diagnostics.Debug.WriteLine(t + s);
                    if (logtologline)
                    {
                        actioncontroller.LogLine(t + s);
                    }
                    if (logger != null)
                    {
                        logger.WriteLine(s);
                    }
                }

                if (progcurrent.DoExecute(ac))                 // execute is on..
                {
                    if (ac.Type == ActionBase.ActionType.Call) // Call needs to pass info back up thru to us, need a different call
                    {
                        ActionCall acall = ac as ActionCall;
                        string     prog;
                        Variables  paravars;
                        if (acall.ExecuteCallAction(progcurrent, out prog, out paravars)) // if execute ok
                        {
                            //System.Diagnostics.Debug.WriteLine("Call " + prog + " with " + paravars.ToString());

                            Tuple <ActionFile, ActionProgram> ap = actionfilelist.FindProgram(prog, progcurrent.actionfile);          // find program using this name, prefer this action file first

                            if (ap != null)
                            {
                                Run(true, ap.Item1, ap.Item2, paravars, progcurrent.functions.persistentdata, progcurrent.dialogs, false);   // run now with these para vars
                            }
                            else
                            {
                                progcurrent.ReportError("Call cannot find " + prog);
                            }
                        }
                    }
                    else if (ac.Type == ActionBase.ActionType.Return)     // Return needs to pass info back up thru to us, need a different call
                    {
                        ActionReturn ar = ac as ActionReturn;
                        string       retstr;
                        if (ar.ExecuteActionReturn(progcurrent, out retstr))
                        {
                            TerminateCurrent();

                            // if a new program is queued, but not prepared, and this program returns to finish, make sure we don't
                            // screw up since the variables are not preparred yet - they will be above in PrepareToRun

                            if (progqueue.Count > 0 && progqueue[0].variables != null)         // pass return value if program is there AND its prepared
                            {
                                progqueue[0]["ReturnValue"] = retstr;
                            }

                            continue;       // back to top, next action from returned function.
                        }
                    }
                    else if (!ac.ExecuteAction(progcurrent)) // if execute says, stop, i'm waiting for something
                    {
                        return;                              // exit, with executing set true.  ResumeAfterPause will restart it.
                    }
                }

                if (AsyncMode && timetaken.ElapsedMilliseconds > 150)  // no more than ms per go to stop the main thread being blocked
                {
                    //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " *** SUSPEND");
                    restarttick.Start();
                    break;
                }
            }

            executing = false;
        }
Esempio n. 2
0
        public bool ExecuteAction(ActionProgramRun ap, bool setit, bool globalit = false, bool persistentit = false, bool staticit = false)
        {
            if (av == null)
            {
                FromString(userdata, out av, out operations);
            }

            foreach (string key in av.NameEnumuerable)
            {
                string keyname = key;

                if (keyname.Contains("%"))      // if its an expansion, got for expansion
                {
                    if (ap.functions.ExpandString(key, out keyname) == Functions.ExpandResult.Failed)
                    {
                        ap.ReportError(keyname);
                        break;
                    }
                }
                else
                {
                    keyname = ap.variables.Qualify(key);    // else allow name to be mangled
                }
                string res;

                if (operations[key].Contains("$"))
                {
                    res = av[key];
                }
                else if (ap.functions.ExpandString(av[key], out res) == Functions.ExpandResult.Failed)       //Expand out.. and if no errors
                {
                    ap.ReportError(res);
                    break;
                }

                if (setit)
                {
                    if (operations[key].Contains("+") && ap.VarExist(keyname))
                    {
                        res = ap[keyname] + res;
                    }
                }
                else
                {
                    Eval ev = new Eval(res, checkend: true, allowfp: true, allowstrings: false);

                    Object ret = ev.Evaluate();

                    if (ev.InError)
                    {
                        ap.ReportError(ev.ToString(System.Globalization.CultureInfo.InvariantCulture));
                        break;
                    }
                    else
                    {
                        res = ev.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    }
                }

                //System.Diagnostics.Debug.WriteLine("Var " + keyname + "=" + res + "  :" + globalit + ":" + persistentit);
                ap[keyname] = res;

                if (globalit)
                {
                    ap.actioncontroller.SetNonPersistentGlobal(keyname, res);
                }

                if (persistentit)
                {
                    ap.actioncontroller.SetPeristentGlobal(keyname, res);
                }

                if (staticit)
                {
                    ap.actionfile.SetFileVariable(keyname, res);
                }
            }

            if (av.Count == 0)
            {
                ap.ReportError("No variable name given in variable assignment");
            }

            return(true);
        }
Esempio n. 3
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.Functions.ExpandString(UserData, out res) != Functions.ExpandResult.Failed)
            {
                StringParser p = new StringParser(res);

                string cmd;
                while ((cmd = p.NextWordLCInvariant(" ")) != null)
                {
                    if (cmd.Equals("dumpvars"))
                    {
                        string rest = p.NextQuotedWord();

                        if (rest != null && rest.Length > 0)
                        {
                            Variables filtered = ap.variables.FilterVars(rest);
                            foreach (string key in filtered.NameEnumuerable)
                            {
                                ap.ActionController.LogLine(key + "=" + filtered[key]);
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing variable wildcard after Pragma DumpVars");
                            return(true);
                        }
                    }
                    else if (cmd.Equals("log"))
                    {
                        string rest = p.NextQuotedWord(replaceescape: true);

                        if (rest != null)
                        {
                            ap.ActionController.LogLine(rest);
                        }
                        else
                        {
                            ap.ReportError("Missing string after Pragma Log");
                            return(true);
                        }
                    }
                    else if (cmd.Equals("debug"))
                    {
                        string rest = p.NextQuotedWord(replaceescape: true);

                        if (rest != null)
                        {
#if DEBUG
                            ap.ActionController.LogLine(rest);
#endif
                        }
                        else
                        {
                            ap.ReportError("Missing string after Debug");
                        }
                        return(true);
                    }
                    else if (cmd.Equals("ignoreerrors"))
                    {
                        ap.SetContinueOnErrors(true);
                    }
                    else if (cmd.Equals("allowerrors"))
                    {
                        ap.SetContinueOnErrors(false);
                    }
                    else if (cmd.Equals("disableasync"))
                    {
                        ap.ActionController.AsyncMode = false;
                    }
                    else if (cmd.Equals("enableasync"))
                    {
                        ap.ActionController.AsyncMode = false;
                    }
                    else if (cmd.Equals("enabletrace"))
                    {
                        string file = p.NextQuotedWord();
                        ap.ActionController.DebugTrace(file == null, file);
                    }
                    else if (cmd.Equals("disabletrace"))
                    {
                        ap.ActionController.DebugTrace(false);
                    }
                    else if (!ap.ActionController.Pragma(cmd))
                    {
                        ap.ReportError("Unknown pragma");
                    }
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            List <string> ctrl = FromString(UserData);

            if (ctrl != null)
            {
                List <string> exp;

                if (ap.functions.ExpandStrings(ctrl, out exp) != Functions.ExpandResult.Failed)
                {
                    Variables cv = ap.variables.FilterVars(exp[3] + "*");

                    ExtendedControls.ConfigurableForm cd = new ExtendedControls.ConfigurableForm();

                    foreach (string k in cv.NameList)
                    {
                        string errmsg = cd.Add(cv[k]);
                        if (errmsg != null)
                        {
                            return(ap.ReportError(errmsg + " in " + k + " variable for Dialog"));
                        }
                    }

                    StringParser sp2 = new StringParser(exp[2]);
                    int?         dw  = sp2.NextWordComma().InvariantParseIntNull();
                    int?         dh  = sp2.NextWordComma().InvariantParseIntNull();
                    int?         x   = sp2.NextWordComma().InvariantParseIntNull();
                    int?         y   = sp2.NextWord().InvariantParseIntNull();

                    if (dw != null && dh != null && ((x == null) == (y == null))) // need w/h, must have either no pos or both pos
                    {
                        if (IsModalDialog())
                        {
                            ap.dialogs[exp[0]] = cd;
                        }
                        else
                        {
                            ap.actionfile.dialogs[exp[0]] = cd;
                        }

                        System.Drawing.Point pos = new System.Drawing.Point(-999, -999);
                        if (x != null && y != null)
                        {
                            pos = new System.Drawing.Point(x.Value, y.Value);
                        }

                        cd.Trigger += Cd_Trigger;

                        cd.Show(ap.actioncontroller.Form, ap.actioncontroller.Icon,
                                new System.Drawing.Size(dw.Value, dh.Value), pos,
                                exp[1],
                                exp[0], new List <Object>()
                        {
                            ap, IsModalDialog()
                        }                                                                       // logical name and tag
                                );

                        return(!IsModalDialog());       // modal, return false, STOP.  Non modal, continue
                    }
                    else
                    {
                        ap.ReportError("Width/Height and/or X/Y not specified correctly in Dialog");
                    }
                }
                else
                {
                    ap.ReportError(exp[0]);
                }
            }
            else
            {
                ap.ReportError("Dialog command line not in correct format");
            }

            return(true);
        }
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string exp;

            if (ap.functions.ExpandString(UserData, out exp) != Functions.ExpandResult.Failed)
            {
                StringParser sp     = new StringParser(exp);
                string       handle = sp.NextWordComma();

                if (handle != null)
                {
                    bool infile  = ap.actionfile.dialogs.ContainsKey(handle);
                    bool inlocal = ap.dialogs.ContainsKey(handle);

                    ExtendedControls.ConfigurableForm f = infile ? ap.actionfile.dialogs[handle] : (inlocal ? ap.dialogs[handle] : null);

                    string cmd = sp.NextWordLCInvariant();

                    if (cmd == null)
                    {
                        ap.ReportError("Missing command in DialogControl");
                    }
                    else if (cmd.Equals("exists"))
                    {
                        ap["Exists"] = (f != null) ? "1" : "0";
                    }
                    else if (f == null)
                    {
                        ap.ReportError("No such dialog exists in DialogControl");
                    }
                    else if (cmd.Equals("continue"))
                    {
                        return((inlocal) ? false : true);    // if local, pause. else just ignore
                    }
                    else if (cmd.Equals("position"))
                    {
                        ap["X"] = f.Location.X.ToStringInvariant();
                        ap["Y"] = f.Location.Y.ToStringInvariant();
                    }
                    else if (cmd.Equals("get"))
                    {
                        string control = sp.NextWord();
                        string r;

                        if (control != null && (r = f.Get(control)) != null)
                        {
                            ap["DialogResult"] = r;
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog name in DialogControl get");
                        }
                    }
                    else if (cmd.Equals("set"))
                    {
                        string control = sp.NextWord(" =");
                        string value   = sp.IsCharMoveOn('=') ? sp.NextQuotedWord() : null;
                        if (control != null && value != null)
                        {
                            if (!f.Set(control, value))
                            {
                                ap.ReportError("Cannot set control " + control + " in DialogControl set");
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog name and/or value in DialogControl set");
                        }
                    }
                    else if (cmd.Equals("close"))
                    {
                        f.Close();
                        if (inlocal)
                        {
                            ap.dialogs.Remove(handle);
                        }
                        else
                        {
                            ap.actionfile.dialogs.Remove(handle);
                        }
                    }
                    else
                    {
                        ap.ReportError("Unknown command in DialogControl");
                    }
                }
                else
                {
                    ap.ReportError("Missing handle in DialogControl");
                }
            }
            else
            {
                ap.ReportError(exp);
            }

            return(true);
        }
Esempio n. 6
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string             say;
            ConditionVariables statementvars;

            if (FromString(userdata, out say, out statementvars))
            {
                string             errlist = null;
                ConditionVariables vars    = ap.functions.ExpandVars(statementvars, out errlist);

                if (errlist == null)
                {
                    bool wait = vars.GetInt(waitname, 0) != 0;

                    string prior = (vars.Exists(priorityname) && vars[priorityname].Length > 0) ? vars[priorityname] : (ap.VarExist(globalvarspeechpriority) ? ap[globalvarspeechpriority] : "Normal");
                    AudioQueue.Priority priority = AudioQueue.GetPriority(prior);

                    string start  = vars.GetString(startname, checklen: true);
                    string finish = vars.GetString(finishname, checklen: true);
                    string voice  = (vars.Exists(voicename) && vars[voicename].Length > 0)? vars[voicename] : (ap.VarExist(globalvarspeechvoice) ? ap[globalvarspeechvoice] : "Default");

                    int vol = vars.GetInt(volumename, -999);
                    if (vol == -999)
                    {
                        vol = ap.variables.GetInt(globalvarspeechvolume, 60);
                    }

                    int rate = vars.GetInt(ratename, -999);
                    if (rate == -999)
                    {
                        rate = ap.variables.GetInt(globalvarspeechrate, 0);
                    }

                    int queuelimitms = vars.GetInt(queuelimit, 0);

                    string culture = (vars.Exists(culturename) && vars[culturename].Length > 0) ? vars[culturename] : (ap.VarExist(globalvarspeechculture) ? ap[globalvarspeechculture] : "Default");

                    bool literal   = vars.GetInt(literalname, 0) != 0;
                    bool dontspeak = vars.GetInt(dontspeakname, 0) != 0;

                    string prefixsoundpath  = vars.GetString(prefixsound, checklen: true);
                    string postfixsoundpath = vars.GetString(postfixsound, checklen: true);
                    string mixsoundpath     = vars.GetString(mixsound, checklen: true);

                    ConditionVariables  globalsettings = ap.VarExist(globalvarspeecheffects) ? new ConditionVariables(ap[globalvarspeecheffects], ConditionVariables.FromMode.MultiEntryComma) : null;
                    SoundEffectSettings ses            = SoundEffectSettings.Set(globalsettings, vars); // work out the settings

                    if (queuelimitms > 0)
                    {
                        int queue = ap.actioncontroller.AudioQueueSpeech.InQueuems();

                        if (queue >= queuelimitms)
                        {
                            ap["SaySaid"] = "!LIMIT";
                            System.Diagnostics.Debug.WriteLine("Abort say due to queue being at " + queue);
                            return(true);
                        }
                    }

                    string expsay;
                    if (ap.functions.ExpandString(say, out expsay) != ConditionFunctions.ExpandResult.Failed)
                    {
                        Random rnd = ConditionFunctionHandlers.GetRandom();

                        if (!literal)
                        {
                            expsay = expsay.PickOneOfGroups(rnd);       // expand grouping if not literal
                        }

                        ap["SaySaid"] = expsay;

                        string ctrl = ap.VarExist("SpeechDebug") ? ap["SpeechDebug"] : "";

                        if (ctrl.Contains("Global"))
                        {
                            ap.actioncontroller.SetPeristentGlobal("GlobalSaySaid", expsay);
                        }

                        if (ctrl.Contains("Print"))
                        {
                            ap.actioncontroller.LogLine("Say: " + expsay);
                        }

                        if (ctrl.Contains("Mute"))
                        {
                            return(true);
                        }

                        if (ctrl.Contains("DontSpeak"))
                        {
                            expsay = "";
                        }

                        if (dontspeak)
                        {
                            expsay = "";
                        }

                        System.IO.MemoryStream ms = ap.actioncontroller.SpeechSynthesizer.Speak(expsay, culture, voice, rate);

                        if (ms != null)
                        {
                            AudioQueue.AudioSample audio = ap.actioncontroller.AudioQueueSpeech.Generate(ms, ses, true);

                            if (audio == null)
                            {
                                ap.ReportError("Say could not create audio, check Effects settings");
                                return(true);
                            }

                            if (mixsoundpath != null)
                            {
                                AudioQueue.AudioSample mix = ap.actioncontroller.AudioQueueSpeech.Generate(mixsoundpath);

                                if (mix == null)
                                {
                                    ap.ReportError("Say could not create mix audio, check audio file format is supported and effects settings");
                                    return(true);
                                }

                                audio = ap.actioncontroller.AudioQueueSpeech.Mix(audio, mix);     // audio in MIX format
                            }

                            if (prefixsoundpath != null)
                            {
                                AudioQueue.AudioSample p = ap.actioncontroller.AudioQueueSpeech.Generate(prefixsoundpath);

                                if (p == null)
                                {
                                    ap.ReportError("Say could not create prefix audio, check audio file format is supported and effects settings");
                                    return(true);
                                }

                                audio = ap.actioncontroller.AudioQueueSpeech.Append(p, audio);        // audio in AUDIO format.
                            }

                            if (postfixsoundpath != null)
                            {
                                AudioQueue.AudioSample p = ap.actioncontroller.AudioQueueSpeech.Generate(postfixsoundpath);

                                if (p == null)
                                {
                                    ap.ReportError("Say could not create postfix audio, check audio file format is supported and effects settings");
                                    return(true);
                                }

                                audio = ap.actioncontroller.AudioQueueSpeech.Append(audio, p);         // Audio in P format
                            }

                            if (start != null)
                            {
                                audio.sampleStartTag = new AudioEvent {
                                    apr = ap, eventname = start, ev = ActionEvent.onSayStarted
                                };
                                audio.sampleStartEvent += Audio_sampleEvent;
                            }

                            if (wait || finish != null)        // if waiting, or finish call
                            {
                                audio.sampleOverTag = new AudioEvent()
                                {
                                    apr = ap, wait = wait, eventname = finish, ev = ActionEvent.onSayFinished
                                };
                                audio.sampleOverEvent += Audio_sampleEvent;
                            }

                            ap.actioncontroller.AudioQueueSpeech.Submit(audio, vol, priority);

                            return(!wait);       //False if wait, meaning terminate and wait for it to complete, true otherwise, continue
                        }
                    }
                    else
                    {
                        ap.ReportError(expsay);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Say command line not in correct format");
            }


            return(true);
        }
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.functions.ExpandString(UserData, out res) != Functions.ExpandResult.Failed)
            {
                StringParser sp      = new StringParser(res);
                string       cmdname = sp.NextWordLCInvariant(", ");

                if (cmdname.Equals("folder"))
                {
                    sp.IsCharMoveOn(',');

                    FolderBrowserDialog fbd = new FolderBrowserDialog();

                    string descr = sp.NextQuotedWordComma();
                    if (descr != null)
                    {
                        fbd.Description = descr;
                    }

                    string rootfolder = sp.NextQuotedWordComma();
                    if (rootfolder != null)
                    {
                        Environment.SpecialFolder sf;
                        if (Enum.TryParse <Environment.SpecialFolder>(rootfolder, out sf))
                        {
                            fbd.RootFolder = sf;
                        }
                        else
                        {
                            return(ap.ReportError("FileDialog folder does not recognise folder location " + rootfolder));
                        }
                    }

                    string fileret = (fbd.ShowDialog(ap.actioncontroller.Form) == DialogResult.OK) ? fbd.SelectedPath : "";
                    ap["FolderName"] = fileret;
                }
                else if (cmdname.Equals("openfile"))
                {
                    sp.IsCharMoveOn(',');

                    OpenFileDialog fd = new OpenFileDialog();
                    fd.Multiselect     = false;
                    fd.CheckPathExists = true;

                    try
                    {
                        string rootfolder = sp.NextQuotedWordComma();
                        if (rootfolder != null)
                        {
                            fd.InitialDirectory = rootfolder;
                        }

                        string filter = sp.NextQuotedWordComma();
                        if (filter != null)
                        {
                            fd.Filter = filter;
                        }

                        string defext = sp.NextQuotedWordComma();
                        if (defext != null)
                        {
                            fd.DefaultExt = defext;
                        }

                        string check = sp.NextQuotedWordComma();
                        if (check != null && check.Equals("On", StringComparison.InvariantCultureIgnoreCase))
                        {
                            fd.CheckFileExists = true;
                        }

                        string fileret = (fd.ShowDialog(ap.actioncontroller.Form) == DialogResult.OK) ? fd.FileName : "";
                        ap["FileName"] = fileret;
                    }
                    catch
                    {
                        ap.ReportError("FileDialog file failed to generate dialog, check options");
                    }
                }
                else if (cmdname.Equals("savefile"))
                {
                    sp.IsCharMoveOn(',');

                    SaveFileDialog fd = new SaveFileDialog();

                    try
                    {
                        string rootfolder = sp.NextQuotedWordComma();
                        if (rootfolder != null)
                        {
                            fd.InitialDirectory = rootfolder;
                        }

                        string filter = sp.NextQuotedWordComma();
                        if (filter != null)
                        {
                            fd.Filter = filter;
                        }

                        string defext = sp.NextQuotedWordComma();
                        if (defext != null)
                        {
                            fd.DefaultExt = defext;
                        }

                        string check = sp.NextQuotedWordComma();
                        if (check != null && check.Equals("On", StringComparison.InvariantCultureIgnoreCase))
                        {
                            fd.OverwritePrompt = true;
                        }

                        string fileret = (fd.ShowDialog(ap.actioncontroller.Form) == DialogResult.OK) ? fd.FileName : "";
                        ap["FileName"] = fileret;
                    }
                    catch
                    {
                        ap.ReportError("FileDialog file failed to generate dialog, check options");
                    }
                }
                else
                {
                    ap.ReportError("FileDialog does not recognise command " + cmdname);
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Esempio n. 8
0
        public bool ExecuteAction(ActionProgramRun ap, bool setit, bool globalit = false, bool persistentit = false, bool staticit = false)
        {
            if (av == null)
            {
                FromString(userdata, out av, out operations);
            }

            foreach (string key in av.NameEnumuerable)
            {
                string keyname = key;

                if (keyname.Contains("%"))
                {
                    if (ap.functions.ExpandString(key, out keyname) == ConditionFunctions.ExpandResult.Failed)
                    {
                        ap.ReportError(keyname);
                        break;
                    }
                }

                string res;

                if (operations[key].Contains("$"))
                {
                    res = av[key];
                }
                else if (ap.functions.ExpandString(av[key], out res) == ConditionFunctions.ExpandResult.Failed)       //Expand out.. and if no errors
                {
                    ap.ReportError(res);
                    break;
                }

                if (setit)
                {
                    if (operations[key].Contains("+") && ap.VarExist(keyname))
                    {
                        res = ap[keyname] + res;
                    }
                }
                else
                {
                    if (!res.Eval(out res))
                    {
                        ap.ReportError("Let " + res);
                        break;
                    }
                }

                //System.Diagnostics.Debug.WriteLine("Var " + keyname + "=" + res + "  :" + globalit + ":" + persistentit);
                ap[keyname] = res;

                if (globalit)
                {
                    ap.actioncontroller.SetNonPersistentGlobal(keyname, res);
                }

                if (persistentit)
                {
                    ap.actioncontroller.SetPeristentGlobal(keyname, res);
                }

                if (staticit)
                {
                    ap.actionfile.SetFileVariable(keyname, res);
                }
            }

            if (av.Count == 0)
            {
                ap.ReportError("No variable name given in variable assignment");
            }

            return(true);
        }
Esempio n. 9
0
        //special call for execute, needs to pass back more data
        public bool ExecuteCallAction(ActionProgramRun ap, out string progname, out Variables vars)
        {
            Dictionary <string, string> altops;

            if (FromString(UserData, out progname, out vars, out altops) && progname.Length > 0)
            {
                if (ap.functions.ExpandString(progname, out string prognameexpanded) == Functions.ExpandResult.Failed)
                {
                    ap.ReportError(prognameexpanded);
                    return(true);
                }
                else
                {
                    progname = prognameexpanded;
                }

                List <string> wildcards = new List <string>();
                Variables     newitems  = new Variables();

                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) == Functions.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) == Functions.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);
            }
        }
Esempio n. 10
0
        public bool ExecuteAction(ActionProgramRun ap, BaseUtils.EnhancedSendKeysParser.IAdditionalKeyParser akp)       // additional parser
        {
            string    keys;
            Variables statementvars;

            if (FromString(userdata, out keys, out statementvars))
            {
                string    errlist = null;
                Variables vars    = ap.Functions.ExpandVars(statementvars, out errlist);

                if (errlist == null)
                {
                    int    delay               = vars.Exists(DelayID) ? vars[DelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarDelay) ? ap[globalvarDelay].InvariantParseInt(DefaultDelay) : DefaultDelay);
                    int    updelay             = vars.Exists(UpDelayID) ? vars[UpDelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarUpDelay) ? ap[globalvarUpDelay].InvariantParseInt(DefaultDelay) : DefaultDelay);
                    int    shiftdelay          = vars.Exists(ShiftDelayID) ? vars[ShiftDelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarShiftDelay) ? ap[globalvarShiftDelay].InvariantParseInt(DefaultDelay) : DefaultDelay);
                    string process             = vars.Exists(ProcessID) ? vars[ProcessID] : (ap.VarExist(globalvarProcessID) ? ap[globalvarProcessID] : "");
                    string silentonerrors      = vars.Exists(SilentOnError) ? vars[SilentOnError] : (ap.VarExist(globalvarSilentOnErrors) ? ap[globalvarSilentOnErrors] : "0");
                    string announciateonerrors = vars.Exists(AnnounciateOnError) ? vars[AnnounciateOnError] : (ap.VarExist(globalvarAnnounciateOnError) ? ap[globalvarAnnounciateOnError] : "0");

                    string res = BaseUtils.EnhancedSendKeys.SendToProcess(keys, delay, shiftdelay, updelay, process, akp);

                    if (res.HasChars())
                    {
                        if (silentonerrors.Equals("2") || (errorsreported.Contains(res) && silentonerrors.Equals("1")))
                        {
                            System.Diagnostics.Debug.WriteLine("Swallow key error " + res);
                            ap.ActionController.TerminateAll();
                        }
                        else
                        {
                            errorsreported.Add(res);

                            if (announciateonerrors.Equals("1"))
                            {
                                string culture            = ap.VarExist(ActionSay.globalvarspeechculture) ? ap[ActionSay.globalvarspeechculture] : "Default";
                                System.IO.MemoryStream ms = ap.ActionController.SpeechSynthesizer.Speak("Cannot press key due to " + res, culture, "Default", 0);
                                if (ms != null)
                                {
                                    AudioQueue.AudioSample audio = ap.ActionController.AudioQueueSpeech.Generate(ms);
                                    if (audio != null)
                                    {
                                        ap.ActionController.AudioQueueSpeech.Submit(audio, 80, AudioQueue.Priority.Normal);
                                    }
                                }
                            }

                            ap.ReportError(res);
                        }
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Key command line not in correct format");
            }

            return(true);
        }
Esempio n. 11
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string    pathunexpanded;
            Variables statementvars;

            if (FromString(userdata, out pathunexpanded, out statementvars))
            {
                string    errlist = null;
                Variables vars    = ap.functions.ExpandVars(statementvars, out errlist);

                if (errlist == null)
                {
                    string path;
                    if (ap.functions.ExpandString(pathunexpanded, out path) != Functions.ExpandResult.Failed)
                    {
                        if (System.IO.File.Exists(path))
                        {
                            bool wait = vars.GetInt(waitname, 0) != 0;
                            AudioQueue.Priority priority = AudioQueue.GetPriority(vars.GetString(priorityname, "Normal"));
                            string start  = vars.GetString(startname);
                            string finish = vars.GetString(finishname);

                            int vol = vars.GetInt(volumename, -999);
                            if (vol == -999)
                            {
                                vol = ap.variables.GetInt(globalvarplayvolume, 60);
                            }

                            Variables           globalsettings = ap.VarExist(globalvarplayeffects) ? new Variables(ap[globalvarplayeffects], Variables.FromMode.MultiEntryComma) : null;
                            SoundEffectSettings ses            = SoundEffectSettings.Set(globalsettings, vars); // work out the settings

                            AudioQueue.AudioSample audio = ap.actioncontroller.AudioQueueWave.Generate(path, ses);

                            if (audio != null)
                            {
                                if (start != null && start.Length > 0)
                                {
                                    audio.sampleStartTag = new AudioEvent {
                                        apr = ap, eventname = start, ev = ActionEvent.onPlayStarted
                                    };
                                    audio.sampleStartEvent += Audio_sampleEvent;
                                }
                                if (wait || (finish != null && finish.Length > 0))       // if waiting, or finish call
                                {
                                    audio.sampleOverTag = new AudioEvent()
                                    {
                                        apr = ap, wait = wait, eventname = finish, ev = ActionEvent.onPlayFinished
                                    };
                                    audio.sampleOverEvent += Audio_sampleEvent;
                                }

                                ap.actioncontroller.AudioQueueWave.Submit(audio, vol, priority);
                                return(!wait);       //False if wait, meaning terminate and wait for it to complete, true otherwise, continue
                            }
                            else
                            {
                                ap.ReportError("Play could not create audio, check audio file format is supported and effects settings");
                            }
                        }
                        else
                        {
                            ap.ReportError("Play could not find file " + path);
                        }
                    }
                    else
                    {
                        ap.ReportError(path);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Play command line not in correct format");
            }

            return(true);
        }
Esempio n. 12
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string    pathunexpanded;
            Variables statementvars;

            if (FromString(userdata, out pathunexpanded, out statementvars))
            {
                string    errlist = null;
                Variables vars    = ap.Functions.ExpandVars(statementvars, out errlist);

                if (errlist == null)
                {
                    string path;
                    if (ap.Functions.ExpandString(pathunexpanded, out path) != Functions.ExpandResult.Failed)
                    {
                        if (path == tonekey || System.IO.File.Exists(path))
                        {
                            bool wait = vars.GetInt(waitname, 0) != 0;
                            AudioQueue.Priority priority = AudioQueue.GetPriority(vars.GetString(priorityname, "Normal"));
                            string start  = vars.GetString(startname);
                            string finish = vars.GetString(finishname);

                            int vol = vars.GetInt(volumename, -999);
                            if (vol == -999)
                            {
                                vol = ap.variables.GetInt(globalvarplayvolume, 60);
                            }

                            Variables           globalsettings = ap.VarExist(globalvarplayeffects) ? new Variables(ap[globalvarplayeffects], Variables.FromMode.MultiEntryComma) : null;
                            SoundEffectSettings ses            = SoundEffectSettings.Set(globalsettings, vars); // work out the settings

                            AudioQueue.AudioSample audio = null;

                            if (path == tonekey)
                            {
                                double freq     = vars.GetDouble(tonefrequency, 512);
                                double lengthms = vars.GetDouble(toneduration, 1000);
                                audio = ap.ActionController.AudioQueueWave.Tone(freq, 100.0, lengthms);
                            }
                            else
                            {
                                audio = ap.ActionController.AudioQueueWave.Generate(path, ses);
                            }

                            double attack = vars.GetDouble(envelopeattack, -1);
                            if (attack >= 0 && audio != null)
                            {
                                double decay   = vars.GetDouble(envelopedecay, 0);
                                double sustain = vars.GetDouble(envelopesustain, 1E12);
                                double release = vars.GetDouble(enveloperelease, 1000);
                                double svolume = vars.GetDouble(sustainvolume, decay == 0 ? 100 : 50);

                                // System.Diagnostics.Debug.WriteLine($"ADSR {attack} {decay} {sustain} {release} {svolume}");
                                audio = ap.ActionController.AudioQueueWave.Envelope(audio, attack, decay, sustain, release, 100.0, svolume);
                            }

                            if (audio != null)
                            {
                                if (start != null && start.Length > 0)
                                {
                                    audio.sampleStartTag = new AudioEvent {
                                        apr = ap, eventname = start, ev = ActionEvent.onPlayStarted
                                    };
                                    audio.sampleStartEvent += Audio_sampleEvent;
                                }
                                if (wait || (finish != null && finish.Length > 0))       // if waiting, or finish call
                                {
                                    audio.sampleOverTag = new AudioEvent()
                                    {
                                        apr = ap, wait = wait, eventname = finish, ev = ActionEvent.onPlayFinished
                                    };
                                    audio.sampleOverEvent += Audio_sampleEvent;
                                }

                                ap.ActionController.AudioQueueWave.Submit(audio, vol, priority);
                                return(!wait);       //False if wait, meaning terminate and wait for it to complete, true otherwise, continue
                            }
                            else
                            {
                                ap.ReportError("Play could not create audio, check audio file format is supported and effects settings");
                            }
                        }
                        else
                        {
                            ap.ReportError("Play could not find file " + path);
                        }
                    }
                    else
                    {
                        ap.ReportError(path);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Play command line not in correct format");
            }

            return(true);
        }
Esempio n. 13
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string    say;
            Variables statementvars;

            if (FromString(userdata, out say, out statementvars))
            {
                string ctrl = ap.VarExist("SpeechDebug") ? ap["SpeechDebug"] : "";

                string    errlist = null;
                Variables vars    = ap.Functions.ExpandVars(statementvars, out errlist);

                if (ctrl.Contains("SayLine"))
                {
                    ap.ActionController.LogLine("Say Command: " + userdata);
                    ap.ActionController.LogLine("Say Vars: " + vars.ToString(separ: Environment.NewLine));
                    System.Diagnostics.Debug.WriteLine("Say Vars: " + vars.ToString(separ: Environment.NewLine));
                }

                if (errlist == null)
                {
                    bool wait = vars.GetInt(waitname, 0) != 0;

                    string prior = (vars.Exists(priorityname) && vars[priorityname].Length > 0) ? vars[priorityname] : (ap.VarExist(globalvarspeechpriority) ? ap[globalvarspeechpriority] : "Normal");
                    AudioQueue.Priority priority = AudioQueue.GetPriority(prior);

                    string start  = vars.GetString(startname, checklen: true);
                    string finish = vars.GetString(finishname, checklen: true);
                    string voice  = (vars.Exists(voicename) && vars[voicename].Length > 0) ? vars[voicename] : (ap.VarExist(globalvarspeechvoice) ? ap[globalvarspeechvoice] : "Default");

                    int vol = vars.GetInt(volumename, -999);
                    if (vol == -999)
                    {
                        vol = ap.variables.GetInt(globalvarspeechvolume, 60);
                    }

                    int rate = vars.GetInt(ratename, -999);
                    if (rate == -999)
                    {
                        rate = ap.variables.GetInt(globalvarspeechrate, 0);
                    }

                    int queuelimitms = vars.GetInt(queuelimit, 0);

                    string culture = (vars.Exists(culturename) && vars[culturename].Length > 0) ? vars[culturename] : (ap.VarExist(globalvarspeechculture) ? ap[globalvarspeechculture] : "Default");

                    bool literal   = vars.GetInt(literalname, 0) != 0;
                    bool dontspeak = vars.Exists(dontspeakname) ? (vars.GetInt(dontspeakname, 0) != 0) : (ap.VarExist(globalvarspeechdisable) ? ap[globalvarspeechdisable].InvariantParseInt(0) != 0 : false);

                    string prefixsoundpath  = vars.GetString(prefixsound, checklen: true);
                    string postfixsoundpath = vars.GetString(postfixsound, checklen: true);
                    string mixsoundpath     = vars.GetString(mixsound, checklen: true);

                    Variables           globalsettings = ap.VarExist(globalvarspeecheffects) ? new Variables(ap[globalvarspeecheffects], Variables.FromMode.MultiEntryComma) : null;
                    SoundEffectSettings ses            = SoundEffectSettings.Set(globalsettings, vars); // work out the settings

                    if (queuelimitms > 0)
                    {
                        int queue = ap.ActionController.AudioQueueSpeech.InQueuems();

                        if (queue >= queuelimitms)
                        {
                            ap["SaySaid"] = "!LIMIT";
                            System.Diagnostics.Debug.WriteLine("Abort say due to queue being at " + queue);
                            return(true);
                        }
                    }

                    string expsay;
                    if (ap.Functions.ExpandString(say, out expsay) != Functions.ExpandResult.Failed)
                    {
                        System.Diagnostics.Debug.WriteLine("Say wait {0}, vol {1}, rate {2}, queue {3}, priority {4}, culture {5}, literal {6}, dontspeak {7} , prefix {8}, postfix {9}, mix {10} starte {11}, finishe {12} , voice {13}, text {14}",
                                                           wait, vol, rate, queuelimitms, priority, culture, literal, dontspeak, prefixsoundpath, postfixsoundpath, mixsoundpath, start, finish, voice, expsay);

                        Random rnd = FunctionHandlers.GetRandom();

                        if (!literal)
                        {
                            expsay = expsay.PickOneOfGroups(rnd);       // expand grouping if not literal
                        }

                        ap["SaySaid"] = expsay;

                        if (ctrl.Contains("Global"))
                        {
                            ap.ActionController.SetPeristentGlobal("GlobalSaySaid", expsay);
                        }

                        if (ctrl.Contains("Print") && expsay.HasChars())
                        {
                            ap.ActionController.LogLine("Say: " + expsay);
                        }

                        if (ctrl.Contains("Mute"))
                        {
                            return(true);
                        }

                        if (ctrl.Contains("DontSpeak"))
                        {
                            expsay = "";
                        }

                        if (dontspeak)
                        {
                            expsay = "";
                        }

                        AudioQueue.AudioSample mix = null, prefix = null, postfix = null;

                        if (mixsoundpath != null)
                        {
                            mix = ap.ActionController.AudioQueueSpeech.Generate(mixsoundpath);

                            if (mix == null)
                            {
                                ap.ReportError("Say could not create mix audio, check audio file format is supported and effects settings");
                                return(true);
                            }
                        }

                        if (prefixsoundpath != null)
                        {
                            prefix = ap.ActionController.AudioQueueSpeech.Generate(prefixsoundpath);

                            if (prefix == null)
                            {
                                ap.ReportError("Say could not create prefix audio, check audio file format is supported and effects settings");
                                return(true);
                            }
                        }

                        if (postfixsoundpath != null)
                        {
                            postfix = ap.ActionController.AudioQueueSpeech.Generate(postfixsoundpath);

                            if (postfix == null)
                            {
                                ap.ReportError("Say could not create postfix audio, check audio file format is supported and effects settings");
                                return(true);
                            }
                        }

                        // we entrust it to a Speach Queue (New Dec 20) as the synth takes an inordinate time to generate speech, it then calls back

                        ap.ActionController.SpeechSynthesizer.SpeakQueue(expsay, culture, voice, rate, (memstream) =>
                        {
                            // in a thread, invoke on UI thread to complete action, since these objects are owned by that thread

                            ap.ActionController.Form.Invoke((MethodInvoker) delegate
                            {
                                System.Diagnostics.Debug.Assert(Application.MessageLoop);       // double check!

                                AudioQueue.AudioSample audio = ap.ActionController.AudioQueueSpeech.Generate(memstream, ses, true);

                                if (audio != null)
                                {
                                    if (mix != null)
                                    {
                                        audio = ap.ActionController.AudioQueueSpeech.Mix(audio, mix);     // audio in MIX format
                                    }
                                    if (audio != null && prefix != null)
                                    {
                                        audio = ap.ActionController.AudioQueueSpeech.Append(prefix, audio);        // audio in AUDIO format.
                                    }
                                    if (audio != null && postfix != null)
                                    {
                                        audio = ap.ActionController.AudioQueueSpeech.Append(audio, postfix); // Audio in P format
                                    }
                                    if (audio != null)                                                       // just double checking nothing fails above
                                    {
                                        if (start != null)
                                        {
                                            audio.sampleStartTag = new AudioEvent {
                                                apr = ap, eventname = start, ev = ActionEvent.onSayStarted
                                            };
                                            audio.sampleStartEvent += Audio_sampleEvent;
                                        }

                                        if (wait || finish != null)       // if waiting, or finish call
                                        {
                                            audio.sampleOverTag = new AudioEvent()
                                            {
                                                apr = ap, wait = wait, eventname = finish, ev = ActionEvent.onSayFinished
                                            };
                                            audio.sampleOverEvent += Audio_sampleEvent;
                                        }

                                        ap.ActionController.AudioQueueSpeech.Submit(audio, vol, priority);
                                    }
                                }
                            });
                        });

                        return(!wait);
                    }
                    else
                    {
                        ap.ReportError(expsay);
                    }
                }
                else
                {
                    ap.ReportError(errlist);
                }
            }
            else
            {
                ap.ReportError("Say command line not in correct format");
            }

            return(true);
        }
Esempio n. 14
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.Functions.ExpandString(UserData, out res) != Functions.ExpandResult.Failed)
            {
                StringParser sp     = new StringParser(res);
                string       prefix = "EV_";

                string cmdname = sp.NextWordLCInvariant(" ");

                if (cmdname != null && cmdname.Equals("prefix"))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix in Event");
                        return(true);
                    }

                    cmdname = sp.NextWordLCInvariant(" ");
                }

                if (cmdname.Equals("add"))
                {
                    bool      res1 = false;
                    string    err = "Bad Groupname", groupname = null;
                    Condition c = new Condition();

                    if (!(groupname = sp.NextQuotedWord(", ")).HasChars() || !sp.IsCharMoveOn(',') || (err = c.Read(sp, true)).HasChars())
                    {
                        ap.ReportError("Bad conditional line: " + err);
                    }
                    else if (c.Action.Length == 0 || c.EventName.Length == 0)
                    {
                        ap.ReportError("Missing event name or action: " + err);
                    }
                    else
                    {
                        c.GroupName = groupname;
                        if (ap.ActionFile.InUseEventList.Contains(c))
                        {
                            res1 = false;
                        }
                        else
                        {
                            ap.ActionFile.InUseEventList.Add(c);
                            res1 = true;
                        }
                    }

                    ap[prefix + "Result"] = res1.ToStringIntValue();
                }
                else
                {
                    string groupname     = null;
                    string eventname     = null;
                    string action        = null;
                    string actionvarsstr = null;
                    string condition     = null;

                    if ((groupname = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                        (eventname = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                        (action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                        (actionvarsstr = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') ||
                        (condition = sp.NextQuotedWord("")) == null
                        )
                    {
                        ap.ReportError("Missing event pattern");
                    }
                    else
                    {
                        // System.Diagnostics.Debug.WriteLine($"Events command {cmdname} g `{groupname}` e `{eventname}` a `{action}` v `{actionvarsstr}` c `{condition}`");
                        List <Condition> matching = ap.ActionFile.InUseEventList.Find(groupname, eventname, action, actionvarsstr, condition);

                        ap[prefix + "Count"] = matching.Count.ToStringInvariant();

                        if (cmdname == "delete")            // checked 14/5/21
                        {
                            foreach (var e in matching)
                            {
                                // System.Diagnostics.Debug.WriteLine("Event Delete " + e.GroupName + ":" + e.ToString(true));
                                ap.ActionFile.InUseEventList.Remove(e);
                            }
                        }
                        else if (cmdname == "disable" || cmdname == "enable")       // checked 14/5/21
                        {
                            bool disabled = cmdname == "disable";
                            foreach (var e in matching)
                            {
                                e.Disabled = disabled;
                                //   System.Diagnostics.Debug.WriteLine("Event " + !disabled + ": " + e.GroupName + ":" + e.ToString(true));
                            }
                        }
                        else if (cmdname == "disableallbut" || cmdname == "enableallbut")
                        {
                            bool enabled = cmdname == "enableallbut";
                            foreach (var e in ap.ActionFile.InUseEventList.Enumerable)     // all events
                            {
                                e.Disabled = matching.Contains(e) ? enabled : !enabled;    // if matching list has it, we want it to state, else to opposite state
                                // System.Diagnostics.Debug.WriteLine("Event " + !e.Disabled + ": " + e.GroupName + ":" + e.ToString(true));
                            }
                        }
                        else if (cmdname == "list")         // checked 14/5/21
                        {
                            for (int i = 0; i < matching.Count; i++)
                            {
                                ap[prefix + "Event[" + (i + 1).ToStringInvariant() + "]"]     = matching[i].ToString(true);
                                ap[prefix + "Enabled[" + (i + 1).ToStringInvariant() + "]"]   = matching[i].Disabled ? "0" : "1";
                                ap[prefix + "GroupName[" + (i + 1).ToStringInvariant() + "]"] = matching[i].GroupName ?? "";        // groupnames can be null
                            }
                        }
                        else
                        {
                            ap.ReportError("Events unknown command");
                        }
                    }
                }
            }
            else
            {
                ap.ReportError("Events command line not in correct format");
            }

            return(true);
        }