internal void TextArea_ExecuteCSharpScript(object sender, ExecutedRoutedEventArgs e) { if (InteractiveExecution.IsCompleteSubmission(Document.Text)) { OnExecuteCSharpScript(); } else { TextArea.PerformTextInput(Environment.NewLine); } }
public void VerifyOutput(string code) { UiExecutionEntry[] executions = GetExecutions().Take(2).ToArray(); Assert.Equal(2, executions.Length); UiExecutionEntry currentEntry = executions[0]; UiExecutionEntry lastExecution = executions[1]; // Capture code output string expectedOutput; string expectedError; using (StringWriter outputWriter = new StringWriter()) using (StringWriter errorWriter = new StringWriter()) { TextWriter originalOutput = Console.Out; TextWriter originalError = Console.Error; try { Console.SetOut(outputWriter); Console.SetError(errorWriter); DebugOutput captureFlags = DebugOutput.Normal | DebugOutput.Error | DebugOutput.Warning | DebugOutput.Verbose | DebugOutput.Prompt | DebugOutput.PromptRegisters | DebugOutput.ExtensionWarning | DebugOutput.Debuggee | DebugOutput.DebuggeePrompt | DebugOutput.Symbols | DebugOutput.Status; var callbacks = DebuggerOutputToTextWriter.Create(outputWriter, captureFlags); using (OutputCallbacksSwitcher switcher = OutputCallbacksSwitcher.Create(callbacks)) { InteractiveExecution.Interpret(code); } expectedOutput = outputWriter.GetStringBuilder().ToString(); expectedError = errorWriter.GetStringBuilder().ToString(); } finally { Console.SetOut(originalOutput); Console.SetError(originalError); } } // Verify that output is the same if (currentEntry.Code == lastExecution.Code) { Assert.Equal(FixOutput(expectedError), FixOutput(lastExecution.ResultText)); } else { Assert.Equal(FixOutput(expectedOutput), FixOutput(lastExecution.ResultText)); } }
public InteractiveCodeEditor() { interactiveExecution = new InteractiveExecution(); interactiveExecution.scriptBase._InternalObjectWriter_ = new ObjectWriter() { InteractiveCodeEditor = this, }; interactiveExecution.scriptBase.ObjectWriter = new InteractiveResultVisualizer(); // Run initialization of the window in background task IsEnabled = false; Task.Run(() => { try { Initialize(); Dispatcher.InvokeAsync(() => { IsEnabled = true; if (Executing != null) { Executing(false); } }); } catch (ExitRequestedException) { Dispatcher.InvokeAsync(() => { if (CloseRequested != null) { CloseRequested(); } }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }
/// <summary> /// Initializes a new instance of the <see cref="InteractiveCodeEditor" /> class. /// </summary> /// <param name="objectWriter">Interactive result visualizer object writer.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="indentationSize">Size of the indentation.</param> /// <param name="highlightingColors">The highlighting colors.</param> public InteractiveCodeEditor(InteractiveResultVisualizer objectWriter, string fontFamily, double fontSize, int indentationSize, params ICSharpCode.AvalonEdit.Highlighting.HighlightingColor[] highlightingColors) : base(fontFamily, fontSize, indentationSize, highlightingColors) { interactiveExecution = new InteractiveExecution(); interactiveExecution.scriptBase._InternalObjectWriter_ = new ObjectWriter() { InteractiveCodeEditor = this, }; interactiveExecution.scriptBase.ObjectWriter = objectWriter; // Run initialization of the window in background task IsEnabled = false; Task.Run(() => { try { Dispatcher.InvokeAsync(() => { IsEnabled = true; Executing?.Invoke(false); }); Initialize(); Dispatcher.InvokeAsync(() => { InitializationFinished?.Invoke(); }); } catch (ExitRequestedException) { Dispatcher.InvokeAsync(() => { CloseRequested?.Invoke(); }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }
public InteractiveCodeEditor() { interactiveExecution = new InteractiveExecution(); interactiveExecution.scriptBase._InternalObjectWriter_ = new ObjectWriter() { InteractiveCodeEditor = this, }; interactiveExecution.scriptBase.ObjectWriter = new InteractiveResultVisualizer(); // Run initialization of the window in background task IsEnabled = false; Task.Run(() => { try { Initialize(); Dispatcher.InvokeAsync(() => { IsEnabled = true; if (Executing != null) Executing(false); }); } catch (ExitRequestedException) { Dispatcher.InvokeAsync(() => { if (CloseRequested != null) CloseRequested(); }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); }
/// <summary> /// Gets the string that describes value of the variable / property. /// </summary> protected override string GetTypeString() { return(resultType != null?InteractiveExecution.GetCodeName(result?.GetType() ?? resultType) : ""); }