コード例 #1
0
        public bool?IsEnabled(Feature.Name feature)
        {
            if (feature == null)
            {
                return(null);
            }

            if (_cache.Count == 0 || DateTime.UtcNow > _cacheTimeout)
            {
                SetupAsync().GetAwaiter().GetResult();
            }

            if (!_cache.ContainsKey(feature.Value))
            {
                return(CreateFeatureFlagInBackground(feature.Value, defaultValue: false));
            }

            var result = _cache[feature.Value];

            if (DateTime.UtcNow > _cacheTimeout)
            {
                ReloadFeaturesInBackgound();
            }


            return(result.Value);
        }
コード例 #2
0
        private bool?Behaviour(Feature.Name name)
        {
            if (HttpContext.Current == null)
            {
                return(null);
            }

            if (name == null || string.IsNullOrWhiteSpace(name.Value))
            {
                return(null);
            }

            if (HttpContext.Current.IsDebuggingEnabled || this._isForced)
            {
                if (HttpContext.Current.Request == null)
                {
                    return(null);
                }

                var cookie = HttpContext.Current.Request.Cookies[name.Value];

                if (cookie == null)
                {
                    return(null);
                }

                return(cookie.Value == "true");
            }

            return(null);
        }
コード例 #3
0
        public bool?IsEnabled(Feature.Name feature)
        {
            if (_defaultSection == null)
            {
                return(null);
            }

            return(_defaultSection.FeaturesEnabled);
        }
コード例 #4
0
ファイル: InMemory.cs プロジェクト: tjuergens/FeatureSwitcher
 /// <summary>
 /// Determines if a feature is enabled by the specified <paramref name="featureName"/>.
 /// </summary>
 /// <returns>
 ///     <c>true</c> if the specified featureName enabled;
 ///     <c>false</c> if the specified featureName is disabled;
 ///     <c>null</c> otherwise.
 /// </returns>
 /// <param name="featureName">Feature name.</param>
 public bool?IsEnabled(Feature.Name featureName)
 {
     if (_enabledTypes.Contains(featureName.Type))
     {
         return(true);
     }
     if (_disabledTypes.Contains(featureName.Type))
     {
         return(false);
     }
     return(null);
 }
コード例 #5
0
        private bool?Ask(Feature.Name name, User user)
        {
            var x = _configurations.Where(f => f.FeatureName == name.Value);

            if (!x.Any())
            {
                return(null);
            }

            return(x.Any(f => f.UseraccountId == user.Id) ||
                   x.Any(f => f.UseraccountId == null && f.Role == user.Role));
        }
コード例 #6
0
        public bool?IsEnabled(Feature.Name feature)
        {
            if (_features == null)
            {
                return(null);
            }

            var featureElement = _features.Features[feature.Value];

            if (featureElement == null)
            {
                return(null);
            }

            return(featureElement.Enabled);
        }
コード例 #7
0
        public void VstsConfig_IsEnabled_creates_missing_feature()
        {
            var clientMock = new Mock <IVstsClient>();

            clientMock.Setup(x => x.GetAsync()).ReturnsAsync(new Dictionary <string, string>
            {
                { "Feature1", "true" }
            });
            clientMock.Setup(x => x.PutAsync("Feature2", "False")).ReturnsAsync(true);


            var sut = new VstsConfig(new VstsSettings(), clientMock.Object);

            sut.SetupAsync().GetAwaiter().GetResult();

            Feature.Name feature2 = new Feature.Name(typeof(Feature2), "Feature2");

            sut.IsEnabled(feature2).Should().BeFalse();

            clientMock.Verify(x => x.PutAsync("Feature2", "False"));
        }
コード例 #8
0
        public void VstsConfig_IsEnabled_returns_value_from_cache()
        {
            var clientMock = new Mock <IVstsClient>();

            clientMock.Setup(x => x.GetAsync()).ReturnsAsync(new Dictionary <string, string>
            {
                { "Feature1", "true" },
                { "Feature2", "false" }
            });


            var sut = new VstsConfig(new VstsSettings(), clientMock.Object);

            sut.SetupAsync().GetAwaiter().GetResult();

            Feature.Name feature1 = new Feature.Name(typeof(Feature1), "Feature1");
            Feature.Name feature2 = new Feature.Name(typeof(Feature2), "Feature2");

            sut.IsEnabled(feature1).Should().BeTrue();
            sut.IsEnabled(feature2).Should().BeFalse();
        }
コード例 #9
0
 public static bool?IsEnabled(Feature.Name name)
 {
     return(typeof(T).Name == name.Value ? true : (bool?)null);
 }
コード例 #10
0
 /// <summary>
 /// Disables any feature.
 /// </summary>
 /// <param name="featureName">The name of the feature.</param>
 /// <returns>always <c>false</c>.</returns>
 public static bool?Disabled(Feature.Name featureName)
 {
     return(false);
 }
コード例 #11
0
 /// <summary>
 /// Enables any feature.
 /// </summary>
 /// <param name="featureName">The name of the feature.</param>
 /// <returns>always <c>true</c>.</returns>
 public static bool?Enabled(Feature.Name featureName)
 {
     return(true);
 }
コード例 #12
0
 public bool?Behaviour(Feature.Name name)
 {
     return(this._enabled);
 }
コード例 #13
0
 public bool?IsEnabled(Feature.Name feature)
 {
     return(Features(feature).GetValueOrDefault(Default(feature).GetValueOrDefault()));
 }
コード例 #14
0
 /// <summary>
 /// Disables the feature only when it's of type <typeparamref name="T"/>.
 /// </summary>
 /// <param name="featureName">The name of the feature.</param>
 /// <returns><c>false</c> if feature is of type <typeparamref name="T"/>, <c>null</c> otherwise.</returns>
 public static bool?Disabled(Feature.Name featureName)
 {
     return(typeof(T) == featureName.Type ? false : (bool?)null);
 }
コード例 #15
0
 /// <summary>
 /// Enables the feature only when it's of type <typeparamref name="T"/>.
 /// </summary>
 /// <param name="featureName">The name of the feature.</param>
 /// <returns><c>true</c> if feature is of type <typeparamref name="T"/>, <c>null</c> otherwise.</returns>
 public static bool?Enabled(Feature.Name featureName)
 {
     return(typeof(T) == featureName.Type ? true : (bool?)null);
 }