예제 #1
0
        private void OnOutputReceived(object sender, string unorderedText)
        {
            // TODO: rajkumar42 The OutputReceived event in liblinux has some issues. If we stick with liblinux, we should fix it:
            // 1. It kicks off a different thread pool thread every time data is received. As such there is no
            // way to order the input.
            // 2. The shell in Linux keeps a queue of input. If a component only obtains the input through the
            // output received event, then nothing will ever drain the output.
            //
            // Suggested fix: Add a ReadLine async method to the shell and remove the output received event

            // TODO: rajkumar42, this breaks when logging in as root.

            IEnumerable <string> linesToSend = null;

            lock (_lock)
            {
                string text = _shellStream.ReadToEnd();
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                _lineBuffer.ProcessText(text, out linesToSend);
            }

            foreach (string line in linesToSend)
            {
                if (_isClosed)
                {
                    return;
                }

                int endCommandIndex = line.IndexOf(_exitMessagePrefix);
                if (endCommandIndex >= 0)
                {
                    if (Interlocked.CompareExchange(ref _firedOnExit, 1, 0) == 0)
                    {
                        string exitCode = SplitExitCode(line, endCommandIndex + _exitMessagePrefix.Length);
                        _callback.OnExit(exitCode);
                    }
                    Close();
                    return;
                }

                if (!_beginReceived)
                {
                    if (line.Contains(_beginMessage))
                    {
                        _beginReceived = true;
                    }
                    continue;
                }

                _callback.OnOutputLine(line);
            }
        }
예제 #2
0
        protected override void OnOutputReceived(object sender, string e)
        {
            IEnumerable <string> linesToSend = null;

            if (string.IsNullOrEmpty(e))
            {
                return;
            }

            _lineBuffer.ProcessText(e, out linesToSend);

            foreach (string line in linesToSend)
            {
                if (_bClosed == 1)
                {
                    return;
                }

                if (_startCommand != null)
                {
                    if (line.Contains(_startCommand))
                    {
                        // When logged in as root, shell sends a copy of stdin to stdout. On MacOS
                        // trailing control characters appear on the line.
                        // This ignores the shell command that was used to launch the debugger.
                        continue;
                    }

                    int endCommandIndex = line.IndexOf(_exitMessagePrefix, StringComparison.Ordinal);
                    if (endCommandIndex >= 0)
                    {
                        if (Interlocked.CompareExchange(ref _firedOnExit, 1, 0) == 0)
                        {
                            string exitCode = SplitExitCode(line, endCommandIndex + _exitMessagePrefix.Length);
                            Callback.OnExit(exitCode);
                        }
                        Close();
                        return;
                    }

                    if (!_beginReceived)
                    {
                        if (line.Contains(_beginMessage))
                        {
                            _beginReceived = true;
                        }
                        continue;
                    }
                }

                Callback.OnOutputLine(line);
            }
        }
예제 #3
0
        private void OnOutputReceived(object sender, OutputReceivedEventArgs e)
        {
            IEnumerable <string> linesToSend = null;

            lock (_lock)
            {
                if (string.IsNullOrEmpty(e.Output))
                {
                    return;
                }

                _lineBuffer.ProcessText(e.Output, out linesToSend);
            }

            foreach (string line in linesToSend)
            {
                if (_isClosed)
                {
                    return;
                }

                if (line.Equals(_startCommand, StringComparison.Ordinal))
                {
                    // When logged in as root, shell sends a copy of stdin to stdout.
                    // This ignores the shell command that was used to launch the debugger.
                    continue;
                }

                int endCommandIndex = line.IndexOf(_exitMessagePrefix);
                if (endCommandIndex >= 0)
                {
                    if (Interlocked.CompareExchange(ref _firedOnExit, 1, 0) == 0)
                    {
                        string exitCode = SplitExitCode(line, endCommandIndex + _exitMessagePrefix.Length);
                        _callback.OnExit(exitCode);
                    }
                    Close();
                    return;
                }

                if (!_beginReceived)
                {
                    if (line.Contains(_beginMessage))
                    {
                        _beginReceived = true;
                    }
                    continue;
                }

                _callback.OnOutputLine(line);
            }
        }
예제 #4
0
        private void Verify(LineBuffer lineBuffer, string textToAdd, string[] expectedOutput)
        {
            IEnumerable<string> result;
            lineBuffer.ProcessText(textToAdd, out result);
            string[] r = result.ToArray();

            Assert.AreEqual<int>(expectedOutput.Length, r.Length);

            for (int i = 0; i < expectedOutput.Length; i++)
            {
                Assert.AreEqual<string>(expectedOutput[i], r[i]);
            }
        }