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); }
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); }
public bool?IsEnabled(Feature.Name feature) { if (_defaultSection == null) { return(null); } return(_defaultSection.FeaturesEnabled); }
/// <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); }
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)); }
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); }
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")); }
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(); }
public static bool?IsEnabled(Feature.Name name) { return(typeof(T).Name == name.Value ? true : (bool?)null); }
/// <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); }
/// <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); }
public bool?Behaviour(Feature.Name name) { return(this._enabled); }
public bool?IsEnabled(Feature.Name feature) { return(Features(feature).GetValueOrDefault(Default(feature).GetValueOrDefault())); }
/// <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); }
/// <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); }