Beispiel #1
0
            public ConsoleOutputController(RunWindow page)
            {
                var previousConsole = Console.Out;

                Writer        = new StreamWriter(memoryStream, System.Text.Encoding.Unicode);
                page.OldCaret = 0;
                Console.SetOut(Writer);
                new Task(() =>
                {
                    try
                    {
                        var lastPosition    = 0L;
                        StreamReader reader = new StreamReader(memoryStream, System.Text.Encoding.Unicode);
                        while (true)
                        {
                            Thread.Sleep(60);
                            Writer.Flush();
                            var currentPosition = Writer.BaseStream.Position;
                            if (currentPosition > lastPosition)
                            {
                                var buff = new char[(currentPosition - lastPosition) / sizeof(char)];
                                memoryStream.Position = lastPosition;
                                int length            = reader.ReadBlock(buff, 0, buff.Length);
                                lastPosition          = currentPosition;
                                if (length > 0)
                                {
                                    page.Dispatcher.Invoke(new Action(() =>
                                    {
                                        page.OldCaret = page.ConsoleOutput.CaretIndex;
                                    }));
                                    ConsoleOutput = ConsoleOutput + new string(buff, 0, length);
                                    var e         = PropertyChanged;
                                    if (e != null)
                                    {
                                        e(this, new PropertyChangedEventArgs("ConsoleOutput"));
                                    }
                                }
                            }
                            if (this.Done)
                            {
                                Writer.Dispose();
                                Writer = null;
                                return;
                            }
                        }
                    }
                    catch
                    {
                        Console.SetOut(previousConsole);
                    }
                }, TaskCreationOptions.LongRunning).Start();
            }
Beispiel #2
0
 public ConsoleOutputController(RunWindow page)
 {
     var previousConsole = Console.Out;
     Writer = new StreamWriter(memoryStream, System.Text.Encoding.Unicode);
     page.OldCaret = 0;
     Console.SetOut(Writer);
     new Task(() =>
     {
         try
         {
             var lastPosition = 0L;
             StreamReader reader = new StreamReader(memoryStream, System.Text.Encoding.Unicode);
             while (true)
             {
                 Thread.Sleep(60);
                 Writer.Flush();
                 var currentPosition = Writer.BaseStream.Position;
                 if (currentPosition > lastPosition)
                 {
                     var buff = new char[(currentPosition - lastPosition) / sizeof(char)];
                     memoryStream.Position = lastPosition;
                     int length = reader.ReadBlock(buff, 0, buff.Length);
                     lastPosition = currentPosition;
                     if (length > 0)
                     {
                         page.Dispatcher.Invoke(new Action(() =>
                         {
                             page.OldCaret = page.ConsoleOutput.CaretIndex;
                         }));
                         ConsoleOutput = ConsoleOutput + new string(buff, 0, length);
                         var e = PropertyChanged;
                         if (e != null)
                         {
                             e(this, new PropertyChangedEventArgs("ConsoleOutput"));
                         }
                     }
                 }
                 if (this.Done)
                 {
                     Writer.Dispose();
                     Writer = null;
                     return;
                 }
             }
         }
         catch
         {
             Console.SetOut(previousConsole);
         }
     }, TaskCreationOptions.LongRunning).Start();
 }
Beispiel #3
0
 private void SetupRunButton(LayoutDocument document)
 {
     var modelSystem = document.Content as ModelSystemDisplay;
     RunMenu.IsEnabled = false;
     if(modelSystem != null)
     {
         var session = modelSystem.Session;
         if(session.CanRun)
         {
             RunMenu.IsEnabled = true;
             _CurrentRun = () =>
             {
                 RunWindow window = new RunWindow(session);
                 var doc = AddNewWindow("New Run", window);
                 doc.CanClose = true;
                 doc.IsSelected = true;
                 Keyboard.Focus(window);
                 window.Focus();
             };
         }
     }
 }
Beispiel #4
0
 private void SetupRunButton(LayoutDocument document)
 {
     var modelSystem = document.Content as ModelSystemDisplay;
     RunMenu.IsEnabled = false;
     RunLabel.IsEnabled = false;
     if (modelSystem != null)
     {
         var session = modelSystem.Session;
         if (session.CanRun)
         {
             RunMenu.IsEnabled = true;
             RunLabel.IsEnabled = true;
             _CurrentRun = () =>
             {
                 var runName = "Run Name";
                 StringRequest req = new StringRequest("Run Name", ValidateName);
                 var trueWindow = Window.GetWindow(document.Content as DependencyObject);
                 var testWindow = GetWindow(document.Content as DependencyObject);
                 var vis = document.Content as UserControl;
                 if (vis != null && testWindow != trueWindow)
                 {
                     var topLeft = vis.PointToScreen(new Point());
                     // Since the string request dialog isn't shown yet we need to use some defaults as width and height are not available.
                     req.Left = topLeft.X + ((vis.ActualWidth - StringRequest.DefaultWidth) / 2);
                     req.Top = topLeft.Y + ((vis.ActualHeight - StringRequest.DefaultHeight) / 2);
                 }
                 else
                 {
                     req.Owner = trueWindow;
                 }
                 if (req.ShowDialog() == true)
                 {
                     runName = req.Answer;
                     string error = null;
                     var run = session.Run(runName, ref error);
                     if (run != null)
                     {
                         RunWindow window = new RunWindow(session, run, runName);
                         var doc = AddNewWindow("New Run", window);
                         doc.Closing += (o, e) =>
                         {
                             if (!window.CloseRequested())
                             {
                                 e.Cancel = true;
                                 return;
                             }
                         };
                         doc.CanClose = true;
                         doc.IsSelected = true;
                         Keyboard.Focus(window);
                         window.Focus();
                     }
                     else
                     {
                         MessageBox.Show(this, error, "Unable to run", MessageBoxButton.OK, MessageBoxImage.Error);
                     }
                 }
             };
         }
     }
 }