Ejemplo n.º 1
0
        private void OnProcessOutputData(object sender, DataReceivedEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Data))
            {
                return;
            }

            EventHandler<OutputEventArgs> processOutput = ProcessOutput;
            if (processOutput != null)
            {
                string message = string.Format("{0}{1}", e.Data, Environment.NewLine);
                processOutput(this, new OutputEventArgs(this, message));
            }

            if (_debugger != null)
            {
                return;
            }

            Match match = _debuggerPort.Match(e.Data);
            if (match.Success)
            {
                string portValue = match.Groups[1].Value;
                int port = int.Parse(portValue);

                var client = new NodeDebuggerClient(new NodeDebuggerConnection("localhost", port));
                _debugger = new NodeDebuggerManager(client);

                var tasks = new List<Task>
                    {
                        _debugger.InitializeAsync()
                    };

                if (BreakOnAllExceptions)
                {
                    tasks.Add(_debugger.SetExceptionHandlingAsync(BreakOnAllExceptions));
                }

                try
                {
                    Task.WhenAll(tasks).Wait();
                }
                catch (Exception)
                {
                    _debugger.Terminate();
                }

                EventHandler<EventArgs> processLoaded = ProcessLoaded;
                if (processLoaded != null)
                {
                    processLoaded(this, EventArgs.Empty);
                }
            }
        }
Ejemplo n.º 2
0
        private void OnProcessExited(object sender, EventArgs e)
        {
            if (_sentExited)
            {
                return;
            }

            _sentExited = true;
            _debugger = null;

            EventHandler<EventArgs> threadExited = ThreadExited;
            if (threadExited != null)
            {
                threadExited(this, EventArgs.Empty);
            }

            EventHandler<ProcessExitedEventArgs> processExited = ProcessExited;
            if (processExited == null)
            {
                return;
            }

            int exitCode;
            try
            {
                exitCode = (_process != null && _process.HasExited) ? _process.ExitCode : -1;
            }
            catch (InvalidOperationException)
            {
                // debug attach, we didn't start the process...
                exitCode = -1;
            }

            processExited(this, new ProcessExitedEventArgs(exitCode));
        }