public Option <ConfigurationValue> GetValue(GetContextValue fullContext) { foreach (var rule in _rules) { var contextValue = rule.GetValue(fullContext); if (contextValue.IsSome) { return(contextValue); } } return(None); }
public static GetContextValue Memoize(GetContextValue context) { var cache = new Dictionary <string, Option <JsonValue> >(); return(key => { if (!cache.ContainsKey(key)) { cache[key] = context(key); } return cache[key]; }); }
public static GetRuleValue GetRulesEvaluator(IdentityHashSet identities, GetLoadedContextByIdentityType contextByIdentity, GetRule getRule) { var identityTypes = identities.Select(x => x.Type).ToArray(); var flattenContext = ContextHelpers.FlattenLoadedContext(contextByIdentity); GetRuleValue getRuleValue = null; GetContextValue recursiveContext = key => { if (key.StartsWith("@@key:")) { key = key.Replace("@@key:", "keys."); } if (!key.StartsWith("keys.")) { return(Option <JsonValue> .None); } var path = new ConfigurationPath(key.Split('.')[1]); return(getRuleValue(path).Map(x => x.Value)); }; var context = ContextHelpers.Merge(flattenContext, recursiveContext); getRuleValue = Memoize(path => { try { foreach (var identity in identityTypes) { var fixedResult = ContextHelpers.GetFixedConfigurationContext(context, identity)(path); if (fixedResult.IsSome) { return(fixedResult); } } return(getRule(path).Bind(x => x.GetValue(context))); } catch (Exception e) { return(ConfigurationValue.Error(e)); } }); return(getRuleValue); }
public void ParseLink_GetLinkValue() { // Arrange const string ORIGINAL_KEY = "some_key"; var parser = Engine.Core.Rules.Utils.KeyAliasParser; string requestedContext = null; var getContextValue = new GetContextValue(key => { requestedContext = key; return(None); }); // Act var result = parser.Parse(ORIGINAL_KEY).GetValue(getContextValue); // Assert Assert.Equal(result, None); Assert.Equal(requestedContext, $"keys.{ORIGINAL_KEY}"); }
public Option <ConfigurationValue> GetValue(GetContextValue fullContext) { return(_l.GetValue(fullContext).IfNone(() => _r.GetValue(fullContext))); }
public static GetContextValue Merge(GetContextValue a, GetContextValue b) { return(key => a(key).IfNone(() => b(key))); }
internal static GetContextFixedConfigurationValue GetFixedConfigurationContext(GetContextValue getContextValue, string identityType) { return(path => getContextValue($"{identityType}.@fixed:{path}") .Select(x => new ConfigurationValue(x))); }
public Option <ConfigurationValue> GetValue(GetContextValue fullContext) => fn(fullContext);
public Option <ConfigurationValue> GetValue(GetContextValue fullContext) { return(_func(fullContext)); }
public static GetContextValue Merge(GetContextValue a, GetContextValue b) { return(key => a(key).Match(x => x, () => b(key))); }