Пример #1
0
        public static void LogInstallationStatus(Workspace workspace, LiveCodeAnalysisInstallStatus installStatus)
        {
            var vsixInstalled = workspace.Options.GetOption(AnalyzerABTestOptions.VsixInstalled);

            if (!vsixInstalled && installStatus == LiveCodeAnalysisInstallStatus.Installed)
            {
                // first time after vsix installed
                workspace.Options = workspace.Options.WithChangedOption(AnalyzerABTestOptions.VsixInstalled, true);
                workspace.Options = workspace.Options.WithChangedOption(AnalyzerABTestOptions.ParticipatedInExperiment, true);
                Log("Installed");

                // set the system to report the errors.
                s_reportErrors = true;
            }

            if (vsixInstalled && installStatus == LiveCodeAnalysisInstallStatus.NotInstalled)
            {
                // first time after vsix is uninstalled
                workspace.Options = workspace.Options.WithChangedOption(AnalyzerABTestOptions.VsixInstalled, false);
                Log("Uninstalled");
            }
        }
        private bool IsVsixInstalled()
        {
            if (_installStatus == LiveCodeAnalysisInstallStatus.Unknown)
            {
                var vsShell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
                var hr      = vsShell.IsPackageInstalled(FxCopAnalyzersPackageGuid, out int installed);
                if (ErrorHandler.Failed(hr))
                {
                    FatalError.ReportWithoutCrash(Marshal.GetExceptionForHR(hr));

                    // We set installed to ensure we don't go through this again next time a
                    // suggested action is called, and we don't want to continue if the shell
                    // is busted.
                    _installStatus = LiveCodeAnalysisInstallStatus.Installed;
                }
                else
                {
                    _installStatus = installed != 0 ? LiveCodeAnalysisInstallStatus.Installed : LiveCodeAnalysisInstallStatus.NotInstalled;
                }
            }

            return(_installStatus == LiveCodeAnalysisInstallStatus.Installed);
        }