Пример #1
0
        public void Start(int port)
        {
            if (!_running)
            {
                Port = port;

                _running           = true;
                _stream            = new PipeStream();
                _writer            = new StreamWriter(_stream);
                _cancellationToken = new CancellationTokenSource();

                _eventAggregator.GetEvent <LogEvent>().Subscribe(ProcessLog, ThreadOption.BackgroundThread);

                Task.Factory.StartNew(() =>
                {
                    while (_running)
                    {
                        // parse input args, and open input file
                        var scanner             = new TelnetScanner(_stream);
                        scanner.ErrorPorcessed += PublishError;

                        while (_running && !scanner.Restart)
                        {
                            if (_stream.Length > 0)
                            {
                                var parser = new BrightScriptDebug.Compiler.Parser(scanner);

                                parser.BacktraceProcessed += PublishBacktrace;
                                parser.VariablesProcessed += PublishVariables;
                                parser.DebugPorcessed     += PublishDebug;
                                parser.AppCloseProcessed  += PublishAppClose;
                                parser.AppOpenProcessed   += PublishAppOpen;

                                try
                                {
                                    parser.Parse();
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                parser.BacktraceProcessed -= PublishBacktrace;
                                parser.VariablesProcessed -= PublishVariables;
                                parser.DebugPorcessed     -= PublishDebug;
                                parser.AppCloseProcessed  -= PublishAppClose;
                                parser.AppOpenProcessed   -= PublishAppOpen;
                            }

                            Task.Delay(100).Wait();
                        }

                        if (_running && scanner.Restart)
                        {
                            Console.WriteLine("Restart Scanner {0}", port);
                        }
                    }
                }, _cancellationToken.Token);
            }
        }
Пример #2
0
        public void OnStdOutLine(string line)
        {
            if (line.Length == 0)
            {
                return;
            }
            if (!_initialized && !line.Contains("------ Running dev '"))
            {
                return;
            }

            if (!_initialized)
            {
                var index = line.LastIndexOf("------ Running dev '", StringComparison.Ordinal);
                if (index > 0)
                {
                    line = Environment.NewLine + line.Substring(index);
                    if (line.Contains("------ Compiling dev '"))
                    {
                        return;
                    }
                    _initialized = true;
                }
            }

            if (_lasCommand.HasValue)
            {
                if (_injectStrings.ContainsKey(_lasCommand.Value))
                {
                    line = _injectStrings[_lasCommand.Value] + Environment.NewLine + line;
                }


                _lasCommand = null;
            }

            OnOutput?.Invoke(line);

            DispatchGeneric(line);

            try
            {
                using (var ms = new MemoryStream())
                {
                    using (var sw = new StreamWriter(ms))
                    {
                        sw.WriteLine(line);
                        sw.Flush();
                        ms.Position = 0;

                        // parse input args, and open input file
                        var scanner = new TelnetScanner(ms);
                        scanner.ErrorPorcessed += PublishError;

                        var parser = new BrightScriptDebug.Compiler.Parser(scanner);

                        parser.BacktraceProcessed       += ParserOnBacktraceProcessed;
                        parser.VariablesProcessed       += ParserOnVariablesProcessed;
                        parser.DebugPorcessed           += ParserOnDebugPorcessed;
                        parser.AppCloseProcessed        += ParserOnAppCloseProcessed;
                        parser.AppOpenProcessed         += ParserOnAppOpenProcessed;
                        parser.CurrentFunctionProcessed += ParserOnCurrentFunctionProcessed;
                        parser.StepPorcessed            += ParserOnStepPorcessed;

                        try
                        {
                            parser.Parse();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        parser.BacktraceProcessed       -= ParserOnBacktraceProcessed;
                        parser.VariablesProcessed       -= ParserOnVariablesProcessed;
                        parser.DebugPorcessed           -= ParserOnDebugPorcessed;
                        parser.AppCloseProcessed        -= ParserOnAppCloseProcessed;
                        parser.AppOpenProcessed         -= ParserOnAppOpenProcessed;
                        parser.CurrentFunctionProcessed -= ParserOnCurrentFunctionProcessed;
                        parser.StepPorcessed            += ParserOnStepPorcessed;
                    }
                }
            }
            catch (Exception ex)
            {
                LiveLogger.WriteLine(ex.Message);
            }
        }