public override void OnExecute(object sender) { if (commanderWindow == null || !commanderWindow.IsLoaded) { InitializeAddinModel(); commanderWindow = new CommanderWindow(this); commanderWindow.Top = Model.Window.Top; commanderWindow.Left = Model.Window.Left + Model.Window.Width - Model.Configuration.WindowPosition.SplitterPosition; } commanderWindow.Show(); commanderWindow.Activate(); }
public void RunCommand(CommanderCommand command) { if (AddinModel.AppModel == null) { InitializeAddinModel(); } string code = command.CommandText; bool showConsole = commanderWindow != null && commanderWindow.Visibility == Visibility.Visible; if (showConsole) { var tbox = commanderWindow.TextConsole; tbox.Clear(); WindowUtilities.DoEvents(); Console.SetOut(new ConsoleTextWriter() { tbox = tbox }); } var parser = new ScriptParser(); if (!parser.EvaluateScript(code, AddinModel)) { if (!showConsole) { AddinModel.Window.ShowStatus("*** Addin execution failed: " + parser.ErrorMessage, 6000); AddinModel.Window.SetStatusIcon(FontAwesomeIcon.Warning, Colors.Red); } else { Console.WriteLine($"*** Error running Script code:\r\n{parser.ErrorMessage}"); } if (CommanderAddinConfiguration.Current.OpenSourceInEditorOnErrors) { string fname = Path.Combine(Path.GetTempPath(), "Commander_Compiled_Code.cs"); File.WriteAllText(fname, parser.ScriptInstance.SourceCode); var tab = OpenTab(fname); File.Delete(fname); if (tab != null) { var editor = tab.Tag as MarkdownDocumentEditor; editor.SetEditorSyntax("csharp"); editor.SetMarkdown(parser.ScriptInstance.SourceCode); Dispatcher.CurrentDispatcher.InvokeAsync(() => { if (editor.AceEditor == null) { Task.Delay(400); } editor.AceEditor.setshowlinenumbers(true); if (commanderWindow == null) { commanderWindow = new CommanderWindow(this); commanderWindow.Show(); } else { commanderWindow.Activate(); } }, DispatcherPriority.ApplicationIdle); } } } else { AddinModel.Window.ShowStatus("Command execution for " + command.Name + " completed successfully", 6000); } if (showConsole) { commanderWindow.TextConsole.ScrollToHome(); StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); } }