private void TryRunMacro(JobItemMacro macro, IXDocument doc) { try { macro.Status = JobItemStatus_e.InProgress; m_MacroRunner.RunMacro(m_App, macro.Macro.FilePath, null, XCad.Enums.MacroRunOptions_e.UnloadAfterRun, macro.Macro.Arguments, doc); macro.Status = JobItemStatus_e.Succeeded; } catch (Exception ex) { string errorDesc; if (ex is MacroRunFailedException) { errorDesc = (ex as MacroRunFailedException).Message; } else { errorDesc = "Unknown error"; } LogMessage($"Failed to run macro '{macro.FilePath}': {errorDesc}"); macro.Status = JobItemStatus_e.Failed; } }
public void RunMacro(string macroPath, MacroStartFunction entryPoint, bool unloadAfterRun, string args) { var opts = unloadAfterRun ? MacroRunOptions_e.UnloadAfterRun : MacroRunOptions_e.Default; m_Runner.RunMacro(m_App, macroPath, new XCad.Structures.MacroEntryPoint(entryPoint.ModuleName, entryPoint.SubName), opts, args, null); }
private void AttempRunMacros(IXApplication app, IXDocument doc, List <JobItemMacro> macrosStack, Actions_e actions, bool forbidSaving, CancellationToken cancellationToken) { while (macrosStack.Any()) { var macroItem = macrosStack.First(); try { if (cancellationToken.IsCancellationRequested) { throw new JobCancelledException(); } macroItem.Status = JobItemStatus_e.InProgress; m_UserLogger.WriteLine($"Running '{macroItem.FilePath}' macro"); m_MacroRunnerSvc.RunMacro(app, macroItem.Macro.FilePath, null, XCad.Enums.MacroRunOptions_e.UnloadAfterRun, macroItem.Macro.Arguments, doc); macroItem.Status = JobItemStatus_e.Succeeded; if (actions.HasFlag(Actions_e.AutoSaveDocuments)) { if (!forbidSaving) { m_UserLogger.WriteLine("Saving the document"); doc.Save(); } else { throw new SaveForbiddenException(); } } } catch (JobCancelledException) { throw; } catch (Exception ex) { macroItem.Status = JobItemStatus_e.Failed; string errorDesc; if (ex is MacroRunFailedException || ex is SaveForbiddenException || ex is SaveDocumentFailedException) { errorDesc = ex.Message; } else { errorDesc = "Unknown error"; } m_UserLogger.WriteLine($"Failed to run macro '{macroItem}': {errorDesc}"); if (!doc.IsAlive) { throw new UserMessageException("Document has been disconnected"); } } macrosStack.RemoveAt(0); } }