public bool ParserConstant(string value) { var a = FeatureFlagEvaluatorUtils.Parse(value); Assert.IsInstanceOf <ConstantFeatureFlagStateEvaluator>(a); return(a.Evaluate(null) == FeatureFlagState.Active); }
private void OnZookeeperEntryChanged(string path, string data) { var featureKey = GetKeyForPath(path); if (featureKey != null) { localView[featureKey] = new LocalViewItem { Definition = data, Evaluator = FeatureFlagEvaluatorUtils.Parse(featureKey, data) }; } }
public void SetRule(string store, string key, string rule) { var featureStore = FeatureStoreFactory.GetFeatureStore(store); var def = featureStore.GetFeatureFlagDefinition(key); var p = FeatureFlagEvaluatorUtils.Parse(key, def.Definition); var dynamicEvaluator = p as DynamicFeatureFlagStateEvaluator ?? new DynamicFeatureFlagStateEvaluator(key, new FeatureRulesDefinition()); dynamicEvaluator.Rules.ActiveExpression = rule; featureStore.SetFeatureFlagDefinition(new FeatureFlagDefinition { Name = key, Definition = FeatureFlagEvaluatorUtils.SerializeRules(dynamicEvaluator.Rules) }); }
public void ComplexValue() { var value = @" { 'contextualRules': [ { 'rule': 'Or', 'rules': [ { 'rule': 'Schedule', 'from': '2016-11-28T12:00:00', 'to': '2016-11-28T14:00:00' }, { 'rule': 'Schedule', 'from': '2016-11-28T18:00:00', 'to': '2016-11-28T20:00:00' }, ] }, { 'rule': 'Or', 'rules': [ { 'rule': 'UserSelection', 'uid': 'DF767C54-AB7F-4158-ADBC-56C38B4E7831', }, { 'rule': 'UserSelection', 'ratio': '0.05' }, ] } ] } "; var a = FeatureFlagEvaluatorUtils.Parse(value); Assert.IsInstanceOf <DynamicFeatureFlagStateEvaluator>(a); var ev = (DynamicFeatureFlagStateEvaluator)a; Assert.AreEqual(2, ev.Rules.ContextualRules.Length); Assert.IsInstanceOf <OrRule>(ev.Rules.ContextualRules[0]); Assert.AreEqual(2, ((OrRule)ev.Rules.ContextualRules[0]).Rules.Length); Assert.IsInstanceOf <ScheduleRule>(((OrRule)ev.Rules.ContextualRules[0]).Rules[0]); Assert.IsInstanceOf <ScheduleRule>(((OrRule)ev.Rules.ContextualRules[0]).Rules[1]); Assert.IsInstanceOf <OrRule>(ev.Rules.ContextualRules[1]); Assert.AreEqual(2, ((OrRule)ev.Rules.ContextualRules[1]).Rules.Length); Assert.IsInstanceOf <UserSelectionRule>(((OrRule)ev.Rules.ContextualRules[1]).Rules[0]); Assert.IsInstanceOf <UserSelectionRule>(((OrRule)ev.Rules.ContextualRules[1]).Rules[1]); }
public void SetFeatureFlagDefinition(FeatureFlagDefinition featureFlagDefinition) { if (zooKeeper.getState() == Z.ZooKeeper.States.CONNECTED || zooKeeper.getState() == Z.ZooKeeper.States.CONNECTING) { WriteKey(featureFlagDefinition.Name, featureFlagDefinition.Definition).Wait(); } else { localView[featureFlagDefinition.Name] = new LocalViewItem { Definition = featureFlagDefinition.Definition, Evaluator = FeatureFlagEvaluatorUtils.Parse(featureFlagDefinition.Name, featureFlagDefinition.Definition) } }; }
public void Dectivate(string store, string key) { var featureStore = FeatureStoreFactory.GetFeatureStore(store); var def = featureStore.GetFeatureFlagDefinition(key); var p = FeatureFlagEvaluatorUtils.Parse(key, def.Definition); var dynamicEvaluator = p as DynamicFeatureFlagStateEvaluator; if (dynamicEvaluator != null) { dynamicEvaluator.Rules.OverrideValue = false; featureStore.SetFeatureFlagDefinition(new FeatureFlagDefinition { Name = key, Definition = FeatureFlagEvaluatorUtils.SerializeRules(dynamicEvaluator.Rules) }); } else { featureStore.SetFeatureFlagDefinition(new FeatureFlagDefinition { Name = key, Definition = "false" }); } }
public async Task <IActionResult> StoreIndex(string store) { var featureStore = FeatureStoreFactory.GetFeatureStore(store); var model = new IndexViewModel { Features = featureStore.GetAllFeatures() .Select( x => { var definition = featureStore.GetFeatureFlagDefinition(x.Name); var p = FeatureFlagEvaluatorUtils.Parse(x.Name, definition.Definition); var dynamicEvaluator = p as DynamicFeatureFlagStateEvaluator; if (dynamicEvaluator != null) { return(new FeatureFlagsViewModel { Key = x.Name, IsDynamic = true, IsActive = dynamicEvaluator.Rules.OverrideValue.GetValueOrDefault(true), Definition = dynamicEvaluator.Rules.ActiveExpression }); } else { return new FeatureFlagsViewModel { Key = x.Name, IsDynamic = false, IsActive = x.GetState(null) == FeatureFlagState.Active } }; } ).OrderBy(x => x.Key).ToList(), ActiveNodes = await(featureStore as IWatchdog)?.GetActiveNodes(), AllStores = await FeatureStoreFactory.GetStores() }; return(View(model)); }
public FeatureFlagState GetFeatureState(string featureKey, FeatureContext featureContext) { var v = GetFeatureFlagDefinition(featureKey)?.Definition; return(FeatureFlagEvaluatorUtils.Parse(featureKey, v).Evaluate(featureContext)); }