private TriState EvaluateSpecifications(RuleAgenda <T, V> agenda, bool execute) { var match = TriState.False; foreach (T specification in agenda.Specifications) { RuleBase <T, V>[] rules; var registered = _rules.TryGetValue(specification.RuleIndex, out rules); var facts = (V)agenda.Facts; if (!registered) { continue; } var evaluation = EvaluateRules(specification, facts, rules, execute, agenda.RuleChaining); switch (agenda.SpecificationChaining) { case ChainType.All: if (evaluation != TriState.False) { specification.Successful = evaluation; match = evaluation; } else { return(TriState.False); } break; case ChainType.Any: if (evaluation != TriState.False) { specification.Successful = evaluation; match = evaluation; } break; case ChainType.First: if (evaluation != TriState.False) { specification.Successful = evaluation; return(evaluation); } break; } } return(match); }
public bool Resolve(RuleAgenda <T, V> agenda) { var resolved = false; foreach (T specification in agenda.Specifications) { if (specification.Successful == TriState.True) { var modified = ResolveFor(specification, (V)agenda.Facts); if (modified) { resolved = true; } } } return(resolved); }
public bool Evaluate(RuleAgenda <T, V> agenda) { return(EvaluateSpecifications(agenda, false).ToBool()); }