コード例 #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));
            }
        }
コード例 #3
0
        private bool IsCandidate(SuggestedAction action)
        {
            // Candidates fill the following critera:
            //     1: Are a Dotnet user (as evidenced by the fact that this code is being run)
            //     2: Have triggered a lightbulb on 3 separate days or if this is a code quality suggested action.

            // If the user hasn't met candidacy conditions, then we check them. Otherwise, proceed
            // to info bar check
            var options     = _workspace.Options;
            var isCandidate = options.GetOption(FxCopAnalyzersInstallOptions.HasMetCandidacyRequirements);

            if (!isCandidate)
            {
                // We store in UTC to avoid any timezone offset weirdness
                var lastTriggeredTimeBinary = options.GetOption(FxCopAnalyzersInstallOptions.LastDateTimeUsedSuggestionAction);
                FxCopAnalyzersInstallLogger.LogCandidacyRequirementsTracking(lastTriggeredTimeBinary);

                var lastTriggeredTime = DateTime.FromBinary(lastTriggeredTimeBinary);
                var currentTime       = DateTime.UtcNow;
                var span = currentTime - lastTriggeredTime;
                if (span.TotalDays >= 1)
                {
                    options = options.WithChangedOption(FxCopAnalyzersInstallOptions.LastDateTimeUsedSuggestionAction, currentTime.ToBinary());

                    var usageCount = options.GetOption(FxCopAnalyzersInstallOptions.UsedSuggestedActionCount);
                    options = options.WithChangedOption(FxCopAnalyzersInstallOptions.UsedSuggestedActionCount, ++usageCount);

                    // Candidate if user has invoked the light bulb 3 times or if this is a code quality suggested action.
                    if (usageCount >= 3 || action.IsForCodeQualityImprovement)
                    {
                        isCandidate = true;
                        options     = options.WithChangedOption(FxCopAnalyzersInstallOptions.HasMetCandidacyRequirements, true);
                        FxCopAnalyzersInstallLogger.Log(nameof(FxCopAnalyzersInstallOptions.HasMetCandidacyRequirements));
                    }

                    _workspace.Options = options;
                }
            }

            return(isCandidate);
        }
コード例 #4
0
        private bool IsVsixInstalled()
        {
            if (_vsixInstallStatus == FxCopAnalyzersInstallStatus.Unknown)
            {
                var vsShell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
                var hr      = vsShell.IsPackageInstalled(FxCopAnalyzersPackageGuid, out var 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.
                    _vsixInstallStatus = FxCopAnalyzersInstallStatus.Installed;
                }
                else
                {
                    _vsixInstallStatus = installed != 0 ? FxCopAnalyzersInstallStatus.Installed : FxCopAnalyzersInstallStatus.NotInstalled;
                    FxCopAnalyzersInstallLogger.LogVsixInstallationStatus(_workspace, _vsixInstallStatus);
                }
            }

            return(_vsixInstallStatus == FxCopAnalyzersInstallStatus.Installed);
        }
コード例 #5
0
 private void DoNotShowAgain()
 {
     _workspace.Options = _workspace.Options.WithChangedOption(FxCopAnalyzersInstallOptions.NeverShowAgain, true);
     FxCopAnalyzersInstallLogger.Log(nameof(FxCopAnalyzersInstallOptions.NeverShowAgain));
 }
コード例 #6
0
 private void OpenLearnMoreHyperlink()
 {
     System.Diagnostics.Process.Start(AnalyzerInstallLearnMoreHyperlink);
     FxCopAnalyzersInstallLogger.Log(nameof(AnalyzerInstallLearnMoreHyperlink));
 }
コード例 #7
0
 private void OpenVSIXInstallHyperlink()
 {
     System.Diagnostics.Process.Start(AnalyzerVsixHyperlink);
     FxCopAnalyzersInstallLogger.Log(nameof(AnalyzerVsixHyperlink));
 }
コード例 #8
0
 private void DoNotShowAgain()
 {
     _workspace.TryApplyChanges(_workspace.CurrentSolution.WithOptions(_workspace.Options
                                                                       .WithChangedOption(FxCopAnalyzersInstallOptions.NeverShowAgain, true)));
     FxCopAnalyzersInstallLogger.Log(nameof(FxCopAnalyzersInstallOptions.NeverShowAgain));
 }