Esempio n. 1
0
 public Repl(Process process, TextBoxWriter textBoxWriter)
 {
     _process = process;
     _textBoxWriter = textBoxWriter;
 }
Esempio n. 2
0
        private static void WireUpTheOutputOfTheReplProcessToTheTextBox(TextBox replTextBox, Process replProcess, Entity<ReplState> replEntity)
        {
            var standardOutputStream = new StreamBuffer();
            var standardErrorStream = new StreamBuffer();
            var textboxWriter = new TextBoxWriter(replTextBox, replEntity);

            var processStreamReader = new AsynchronousAggregateStreamReader(standardOutputStream, standardErrorStream);
            processStreamReader.DataReceived += textboxWriter.WriteToTextBox;

            var outputReaderThread = new Thread(processStreamReader.StartReading);
            var outputBufferStreamThread = new Thread(() => standardOutputStream.ReadStream(replProcess.StandardOutput.BaseStream));
            var errorBufferStreamThread = new Thread(() => standardOutputStream.ReadStream(replProcess.StandardError.BaseStream));

            replTextBox.Loaded +=
                (o, e) =>
                {
                    if (outputReaderThread.IsAlive) return;
                    replProcess.Start();
                    replProcess.StandardInput.AutoFlush = true;
                    outputBufferStreamThread.Start();
                    errorBufferStreamThread.Start();
                    outputReaderThread.Start();
                };

            replProcess.Exited +=
                (o, e) =>
                {
                    outputBufferStreamThread.Abort();
                    errorBufferStreamThread.Abort();
                    outputReaderThread.Abort();
                };
        }