private void ReParse()
        {
            try
            {
                _dirty = false;

                IOutputWindowPane outputWindow = null;
                if (_outputWindowService != null && !string.IsNullOrEmpty(_outputWindowName))
                {
                    outputWindow = _outputWindowService.TryGetPane(_outputWindowName);
                }

                Stopwatch stopwatch = Stopwatch.StartNew();

                string message = "{0}: Background parse {1}{2} in {3}ms. {4}";
                string name    = Name;
                if (!string.IsNullOrEmpty(name))
                {
                    name = "(" + name + ") ";
                }

                string        filename     = "<Unknown File>";
                ITextDocument textDocument = TextDocument;
                if (textDocument != null)
                {
                    filename = textDocument.FilePath;
                    if (filename != null)
                    {
                        filename = filename.Substring(filename.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }) + 1);
                    }
                }

                try
                {
                    ReParseImpl();

                    if (outputWindow != null)
                    {
                        long time = stopwatch.ElapsedMilliseconds;
                        outputWindow.WriteLine(string.Format(message, filename, name, "succeeded", time, string.Empty));
                    }
                }
                catch (Exception e2)
                {
                    if (ErrorHandler.IsCriticalException(e2))
                    {
                        throw;
                    }

                    try
                    {
                        if (outputWindow != null)
                        {
                            long time = stopwatch.ElapsedMilliseconds;
                            outputWindow.WriteLine(string.Format(message, filename, name, "failed", time, e2.Message + e2.StackTrace));
                        }
                    }
                    catch (Exception e3)
                    {
                        if (ErrorHandler.IsCriticalException(e3))
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ErrorHandler.IsCriticalException(ex))
                {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public void Start()
        {
            if (IsRunning)
            {
                logger.WriteLine("Daemon is already running");
                return;
            }

            if (!installer.IsInstalled())
            {
                logger.WriteLine("Daemon is not installed");
                return;
            }

            if (!settings.IsActivateMoreEnabled)
            {
                // Don't start if the user has subsequently deactivated support for additional languages
                logger.WriteLine(Strings.Daemon_NotStarting_NotEnabled);
                return;
            }

            logger.WriteLine(Strings.Daemon_Starting);

            Port    = TcpUtil.FindFreePort(DefaultDaemonPort);
            process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    UseShellExecute        = false,
                    ErrorDialog            = false, // don't display UI to user
                    FileName               = ExePath,
                    Arguments              = GetCmdArgs(Port),
                    CreateNoWindow         = true,
                    WindowStyle            = ProcessWindowStyle.Hidden,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                }
            };

            process.OutputDataReceived += (sender, args) => HandleOutputDataReceived(args?.Data);
            process.ErrorDataReceived  += (sender, args) => HandleErrorDataReceived(args?.Data);

            if (IsVerbose())
            {
                WritelnToPane($"Running {ExePath}");
            }

            try
            {
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                logger.WriteLine(Strings.Daemon_Started);
            }
            catch (Exception e) when(!ErrorHandler.IsCriticalException(e))
            {
                Debug.WriteLine("Unable to start SonarLint daemon: {0}", e);
                WritelnToPane($"Unable to start SonarLint daemon {e.Message}");
                this.SafeInternalStop();
            }
        }