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(); } }
public void Start() { if (IsRunning) { throw new InvalidOperationException("Process already running"); } if (!IsInstalled) { throw new InvalidOperationException("Daemon is not installed"); } logger.WriteLine(Strings.Daemon_Starting); port = TcpUtil.FindFreePort(DEFAULT_DAEMON_PORT); process = new Process { StartInfo = new ProcessStartInfo { UseShellExecute = false, FileName = ExePath, Arguments = GetCmdArgs(port), CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardOutput = true, RedirectStandardError = true } }; process.OutputDataReceived += (sender, args) => { string data = args.Data; if (data != null) { if (data.Contains("Server started")) { CreateChannelAndStreamLogs(); Ready?.Invoke(this, EventArgs.Empty); } if (IsVerbose()) { WritelnToPane(data); } } }; process.ErrorDataReceived += (sender, args) => { string data = args.Data; if (data != null) { WritelnToPane(data); } }; if (IsVerbose()) { WritelnToPane($"Running {ExePath}"); } try { process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); logger.WriteLine(Strings.Daemon_Started); } catch (Exception e) { Debug.WriteLine("Unable to start SonarLint daemon: {0}", e); WritelnToPane($"Unable to start SonarLint daemon {e.Message}"); } }