private async System.Threading.Tasks.Task InitAsync()
        {
            try
            {
                logger = await this.GetMefServiceAsync <ILogger>();

                logger.WriteLine(Resources.Strings.Daemon_Initializing);

                await DisableRuleCommand.InitializeAsync(this, logger);

                await CFamilyReproducerCommand.InitializeAsync(this, logger);

                cFamilyPreCompiledHeadersEventListener = await this.GetMefServiceAsync <IPreCompiledHeadersEventListener>();

                daemon = await this.GetMefServiceAsync <ISonarLintDaemon>();

                LegacyInstallationCleanup.CleanupDaemonFiles(logger);

                // Set up the solution tracker so we can shut down the daemon when a solution is closed
                var solutionTracker = await this.GetMefServiceAsync <IActiveSolutionTracker>();

                solutionTracker.ActiveSolutionChanged += HandleActiveSolutionChanged;

                IDaemonInstaller installer = await this.GetMefServiceAsync <IDaemonInstaller>();

                if (!installer.IsInstalled())
                {
                    // Set up the status bar download handler in case the user enables
                    // support for additional languages during the VS session
                    var sbService = await this.GetServiceAsync(typeof(IVsStatusbar)) as IVsStatusbar;

                    statusBarDownloadProgressHandler = new StatusBarDownloadProgressHandler(sbService, installer, logger);

                    var settings = await this.GetMefServiceAsync <ISonarLintSettings>();

                    if (settings.IsActivateMoreEnabled)
                    {
                        // User already agreed to have the daemon installed so directly start download.
                        // No UI interation so we don't need to be on the UI thread.
                        installer.Install();
                    }
                }
            }
            catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex))
            {
                logger?.WriteLine(Resources.Strings.ERROR_InitializingDaemon, ex);
            }
            logger?.WriteLine(Resources.Strings.Daemon_InitializationComplete);
        }
Пример #2
0
        private void OnActivateMoreClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!installer.IsInstalled())
                {
                    installer.Install();
                }

                settings.IsActivateMoreEnabled = true;

                UpdateActiveMoreControls();
            }
            catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex))
            {
                logger.WriteLine(Strings.ERROR_ConfiguringDaemon, ex);
            }
        }
 public void Execute()
 {
     // Note: called on the UI thread so an unhandled exception will crash VS.
     // However, the only excecution path to this point should be from our tagger which
     // should handle any exceptions.
     if (!daemonInstaller.IsInstalled())
     {
         daemonInstaller.InstallationCompleted += HandleInstallCompleted;
         daemonInstaller.Install();
     }
     else
     {
         if (!daemon.IsRunning)
         {
             daemon.Ready += HandleDaemonReady;
             daemon.Start();
         }
         else
         {
             MakeRequest();
         }
     }
 }
        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();
            }
        }