Ejemplo n.º 1
0
        private bool CheckIsEnabled(string toggleName, UnleashContext context, bool defaultSetting)
        {
            var featureToggle = GetToggle(toggleName);

            bool enabled = false;

            if (featureToggle == null)
            {
                enabled = defaultSetting;
            }
            else if (!featureToggle.Enabled)
            {
                // Overall false
                enabled = false;
            }
            else if (featureToggle.Strategies.Count == 0)
            {
                enabled = true;
            }
            else
            {
                var enhancedContext = context.ApplyStaticFields(settings);
                enabled = featureToggle.Strategies.Any(s => GetStrategyOrUnknown(s.Name).IsEnabled(s.Parameters, enhancedContext, s.Constraints));
            }

            RegisterCount(toggleName, enabled);
            return(enabled);
        }
Ejemplo n.º 2
0
        private bool CheckIsEnabled(string toggleName, UnleashContext context, bool defaultSetting)
        {
            var featureToggle = services.ToggleCollection.Instance.GetToggleByName(toggleName);

            bool enabled = false;

            if (featureToggle == null)
            {
                enabled = defaultSetting;
            }
            else if (!featureToggle.Enabled)
            {
                // Overall false
                enabled = false;
            }
            else
            {
                for (var i = 0; i < featureToggle.Strategies.Count; i++)
                {
                    var toggleStrategy = featureToggle.Strategies[i];
                    var strategy       = GetStrategyOrUnknown(toggleStrategy.Name);

                    if (!strategy.IsEnabled(toggleStrategy.Parameters, context))
                    {
                        continue;
                    }

                    enabled = true;
                    break;
                }
            }

            RegisterCount(toggleName, enabled);
            return(enabled);
        }
Ejemplo n.º 3
0
 public Builder(UnleashContext context)
 {
     appName       = context.AppName;
     environment   = context.Environment;
     userId        = context.UserId;
     sessionId     = context.SessionId;
     remoteAddress = context.RemoteAddress;
     properties    = context.Properties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
 }
Ejemplo n.º 4
0
        private Variant GetVariant(string toggleName, UnleashContext context, Variant defaultValue)
        {
            var toggle = GetToggle(toggleName);

            var enabled = CheckIsEnabled(toggleName, context, false);
            var variant = enabled ? VariantUtils.SelectVariant(toggle, context, defaultValue) : defaultValue;

            RegisterVariant(toggleName, variant);
            return(variant);
        }
 public DefaultUnleashContextProvider(UnleashContext context = null)
 {
     Context = context ?? new UnleashContext
     {
         UserId        = string.Empty,
         SessionId     = string.Empty,
         RemoteAddress = string.Empty,
         Properties    = new Dictionary <string, string>(0),
     };
 }
Ejemplo n.º 6
0
 public bool IsEnabled(string toggleName, UnleashContext context, bool defaultSetting)
 {
     return(CheckIsEnabled(toggleName, context, defaultSetting));
 }
Ejemplo n.º 7
0
 public bool IsEnabled(string toggleName, UnleashContext context)
 {
     return(IsEnabled(toggleName, context, false));
 }