Inheritance: System.Windows.Window
Exemplo n.º 1
0
        /// <summary>
        /// Shows the window.
        /// </summary>
        public static void ShowWindow()
        {
            System.Threading.AutoResetEvent windowShown = new System.Threading.AutoResetEvent(false);

            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.Show();
                    windowShown.Set();

                    var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame();
                    window.Closed += (obj, e) => { _dispatcherFrame.Continue = false; };
                    System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    windowShown.Set();
                }

                window?.Close();
                System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
            }, waitForExecution: false);
            windowShown.WaitOne();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows the window as modal dialog.
        /// </summary>
        public static void ShowModalWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Shows the window as modal dialog.
        /// </summary>
        public static void ShowModalWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
                System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Shows the window.
        /// </summary>
        public static void ShowWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.Show();

                    var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame();
                    window.Closed       += (obj, e) => { _dispatcherFrame.Continue = false; };
                    System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
            }, waitForExecution: false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shows the window as modal dialog.
        /// </summary>
        public static void ShowModalWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
                System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Shows the window.
        /// </summary>
        public static void ShowWindow()
        {
            ExecuteInSTA(() =>
            {
                Window window = null;

                try
                {
                    window = new InteractiveWindow();
                    window.Show();

                    var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame();
                    window.Closed += (obj, e) => { _dispatcherFrame.Continue = false; };
                    System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                window.Close();
                System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
            }, waitForExecution: false);
        }
Exemplo n.º 7
0
        protected override void OnExecuteCSharpScript()
        {
            BackgroundExecute((string _documentText, out string _textOutput, out string _errorOutput, out IEnumerable <object> _result) =>
            {
                BackgroundExecuteDelegate scriptExecution = (string documentText, out string textOutput, out string errorOutput, out IEnumerable <object> result) =>
                {
                    // Setting results
                    textOutput  = "";
                    errorOutput = "";

                    // Execution code
                    var oldOut   = Console.Out;
                    var oldError = Console.Error;

                    try
                    {
                        using (StringWriter writer = new StringWriter())
                        {
                            Console.SetOut(writer);
                            Console.SetError(writer);

                            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(Console.Out, captureFlags);

                            interactiveExecution.scriptBase._UiActionExecutor_ = (action) => Dispatcher.Invoke(action);
                            using (OutputCallbacksSwitcher switcher = OutputCallbacksSwitcher.Create(callbacks))
                            {
                                interactiveExecution.UnsafeInterpret(documentText);
                                writer.Flush();
                                textOutput = writer.GetStringBuilder().ToString();
                            }
                        }

                        UpdateScriptCode();
                    }
                    catch (Microsoft.CodeAnalysis.Scripting.CompilationErrorException ex)
                    {
                        StringBuilder sb = new StringBuilder();

                        sb.AppendLine("Compile errors:");
                        foreach (var error in ex.Diagnostics)
                        {
                            sb.AppendLine(error.ToString());
                        }

                        errorOutput = sb.ToString();
                    }
                    catch (ExitRequestedException)
                    {
                        throw;
                    }
                    catch (AggregateException ex)
                    {
                        if (ex.InnerException is ExitRequestedException)
                        {
                            throw ex.InnerException;
                        }
                        errorOutput = ex.ToString();
                    }
                    catch (TargetInvocationException ex)
                    {
                        if (ex.InnerException is ExitRequestedException)
                        {
                            throw ex.InnerException;
                        }
                        errorOutput = ex.InnerException.ToString();
                    }
                    catch (Exception ex)
                    {
                        errorOutput = ex.ToString();
                    }
                    finally
                    {
                        Console.SetError(oldError);
                        Console.SetOut(oldOut);
                        result  = results;
                        results = new List <object>();
                        interactiveExecution.scriptBase._UiActionExecutor_ = null;
                    }
                };

                // Check if we should execute script code in STA thread
                if (interactiveExecution.scriptBase.ForceStaExecution)
                {
                    string tempTextOutput           = null;
                    string tempErrorOutput          = null;
                    IEnumerable <object> tempResult = null;

                    InteractiveWindow.ExecuteInSTA(() =>
                    {
                        scriptExecution(_documentText, out tempTextOutput, out tempErrorOutput, out tempResult);
                    });
                    _textOutput  = tempTextOutput;
                    _errorOutput = tempErrorOutput;
                    _result      = tempResult;
                }
                else
                {
                    scriptExecution(_documentText, out _textOutput, out _errorOutput, out _result);
                }
            }, true);
        }