示例#1
0
        public void WriteSettingsFile()
        {
            if (!xDoc.Descendants("someNodeName").Any())
            {
                return;
            }

            foreach (var desc in xDoc.Descendants("someNodeName"))
            {
                desc.SetValue(TheAnswerToLifeUniverseAndEverything);
            }

            xDoc.Save(SettingsFile);
        }
示例#2
0
        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);
            }
        }