From b7c32c099e84ff874132c623e5638f4ec073d4ad Mon Sep 17 00:00:00 2001 From: Heejae Chang Date: Fri, 8 Mar 2019 14:15:39 -0800 Subject: [PATCH] support feature flag service in IExperimentationService (#33964) * support feature flag service in IExperimentationService this will let us to create private ring of specific groups for new features until it is ready for bigger group. once feature is ready for bigger group, this service can support VS experiment flight service which will let us to enable new features for bigger group. once we are confident on the feature, we will enable it for general public * remove extra blank line --- .../VisualStudioExperimentationService.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/VisualStudio/Core/Def/Experimentation/VisualStudioExperimentationService.cs b/src/VisualStudio/Core/Def/Experimentation/VisualStudioExperimentationService.cs index 0db9d51490f..370ef27d4e7 100644 --- a/src/VisualStudio/Core/Def/Experimentation/VisualStudioExperimentationService.cs +++ b/src/VisualStudio/Core/Def/Experimentation/VisualStudioExperimentationService.cs @@ -17,6 +17,7 @@ internal class VisualStudioExperimentationService : ForegroundThreadAffinitizedO { private readonly object _experimentationServiceOpt; private readonly MethodInfo _isCachedFlightEnabledInfo; + private readonly IVsFeatureFlags _featureFlags; [ImportingConstructor] [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] @@ -25,11 +26,13 @@ public VisualStudioExperimentationService(IThreadingContext threadingContext, SV { object experimentationServiceOpt = null; MethodInfo isCachedFlightEnabledInfo = null; + IVsFeatureFlags featureFlags = null; threadingContext.JoinableTaskFactory.Run(async () => { try { + featureFlags = (IVsFeatureFlags)await ((IAsyncServiceProvider)serviceProvider).GetServiceAsync(typeof(SVsFeatureFlags)).ConfigureAwait(false); experimentationServiceOpt = await ((IAsyncServiceProvider)serviceProvider).GetServiceAsync(typeof(SVsExperimentationService)).ConfigureAwait(false); if (experimentationServiceOpt != null) { @@ -42,6 +45,7 @@ public VisualStudioExperimentationService(IThreadingContext threadingContext, SV } }); + _featureFlags = featureFlags; _experimentationServiceOpt = experimentationServiceOpt; _isCachedFlightEnabledInfo = isCachedFlightEnabledInfo; } @@ -51,6 +55,20 @@ public bool IsExperimentEnabled(string experimentName) ThisCanBeCalledOnAnyThread(); if (_isCachedFlightEnabledInfo != null) { + try + { + var enabled = _featureFlags.IsFeatureEnabled(experimentName, defaultValue: false); + if (enabled) + { + return enabled; + } + } + catch + { + // featureFlags can throw if given name is in incorrect format which can happen for us + // since we use this for experimentation service as well + } + try { return (bool)_isCachedFlightEnabledInfo.Invoke(_experimentationServiceOpt, new object[] { experimentName }); -- GitLab