public Dictionary <IRule, bool> RunSingleRule(RuleModelData data, string rule) { if (rule == null) { return(new Dictionary <IRule, bool>()); } return(Run(data, GetRules(rule))); }
public static void Main() { var rr = new RunRules(); var model = new RuleModelData { NumberOfPassengers = 22, NumberOfSeats = 28 }; bool result; result = rr.RunSingleRule(model, "RelaxedRule").AllParsed(); // obviously RelaxedRule could be loaded in via config or data store result = rr.RunSingleRule(model, "GreedRule").AllParsed(); // obviously RelaxedRule could be loaded in via config or data store result = rr.Run(model).AllParsed(); // run all rules var allResults = rr.Run(model); }
public bool Parse(RuleModelData data) { return(data.PercentageFull > PercentHigerThan); }
public Dictionary <IRule, bool> Run(RuleModelData data, IEnumerable <IRule> rules) { return(rules.Select(f => new { Ob = f, Result = f.Parse(data) }) .GroupBy(f => f.Ob) .ToDictionary(f => f.Key, f => f.Select(x => x.Result).First())); }
public Dictionary <IRule, bool> RunAllWithAppend(RuleModelData data, IEnumerable <IRule> rules) { return(Run(data, GetRules().Union(rules))); }
public Dictionary <IRule, bool> Run(RuleModelData data) { return(RunAllWithAppend(data, new IRule[0])); }