//_________________________________________________________________________________________________________ #region Macro Execution Next Section after Async call (with Interface Alignment) //_________________________________________________________________________________________________________ public void ExecMacroNextSectionAfterAsyncCall(string sMacroFile) { LogHelper.Msg(); try { if (!File.Exists(sMacroFile)) { return; } using (var helper = new AsmHelper(CSScript.CompileFile(sMacroFile), null, false)) { IFIMSyncMacro script = helper.CreateAndAlignToInterface <IFIMSyncMacro>("Script"); script.LastExecTerminated(this, MacroHelper.ExecName, currentMacroParam); } } catch (Exception ex) { string sMsg = string.Format("[{0}]\n[{1}]\n{2}", sMacroFile, currentMacroParam, ex.Message); LogHelper.Msg("ERROR:\n" + sMsg); LogError(sMsg.Replace('\n', '\\')); MessageBox.Show("ERROR:\n" + sMsg, "ExecMacroNextSectionAfterAsyncCall", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } // If there is not pending activities, call to EndScript if (!MacroHelper.Running && currentMacro != "") { ExecMacroEnd(currentMacro, currentMacroParam); } }
//_________________________________________________________________________________________________________ #region Macro Start Execution (with Interface Alignment) //_________________________________________________________________________________________________________ public void ExecMacro(string sMacroFile, string sParam = "") { LogHelper.Msg(); try { if (!File.Exists(sMacroFile)) { return; } using (var helper = new AsmHelper(CSScript.CompileFile(sMacroFile), null, false)) { IFIMSyncMacro script = helper.CreateAndAlignToInterface <IFIMSyncMacro>("Script"); script.EntryScript(this, sParam); // Save data till the end of macro execution (EndScript) currentMacro = sMacroFile; currentMacroParam = sParam; } } catch (Exception ex) { string sMsg = string.Format("[{0}]\n[{1}]\n{2}", sMacroFile, sParam, ex.Message); LogHelper.Msg("ERROR:\n" + sMsg); LogError(sMsg.Replace('\n', '\\')); MessageBox.Show("ERROR:\n" + sMsg, "ExecMacro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } // If there is not pending activities, call to EndScript while (!MacroHelper.Running && currentMacro != "") { ExecMacroEnd(currentMacro, currentMacroParam); } if (currentMacro == "" && pendingMacros.Count == 0) { f.mExecMacro.Enabled = true; } }
//_________________________________________________________________________________________________________ #region Macro End Execution (with Interface Alignment) //_________________________________________________________________________________________________________ public void ExecMacroEnd(string sMacroFile, string sParam = "") { LogHelper.Msg(); try { currentMacro = ""; currentMacroParam = ""; if (!File.Exists(sMacroFile)) { return; } using (var helper = new AsmHelper(CSScript.CompileFile(sMacroFile), null, false)) { IFIMSyncMacro script = helper.CreateAndAlignToInterface <IFIMSyncMacro>("Script"); script.EndScript(this, sParam); // If an Async method is called, again a new call to EndScript is pending if (MacroHelper.Running) { currentMacro = sMacroFile; currentMacroParam = sParam; } } } catch (Exception ex) { string sMsg = string.Format("[{0}]\n[{1}]\n{2}", sMacroFile, sParam, ex.Message); LogHelper.Msg("ERROR:\n" + sMsg); LogError(sMsg.Replace('\n', '\\')); MessageBox.Show("ERROR:\n" + sMsg, "ExecMacroEnd", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } // If there is not pending activities, call to EndScript while (!MacroHelper.Running && currentMacro != "") { ExecMacroEnd(currentMacro, currentMacroParam); } // Enable timer to call next pending macro or enable menu if (!MacroHelper.Running && pendingMacros.Count > 0) { f.cTimerNextMacro.Enabled = true; } else { f.mExecMacro.Enabled = true; } }