Exemplo n.º 1
0
        private void ShowInfoBarIfNecessary()
        {
            // Only check for whether we should show an info bar once per session.
            _infoBarChecked = true;
            if (_experimentationService.IsExperimentEnabled(AnalyzerEnabledFlight))
            {
                AnalyzerABTestLogger.Log(nameof(AnalyzerEnabledFlight));

                // If we got true from the experimentation service, then we're in the treatment
                // group, and the experiment is enabled. 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(AnalyzerABTestOptions.LastDateTimeInfoBarShown));
                var utcNow             = DateTime.UtcNow;
                var timeSinceLastShown = utcNow - lastTimeInfoBarShown;

                if (timeSinceLastShown.TotalDays >= 1)
                {
                    _workspace.Options = _workspace.Options.WithChangedOption(AnalyzerABTestOptions.LastDateTimeInfoBarShown, utcNow.ToBinary());
                    AnalyzerABTestLogger.Log("InfoBarShown");

                    var infoBarService = _workspace.Services.GetRequiredService <IInfoBarService>();
                    infoBarService.ShowInfoBarInGlobalView(
                        ServicesVSResources.Try_the_preview_version_of_our_live_code_analysis_extension_which_provides_more_fixes_for_common_API_design_naming_performance_and_reliability_issues,
                        // Install link
                        new InfoBarUI(title: ServicesVSResources.Learn_more,
                                      kind: InfoBarUI.UIKind.HyperLink,
                                      action: OpenInstallHyperlink),
                        // Don't show the InfoBar again link
                        new InfoBarUI(title: ServicesVSResources.Never_show_this_again,
                                      kind: InfoBarUI.UIKind.Button,
                                      action: DoNotShowAgain));
                }
            }
        }
Exemplo n.º 2
0
        private bool IsCandidate()
        {
            // if this user ever participated in the experiement and then uninstall the vsix, then
            // this user will never be candidate again.
            if (_workspace.Options.GetOption(AnalyzerABTestOptions.ParticipatedInExperiment))
            {
                return(false);
            }

            // Filter for valid A/B test candidates. 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

            // 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(AnalyzerABTestOptions.HasMetCandidacyRequirements);

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

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

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

                    if (usageCount >= 3)
                    {
                        isCandidate = true;
                        options     = options.WithChangedOption(AnalyzerABTestOptions.HasMetCandidacyRequirements, true);
                        AnalyzerABTestLogger.Log(nameof(AnalyzerABTestOptions.HasMetCandidacyRequirements));
                    }

                    _workspace.Options = options;
                }
            }

            return(isCandidate);
        }
Exemplo n.º 3
0
 private void DoNotShowAgain()
 {
     _workspace.Options = _workspace.Options.WithChangedOption(AnalyzerABTestOptions.NeverShowAgain, true);
     AnalyzerABTestLogger.Log(nameof(AnalyzerABTestOptions.NeverShowAgain));
 }
Exemplo n.º 4
0
 private void OpenInstallHyperlink()
 {
     System.Diagnostics.Process.Start(AnalyzerVsixHyperlink);
     AnalyzerABTestLogger.Log(nameof(AnalyzerVsixHyperlink));
 }