コード例 #1
0
        private void OpenNuGetPackageManagerHyperlink()
        {
            Debug.Assert(_packageInstallerService != null);
            Debug.Assert(_packageInstallerService.CanShowManagePackagesDialog());

            _packageInstallerService.ShowManagePackagesDialog(AnalyzerNuGetPackageId);
            FxCopAnalyzersInstallLogger.Log(nameof(AnalyzerNuGetPackageId));
        }
コード例 #2
0
        private void ShowInfoBarIfNecessary()
        {
            // Only check for whether we should show an info bar once per session.
            _infoBarChecked = true;

            // We determine if the infobar has been displayed in the past 24 hours.
            // If it hasn't been displayed, then we do so now.
            var lastTimeInfoBarShown = DateTime.FromBinary(_workspace.Options.GetOption(FxCopAnalyzersInstallOptions.LastDateTimeInfoBarShown));
            var utcNow             = DateTime.UtcNow;
            var timeSinceLastShown = utcNow - lastTimeInfoBarShown;

            if (timeSinceLastShown.TotalDays >= 1)
            {
                _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                                  .WithChangedOption(FxCopAnalyzersInstallOptions.LastDateTimeInfoBarShown, utcNow.ToBinary())));
                FxCopAnalyzersInstallLogger.Log("InfoBarShown");

                var infoBarService = _workspace.Services.GetRequiredService <IInfoBarService>();
                infoBarService.ShowInfoBar(
                    ServicesVSResources.Install_Microsoft_recommended_Roslyn_analyzers_which_provide_additional_diagnostics_and_fixes_for_common_API_design_security_performance_and_reliability_issues,
                    GetInfoBarUIItems().ToArray());
            }

            return;

            // Local functions
            IEnumerable <InfoBarUI> GetInfoBarUIItems()
            {
                if (_packageInstallerService?.CanShowManagePackagesDialog() == true)
                {
                    // Open NuGet package manager with FxCopAnalyzers search string
                    yield return(new InfoBarUI(
                                     title: ServicesVSResources.Build_plus_live_analysis_NuGet_package,
                                     kind: InfoBarUI.UIKind.HyperLink,
                                     action: OpenNuGetPackageManagerHyperlink,
                                     closeAfterAction: false));
                }

                // FxCop Analyzers VSIX install link
                yield return(new InfoBarUI(
                                 title: ServicesVSResources.Live_analysis_VSIX_extension,
                                 kind: InfoBarUI.UIKind.HyperLink,
                                 action: OpenVSIXInstallHyperlink,
                                 closeAfterAction: false));

                // Documentation link about FxCopAnalyzers
                yield return(new InfoBarUI(title: ServicesVSResources.Learn_more,
                                           kind: InfoBarUI.UIKind.HyperLink,
                                           action: OpenLearnMoreHyperlink,
                                           closeAfterAction: false));

                // Don't show the InfoBar again link
                yield return(new InfoBarUI(title: ServicesVSResources.Never_show_this_again,
                                           kind: InfoBarUI.UIKind.Button,
                                           action: DoNotShowAgain,
                                           closeAfterAction: true));
            }
        }