/// <summary> /// Can be overrided in a derived class to control how this is implemented. By default, will retrieve a feature and run a foreach with all the activation strategies /// </summary> /// <param name="feature">The feature to evaluate</param> /// <param name="context">Optional context</param> /// <param name="token">Cancellation token</param> /// <returns>Boolean indicating if the feature is considered enabled</returns> protected virtual async Task <bool> IsFeatureEnabledAsyncCore(Feature feature, IFeatureContext context, CancellationToken token) { if (feature == null || !feature.Enabled) { return(false); } if (feature.ActivationStrategies == null || !feature.ActivationStrategies.Any(kv => !string.IsNullOrWhiteSpace(kv.Key))) { return(false); } IStrategyHandler handler = null; foreach (var activationStrategy in feature.ActivationStrategies.Keys) { handler = GetStrategyHandler(activationStrategy); if (handler == null) { return(false); } var isEnabled = await handler.IsEnabledAsync(feature.ActivationStrategies[activationStrategy], context, token).ConfigureAwait(false); if (!isEnabled) { return(false); } } return(true); }
/// <summary> /// Can be overrided in a derived class to control how this is implemented. By default, will retrieve a feature and run a foreach with all the activation strategies /// </summary> /// <param name="feature">The feature to evaluate</param> /// <param name="context">Optional context</param> /// <returns>Boolean indicating if the feature is considered enabled</returns> protected virtual bool IsFeatureEnabledCore(Feature feature, IFeatureContext context) { if (feature == null || !feature.Enabled) { return(false); } if (feature.ActivationStrategies == null || !feature.ActivationStrategies.Any(kv => !string.IsNullOrWhiteSpace(kv.Key))) { return(false); } IStrategyHandler handler = null; foreach (var activationStrategy in feature.ActivationStrategies.Keys) { handler = GetStrategyHandler(activationStrategy); if (handler == null || !handler.IsEnabled(feature.ActivationStrategies[activationStrategy], context)) { return(false); } } return(true); }