internal static void ApplyConfiguration(this Feature feature, IFeatureSettings featureSettings) { if (featureSettings.Configuration is BaseFeatureConfiguration baseFeatureConfiguration) { baseFeatureConfiguration?.Apply(featureSettings, feature); } }
internal override void Apply(IFeatureSettings featureSettings, Feature feature) { if (featureSettings is IFeatureWithValueSettings <bool> fBool) { if (featureSettings.Configuration is ITimeWindowFeatureConfiguration <bool> gfcBool) { feature.ConfigurationType = ConfigurationTypes.TimeWindow; feature.TimeWindowFeatures = gfcBool.TimeWindows .Select(g => new DatabaseTimeWindowFeature { StartDate = g.StartDate, EndDate = g.EndDate, BooleanValue = g.Value }) .Concat(new[] { new DatabaseTimeWindowFeature { StartDate = null, EndDate = null, BooleanValue = fBool.Value } }) .ToList(); } } if (featureSettings is IFeatureWithValueSettings <int> fInt) { if (featureSettings.Configuration is ITimeWindowFeatureConfiguration <int> gfcInt) { feature.ConfigurationType = ConfigurationTypes.TimeWindow; feature.TimeWindowFeatures = gfcInt.TimeWindows .Select(g => new DatabaseTimeWindowFeature { StartDate = g.StartDate, EndDate = g.EndDate, IntValue = g.Value }) .Concat(new[] { new DatabaseTimeWindowFeature { StartDate = null, EndDate = null, IntValue = fInt.Value } }) .ToList(); } } if (featureSettings is IFeatureWithValueSettings <decimal> fDecimal) { if (featureSettings.Configuration is ITimeWindowFeatureConfiguration <decimal> gfcDecimal) { feature.ConfigurationType = ConfigurationTypes.TimeWindow; feature.TimeWindowFeatures = gfcDecimal.TimeWindows .Select(g => new DatabaseTimeWindowFeature { StartDate = g.StartDate, EndDate = g.EndDate, DecimalValue = g.Value }) .Concat(new[] { new DatabaseTimeWindowFeature { StartDate = null, EndDate = null, DecimalValue = fDecimal.Value } }) .ToList(); } } if (featureSettings is IFeatureWithValueSettings <string> fString) { if (featureSettings.Configuration is ITimeWindowFeatureConfiguration <string> gfcString) { feature.ConfigurationType = ConfigurationTypes.TimeWindow; feature.TimeWindowFeatures = gfcString.TimeWindows .Select(g => new DatabaseTimeWindowFeature { StartDate = g.StartDate, EndDate = g.EndDate, StringValue = g.Value }) .Concat(new[] { new DatabaseTimeWindowFeature { StartDate = null, EndDate = null, StringValue = fString.Value } }) .ToList(); } } }
internal override void Apply(IFeatureSettings featureSettings, Feature feature) { if (featureSettings is IFeatureWithValueSettings <bool> fBool) { if (featureSettings.Configuration is IGroupFeatureConfiguration <bool> gfcBool) { feature.ConfigurationType = ConfigurationTypes.Group; feature.GroupFeatures = gfcBool.Groups .Select(g => new DatabaseGroupFeature { Group = g.Group, BooleanValue = g.Value }) .Concat(new[] { new DatabaseGroupFeature { Group = null, BooleanValue = fBool.Value } }) .ToList(); } } if (featureSettings is IFeatureWithValueSettings <int> fInt) { if (featureSettings.Configuration is IGroupFeatureConfiguration <int> gfcInt) { feature.ConfigurationType = ConfigurationTypes.Group; feature.GroupFeatures = gfcInt.Groups .Select(g => new DatabaseGroupFeature { Group = g.Group, IntValue = g.Value }) .Concat(new[] { new DatabaseGroupFeature { Group = null, IntValue = fInt.Value } }) .ToList(); } } if (featureSettings is IFeatureWithValueSettings <decimal> fDecimal) { if (featureSettings.Configuration is IGroupFeatureConfiguration <decimal> gfcDecimal) { feature.ConfigurationType = ConfigurationTypes.Group; feature.GroupFeatures = gfcDecimal.Groups .Select(g => new DatabaseGroupFeature { Group = g.Group, DecimalValue = g.Value }) .Concat(new[] { new DatabaseGroupFeature { Group = null, DecimalValue = fDecimal.Value } }) .ToList(); } } if (featureSettings is IFeatureWithValueSettings <string> fString) { if (featureSettings.Configuration is IGroupFeatureConfiguration <string> gfcString) { feature.ConfigurationType = ConfigurationTypes.Group; feature.GroupFeatures = gfcString.Groups .Select(g => new DatabaseGroupFeature { Group = g.Group, StringValue = g.Value }) .Concat(new[] { new DatabaseGroupFeature { Group = null, StringValue = fString.Value } }) .ToList(); } } }
private async Task <bool> IsEnabledAsync <TContext>(string feature, TContext appContext, bool useAppContext) { foreach (ISessionManager sessionManager in _sessionManagers) { if (await sessionManager.TryGetAsync(feature, out bool cachedEnabled).ConfigureAwait(false)) { return(cachedEnabled); } } bool enabled = false; IFeatureSettings settings = _settingsProvider.TryGetFeatureSettings(feature); if (settings != null) { // // Check if feature is always on // If it is, result is true, goto: cache if (settings.EnabledFor.Any(featureFilter => string.Equals(featureFilter.Name, "AlwaysOn", StringComparison.OrdinalIgnoreCase))) { enabled = true; } else { // // For all enabling filters listed in the feature's state calculate if they return true // If any executed filters return true, return true foreach (IFeatureFilterSettings featureFilterSettings in settings.EnabledFor) { IFeatureFilterMetadata filter = GetFeatureFilterMetadata(featureFilterSettings.Name); if (filter == null) { _logger.LogWarning($"Feature filter '{featureFilterSettings.Name}' specified for feature '{feature}' was not found."); continue; } var context = new FeatureFilterEvaluationContext() { FeatureName = feature, Parameters = featureFilterSettings.Parameters }; // // IContextualFeatureFilter if (useAppContext) { ContextualFeatureFilterEvaluator contextualFilter = GetContextualFeatureFilter(featureFilterSettings.Name, typeof(TContext)); if (contextualFilter != null && await contextualFilter.EvaluateAsync(context, appContext).ConfigureAwait(false)) { enabled = true; break; } } // // IFeatureFilter if (filter is IFeatureFilter featureFilter && await featureFilter.EvaluateAsync(context).ConfigureAwait(false)) { enabled = true; break; } } } } foreach (ISessionManager sessionManager in _sessionManagers) { await sessionManager.SetAsync(feature, enabled).ConfigureAwait(false); } return(enabled); }
public bool IsEnabled(string feature) { foreach (ISessionManager sessionManager in _sessionManagers) { if (sessionManager.TryGet(feature, out bool cachedEnabled)) { return(cachedEnabled); } } bool enabled = false; IFeatureSettings settings = _settingsProvider.TryGetFeatureSettings(feature); if (settings != null) { // // Check if feature is always on // If it is, result is true, goto: cache if (settings.EnabledFor.Any(featureFilter => string.Equals(featureFilter.Name, "AlwaysOn", StringComparison.OrdinalIgnoreCase))) { enabled = true; } else { // // For all enabling filters listed in the feature's state calculate if they return true // If any executed filters return true, return true foreach (IFeatureFilterSettings featureFilterSettings in settings.EnabledFor) { IFeatureFilter filter = GetFeatureFilter(featureFilterSettings.Name); if (filter == null) { _logger.LogWarning($"Feature filter '{featureFilterSettings.Name}' specified for feature '{feature}' was not found."); continue; } var context = new FeatureFilterEvaluationContext() { FeatureName = feature, Parameters = featureFilterSettings.Parameters }; if (filter.Evaluate(context)) { enabled = true; break; } } } } foreach (ISessionManager sessionManager in _sessionManagers) { sessionManager.Set(feature, enabled); } return(enabled); }
internal abstract void Apply(IFeatureSettings featureSettings, Feature feature);