/// <summary> /// For a given Rule and RulePrescription create /// A RuleResult to accept the result of the Rule /// and ensure that the RuleResultId is the same for the Rule, RuleResult and RulePrescription /// </summary> /// <param name="rule"></param> /// <param name="rulePrescription"></param> /// <param name="ruleResult"></param> /// <returns></returns> public static RuleResult UnifyRuleObjects(this Rule rule, IRuleProcessing rulePrescription, RuleResult ruleResult = null) { // Create the Rule, RuleResult and RulePrescription and ensure that the RuleResultId is the same for all if (ruleResult == null) { ruleResult = new RuleResult(rule) { RuleResultId = rulePrescription.Entities.RuleResultId }; } else { ruleResult.RuleResultId = rulePrescription.Entities.RuleResultId; } rule.ReferenceValues.RuleResultId = rulePrescription.Entities.RuleResultId; return(ruleResult); }
public static RulEngStore ProcessAllRulesReducer(RulEngStore previousState, IRuleProcessing prescription) { // Set up a temporary 'Processing' copy of the Store as our Unit of Work var newState = previousState.DeepClone(); // First identify rules for entities that may (not) exist newState = newState.AllExists(prescription as ProcessExistsRule); // Then test for meaningful Values newState = newState.AllHasMeaningfulValue(prescription as ProcessHasMeaningfulValueRule); newState = newState.AllCompare(prescription as ProcessLessThanRule, RuleType.LessThan); newState = newState.AllCompare(prescription as ProcessEqualRule, RuleType.Equal); newState = newState.AllCompare(prescription as ProcessGreaterThanRule, RuleType.GreaterThan); newState = newState.AllCompare(prescription as ProcessRegexMatchRule, RuleType.RegularExpression); newState = newState.AllCollection(prescription as ProcessAndRule, RuleType.And); newState = newState.AllCollection(prescription as ProcessOrRule, RuleType.Or); newState = newState.AllCollection(prescription as ProcessXorRule, RuleType.Xor); return(newState.DeepClone()); }