public override bool ExecuteAction(ActionProgramRun ap) { if (ap.IsExecutingType(ActionBase.ActionType.If)) { if (ap.IsExecuteOff) // if not executing, turn on { ap.ChangeState(true); // go true } else { ap.ChangeState(ActionProgramRun.ExecState.OffForGood); // make sure off for good } } else { ap.ReportError("Else without IF"); } return(true); }
public bool ExecuteEndFor(ActionProgramRun ap) // only called if Push pos is set. break clears the push pos { if (values != null) { if (count < values.Count) { ap.Goto(ap.PushPos + 1); ap[expmacroname] = values[count++]; System.Diagnostics.Debug.WriteLine("New value " + ap[expmacroname]); return(true); } else { values = null; } } return(false); }
// now = true, run it immediately, else run at end of queue. Optionally pass in handles and dialogs in case its a sub prog public void Run(bool now, ActionFile fileset, ActionProgram r, ConditionVariables inputparas, ConditionFileHandles fh = null, Dictionary <string, ExtendedControls.ConfigurableForm> d = null, bool closeatend = true) { if (now) { if (progcurrent != null) // if running, push the current one back onto the queue to be picked up { progqueue.Insert(0, progcurrent); } progcurrent = new ActionProgramRun(fileset, r, inputparas, this, actioncontroller); // now we run this.. no need to push to stack progcurrent.PrepareToRun(new ConditionVariables(progcurrent.inputvariables, actioncontroller.Globals, fileset.filevariables), fh == null ? new ConditionFileHandles() : fh, d == null ? new Dictionary <string, ExtendedControls.ConfigurableForm>() : d, closeatend); // if no filehandles, make them and close at end } else { progqueue.Add(new ActionProgramRun(fileset, r, inputparas, this, actioncontroller)); } }
public override bool ExecuteAction(ActionProgramRun ap) { if (ap.IsExecutingType(ActionBase.ActionType.If)) { if (ap.IsExecuteOff) // if not executing, check condition { if (condition == null) { condition = new ConditionLists(); if (condition.Read(UserData) != null) { ap.ReportError("ElseIf condition is not correctly formed"); return(true); } } string errlist; bool? condres = condition.CheckAll(ap.functions.vars, out errlist, null, ap.functions); // may return null.. and will return errlist if (errlist == null) { bool res = condres.HasValue && condres.Value; ap.ChangeState(res); // either to ON.. or to OFF, continuing the off } else { ap.ReportError(errlist); } } else { ap.ChangeState(ActionProgramRun.ExecState.OffForGood); // make sure off for good } } else { ap.ReportError("ElseIf without IF"); } return(true); }
public bool ExecuteAction(ActionProgramRun ap, Func <string, string> keytx) // keytx is passed in { string keys; ConditionVariables statementvars; if (FromString(userdata, out keys, out statementvars)) { string errlist = null; ConditionVariables vars = statementvars.ExpandAll(ap.functions, statementvars, out errlist); if (errlist == null) { int defdelay = vars.Exists(DelayID) ? vars[DelayID].InvariantParseInt(DefaultDelay) : (ap.VarExist(globalvarDelay) ? ap[globalvarDelay].InvariantParseInt(DefaultDelay) : DefaultDelay); string process = vars.Exists(ProcessID) ? vars[ProcessID] : (ap.VarExist(globalvarProcessID) ? ap[globalvarProcessID] : ""); if (keytx != null) { keys = keytx(keys); } string res = BaseUtils.EnhancedSendKeys.Send(keys, defdelay, DefaultShiftDelay, DefaultUpDelay, process); if (res.HasChars()) { ap.ReportError("Key Syntax error : " + res); } } else { ap.ReportError(errlist); } } else { ap.ReportError("Key command line not in correct format"); } return(true); }
static private void Cd_Trigger(string lname, string controlname, Object tag) { if (controlname == "Close") // put in backwards compatibility - close is the same as cancel for action programs { controlname = "Cancel"; } List <Object> tags = tag as List <Object>; // object is a list of objects! lovely ActionProgramRun apr = tags[0] as ActionProgramRun; bool ismodal = (bool)tags[1]; if (ismodal) { apr[lname] = controlname; apr.ResumeAfterPause(); } else { apr.ActionController.ActionRun(ActionEvent.onNonModalDialog, new BaseUtils.Variables(new string[] { "Dialog", lname, "Control", controlname })); } }
public void TerminateToCloseAtEnd() // halt up to close at end function { if ( progcurrent != null && !progcurrent.ClosingHandlesAtEnd ) // if its not a top end function { List<ActionProgramRun> toremove = new List<ActionProgramRun>(); foreach (ActionProgramRun p in progqueue) // ensure all have a chance to clean up { toremove.Add(p); if (p.ClosingHandlesAtEnd) break; } foreach (ActionProgramRun apr in toremove) { apr.Terminated(); progqueue.Remove(apr); } } progcurrent = null; executing = false; }
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) { string[] prompts = exp[1].Split(';'); string[] def = (exp.Count >= 3) ? exp[2].Split(';') : null; bool multiline = (exp.Count >= 4) ? (exp[3].IndexOf("Multiline", StringComparison.InvariantCultureIgnoreCase) >= 0) : false; string[] tooltips = (exp.Count >= 5) ? exp[4].Split(';') : null; List <string> r = ExtendedControls.PromptMultiLine.ShowDialog(ap.ActionController.Form, exp[0], ap.ActionController.Icon, prompts, def, multiline, tooltips); ap["InputBoxOK"] = (r != null) ? "1" : "0"; if (r != null) { for (int i = 0; i < r.Count; i++) { ap["InputBox" + (i + 1).ToString()] = r[i]; } } } else { ap.ReportError(exp[0]); } } else { ap.ReportError("MenuInput command line not in correct format"); } return(true); }
public override bool ExecuteAction(ActionProgramRun ap) { if (condition == null) { if (!FromString(userdata, out condition, out errmsg)) { ap.ReportError("ErrorIF condition is not correctly formed"); return(true); } } string errlist; bool? condres = condition.CheckAll(ap.functions.vars, out errlist, null, ap.functions); // may return null.. and will return errlist if (errlist == null) { bool res = condres.HasValue && condres.Value; if (res) { if (ap.functions.ExpandString(errmsg, out string exprerr) != Functions.ExpandResult.Failed) { ap.ReportError(exprerr); } else { ap.ReportError(exprerr); } } } else { ap.ReportError(errlist); } return(true); }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != ConditionFunctions.ExpandResult.Failed) { StringParser p = new StringParser(res); string v; while ((v = p.NextWord(", ")) != null) { ap.actioncontroller.DeleteVariable(v); ap.actionfile.DeleteFileVariable(v); ap.DeleteVar(v); p.IsCharMoveOn(','); } } else { ap.ReportError(res); } return(true); }
public override bool ExecuteAction(ActionProgramRun ap) { return(ExecuteAction(ap, true, staticit: true)); }
public override bool ExecuteAction(ActionProgramRun ap) { return(ExecuteAction(ap, true, persistentit: true)); }
public override bool ExecuteAction(ActionProgramRun ap) { return(ExecuteAction(ap, false, globalit: true)); }
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")) { 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 (prefix != null) { audio = ap.actioncontroller.AudioQueueSpeech.Append(prefix, audio); // audio in AUDIO format. } if (postfix != null) { audio = ap.actioncontroller.AudioQueueSpeech.Append(audio, postfix); // 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); } else { ap.ReportError(expsay); } } else { ap.ReportError(errlist); } } else { ap.ReportError("Say command line not in correct format"); } return(true); }
//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); } }
public override bool ExecuteAction(ActionProgramRun ap) { string say; ConditionVariables statementvars; if (FromString(userdata, out say, out statementvars)) { string errlist = null; ConditionVariables vars = statementvars.ExpandAll(ap.functions, statementvars, out errlist); if (errlist == null) { bool wait = vars.GetInt(waitname, 0) != 0; AudioQueue.Priority priority = AudioQueue.GetPriority(vars.GetString(priorityname, "Normal")); 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); SoundEffectSettings ses = new SoundEffectSettings(vars); // use the rest of the vars to place effects if (!ses.Any && !ses.OverrideNone && ap.VarExist(globalvarspeecheffects)) // if can't see any, and override none if off, and we have a global, use that { vars = new ConditionVariables(ap[globalvarspeecheffects], ConditionVariables.FromMode.MultiEntryComma); } 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) { if (!literal) { expsay = expsay.PickOneOfGroups(rnd); // expand grouping if not literal } ap["SaySaid"] = expsay; if ((ap.VarExist("SpeechDebug") && ap["SpeechDebug"].Contains("Print"))) { ap.actioncontroller.LogLine("Say: " + expsay); 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, vars, 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, new ConditionVariables()); if (audio == 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, new ConditionVariables()); 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, new ConditionVariables()); 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, triggername = "onSayStarted" }; audio.sampleStartEvent += Audio_sampleEvent; } if (wait || finish != null) // if waiting, or finish call { audio.sampleOverTag = new AudioEvent() { apr = ap, wait = wait, eventname = finish, triggername = "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) != ConditionFunctions.ExpandResult.Failed) { StringParser p = new StringParser(res); string cmd; while ((cmd = p.NextWord(" ", true)) != null) { if (cmd.Equals("dumpvars")) { string rest = p.NextQuotedWord(); if (rest != null && rest.Length > 0) { ConditionVariables 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(true); } 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.NextWordComma().InvariantParseIntNull(); int? mw = sp2.NextWordComma().InvariantParseIntNull(); int? mh = sp2.NextWordComma().InvariantParseIntNull(); if (dw != null && dh != null && ((x == null) == (y == null))) // need w/h, must have either no pos or both pos { bool closeicon = true, alwaysontop = false; for (int i = 4; i < exp.Count; i++) { if (exp[i].Equals("AllowResize", StringComparison.InvariantCultureIgnoreCase)) { cd.AllowResize = true; } else if (exp[i].Equals("Transparent", StringComparison.InvariantCultureIgnoreCase)) { cd.Transparent = true; } else if (exp[i].Equals("NoCloseIcon", StringComparison.InvariantCultureIgnoreCase)) { closeicon = false; } else if (exp[i].Equals("AlwaysOnTop", StringComparison.InvariantCultureIgnoreCase)) { alwaysontop = true; } else if (exp[i].Equals("NoWindowsBorder", StringComparison.InvariantCultureIgnoreCase)) { cd.ForceNoWindowsBorder = true; } else if (exp[i].Equals("NoPanelBorder", StringComparison.InvariantCultureIgnoreCase)) { cd.PanelBorderStyle = BorderStyle.None; } else if (exp[i].StartsWith("FontScale:", StringComparison.InvariantCultureIgnoreCase)) { cd.FontScale = exp[i].Substring(10).InvariantParseFloat(1.0f); } else { ap.ReportError("Unknown Dialog option " + exp[i]); return(true); } } if (IsModalDialog()) { ap.Dialogs[exp[0]] = cd; } else { ap.ActionFile.Dialogs[exp[0]] = cd; } cd.Trigger += Cd_Trigger; System.Drawing.Size minsize = new System.Drawing.Size(dw.Value, dh.Value); System.Drawing.Size maxsize = new System.Drawing.Size(mw.HasValue ? mw.Value : 50000, mh.HasValue ? mh.Value : 50000); if (x != null && y != null) { cd.Init(minsize, maxsize, new System.Drawing.Point(x.Value, y.Value), ap.ActionController.Icon, exp[1], exp[0], new List <Object>() { ap, IsModalDialog() }, // logical name and tag closeicon: closeicon ); } else { cd.InitCentred(ap.ActionController.Form, minsize, maxsize, ap.ActionController.Icon, exp[1], exp[0], new List <Object>() { ap, IsModalDialog() }, // logical name and tag closeicon: closeicon ); } cd.TopMost = alwaysontop; cd.Show(ap.ActionController.Form); 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 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); }
public override bool ExecuteAction(ActionProgramRun ap) // standard action.. at this class level in action language we do not have an additional parser. { return(ExecuteAction(ap, null)); }
public override bool ExecuteAction(ActionProgramRun ap) { string exp; if (ap.functions.ExpandString(UserData, out exp) != ConditionFunctions.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.NextWord(lowercase: true); 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); }
public override bool ExecuteAction(ActionProgramRun ap) { List <string> ctrl = FromString(UserData); if (ctrl != null) { List <string> exp; if (ap.functions.ExpandStrings(ctrl, out exp) != ConditionFunctions.ExpandResult.Failed) { ConditionVariables 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 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(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); }
public override bool ExecuteAction(ActionProgramRun ap) { return(ExecuteAction(ap, null)); }
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") + " " + timetaken.ElapsedMilliseconds + " @ " + 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 Actions at " + timetaken.ElapsedMilliseconds); restarttick.Start(); break; } } executing = false; }
public override bool ExecuteAction(ActionProgramRun ap) { string pathunexpanded; ConditionVariables statementvars; if (FromString(userdata, out pathunexpanded, out statementvars)) { string errlist = null; ConditionVariables vars = statementvars.ExpandAll(ap.functions, statementvars, out errlist); if (errlist == null) { string path; if (ap.functions.ExpandString(pathunexpanded, out path) != ConditionFunctions.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); } SoundEffectSettings ses = new SoundEffectSettings(vars); // use the rest of the vars to place effects if (!ses.Any && !ses.OverrideNone && ap.VarExist(globalvarplayeffects)) // if can't see any, and override none if off, and we have a global, use that { vars = new ConditionVariables(ap[globalvarplayeffects], ConditionVariables.FromMode.MultiEntryComma); } AudioQueue.AudioSample audio = ap.actioncontroller.AudioQueueWave.Generate(path, vars); if (audio != null) { if (start != null && start.Length > 0) { audio.sampleStartTag = new AudioEvent { apr = ap, eventname = start, triggername = "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, triggername = "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); }
} // null if you dont' want to display public override bool ExecuteAction(ActionProgramRun ap) { ap.Break(); return(true); }
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); }
} // update user data, if allow direct editing public virtual bool ExecuteAction(ActionProgramRun ap) // execute action in the action program context.. AP has data on current state, variables etc. { return(false); }
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")) // verified 10/1/21 { int?x = sp.NextIntComma(","); int?y = sp.NextInt(); if (x != null) { if (y != null) { f.Location = new System.Drawing.Point(x.Value, y.Value); } else { ap.ReportError("Missing position in DialogControl position"); } } else if (sp.IsEOL) { ap["X"] = f.Location.X.ToStringInvariant(); ap["Y"] = f.Location.Y.ToStringInvariant(); } else { ap.ReportError("Missing position in DialogControl position"); } } else if (cmd.Equals("size")) // verified 10/1/21 { int?w = sp.NextIntComma(","); int?h = sp.NextInt(); if (w != null) { if (h != null) { f.Size = new System.Drawing.Size(w.Value, h.Value); } else { ap.ReportError("Missing size in DialogControl size"); } } else if (sp.IsEOL) { ap["W"] = f.Size.Width.ToStringInvariant(); ap["H"] = f.Size.Height.ToStringInvariant(); } else { ap.ReportError("Missing size in DialogControl size"); } } else if (cmd.Equals("get")) { string control = sp.NextQuotedWord(); 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.NextQuotedWord(" ="); 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("enable") || cmd.Equals("visible")) // verified 10/1/21 { string control = sp.NextQuotedWord(); Control c; if (control != null && (c = f.GetControl(control)) != null) { bool?r = sp.NextBoolComma(); if (r != null) { if (cmd.Equals("enable")) { c.Enabled = r.Value; } else { c.Visible = r.Value; } } else if (sp.IsEOL) { if (cmd.Equals("enable")) { ap["Enabled"] = c.Enabled.ToStringIntValue(); } else { ap["Visible"] = c.Visible.ToStringIntValue(); } } else { ap.ReportError("Missing or invalid " + cmd + "value in DialogControl " + cmd); } } else { ap.ReportError("Missing or invalid dialog control name in DialogControl " + cmd); } } else if (cmd.Equals("controlbounds")) // verified 10/1/21 { string control = sp.NextQuotedWord(); Control c; if (control != null && (c = f.GetControl(control)) != null) { int?x = sp.NextIntComma(","); int?y = sp.NextIntComma(","); int?w = sp.NextIntComma(","); int?h = sp.NextInt(); if (x != null && y != null && w != null && h != null) { c.Bounds = new System.Drawing.Rectangle(x.Value, y.Value, w.Value, h.Value); } else if (sp.IsEOL) { ap["X"] = c.Left.ToStringInvariant(); ap["Y"] = c.Top.ToStringInvariant(); ap["W"] = c.Width.ToStringInvariant(); ap["H"] = c.Height.ToStringInvariant(); } else { ap.ReportError("Missing or invalid bounds values in DialogControl controlbounds"); } } else { ap.ReportError("Missing or invalid dialog control name in DialogControl controlbounds"); } } else if (cmd.Equals("close")) { f.ReturnResult(f.DialogResult); 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); }