private static void AnalyzeRules(RuleChainingBehavior behavior, List <RuleState> ruleStates, RuleValidation validation, Tracer tracer) { int count = ruleStates.Count; if (behavior != RuleChainingBehavior.None) { RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[count]; int index = 0; while (index < count) { ruleSymbols[index] = AnalyzeRule(behavior, ruleStates[index].Rule, validation, tracer); index++; } for (index = 0; index < count; index++) { RuleState state = ruleStates[index]; if (ruleSymbols[index].thenSideEffects != null) { state.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].thenSideEffects, ruleSymbols); if ((state.ThenActionsActiveRules != null) && (tracer != null)) { tracer.TraceThenTriggers(state.Rule.Name, state.ThenActionsActiveRules, ruleStates); } } if (ruleSymbols[index].elseSideEffects != null) { state.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].elseSideEffects, ruleSymbols); if ((state.ElseActionsActiveRules != null) && (tracer != null)) { tracer.TraceElseTriggers(state.Rule.Name, state.ElseActionsActiveRules, ruleStates); } } } } }
private static RuleSymbolInfo AnalyzeRule(RuleChainingBehavior behavior, Rule rule, RuleValidation validator, Tracer tracer) { RuleSymbolInfo info = new RuleSymbolInfo(); if (rule.Condition != null) { info.conditionDependencies = rule.Condition.GetDependencies(validator); if ((info.conditionDependencies != null) && (tracer != null)) { tracer.TraceConditionSymbols(rule.Name, info.conditionDependencies); } } if (rule.thenActions != null) { info.thenSideEffects = GetActionSideEffects(behavior, rule.thenActions, validator); if ((info.thenSideEffects != null) && (tracer != null)) { tracer.TraceThenSymbols(rule.Name, info.thenSideEffects); } } if (rule.elseActions != null) { info.elseSideEffects = GetActionSideEffects(behavior, rule.elseActions, validator); if ((info.elseSideEffects != null) && (tracer != null)) { tracer.TraceElseSymbols(rule.Name, info.elseSideEffects); } } return(info); }
internal static IList <RuleState> Preprocess(RuleChainingBehavior behavior, ICollection <Rule> rules, RuleValidation validation, Tracer tracer) { List <RuleState> ruleStates = new List <RuleState>(rules.Count); foreach (Rule rule in rules) { if (rule.Active) { ruleStates.Add(new RuleState(rule)); } } ruleStates.Sort(); AnalyzeRules(behavior, ruleStates, validation, tracer); return(ruleStates); }
private static void AnalyzeRules(RuleChainingBehavior behavior, List <RuleState> ruleStates, RuleValidation validation, Tracer tracer) { int i; int numRules = ruleStates.Count; // if no chaining is required, then nothing to do if (behavior == RuleChainingBehavior.None) { return; } // Analyze all the rules and collect all the dependencies & side-effects RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[numRules]; for (i = 0; i < numRules; ++i) { ruleSymbols[i] = AnalyzeRule(behavior, ruleStates[i].Rule, validation, tracer); } for (i = 0; i < numRules; ++i) { RuleState currentRuleState = ruleStates[i]; if (ruleSymbols[i].thenSideEffects != null) { currentRuleState.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].thenSideEffects, ruleSymbols); if ((currentRuleState.ThenActionsActiveRules != null) && (tracer != null)) { tracer.TraceThenTriggers(currentRuleState.Rule.Name, currentRuleState.ThenActionsActiveRules, ruleStates); } } if (ruleSymbols[i].elseSideEffects != null) { currentRuleState.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].elseSideEffects, ruleSymbols); if ((currentRuleState.ElseActionsActiveRules != null) && (tracer != null)) { tracer.TraceElseTriggers(currentRuleState.Rule.Name, currentRuleState.ElseActionsActiveRules, ruleStates); } } } }
private static ICollection <string> GetActionSideEffects(RuleChainingBehavior behavior, IList <RuleAction> actions, RuleValidation validation) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); foreach (RuleAction action in actions) { if ((behavior == RuleChainingBehavior.Full) || ((behavior == RuleChainingBehavior.UpdateOnly) && (action is RuleUpdateAction))) { ICollection <string> sideEffects = action.GetSideEffects(validation); if (sideEffects != null) { foreach (string str in sideEffects) { dictionary[str] = null; } } } } return(dictionary.Keys); }
internal static IList <RuleState> Preprocess(RuleChainingBehavior behavior, ICollection <Rule> rules, RuleValidation validation, Tracer tracer) { // start by taking the active rules and make them into a list sorted by priority List <RuleState> orderedRules = new List <RuleState>(rules.Count); foreach (Rule r in rules) { if (r.Active) { orderedRules.Add(new RuleState(r)); } } orderedRules.Sort(); // Analyze the rules to match side-effects with dependencies. // Note that the RuleSet needs to have been validated prior to this. AnalyzeRules(behavior, orderedRules, validation, tracer); // return the sorted list of rules return(orderedRules); }
private static ICollection <string> GetActionSideEffects(RuleChainingBehavior behavior, IList <RuleAction> actions, RuleValidation validation) { // Man, I wish there were a Set<T> class... Dictionary <string, object> symbols = new Dictionary <string, object>(); foreach (RuleAction action in actions) { if ((behavior == RuleChainingBehavior.Full) || ((behavior == RuleChainingBehavior.UpdateOnly) && (action is RuleUpdateAction))) { ICollection <string> sideEffects = action.GetSideEffects(validation); if (sideEffects != null) { foreach (string symbol in sideEffects) { symbols[symbol] = null; } } } } return(symbols.Keys); }
private static ICollection<string> GetActionSideEffects(RuleChainingBehavior behavior, IList<RuleAction> actions, RuleValidation validation) { // Man, I wish there were a Set<T> class... Dictionary<string, object> symbols = new Dictionary<string, object>(); foreach (RuleAction action in actions) { if ((behavior == RuleChainingBehavior.Full) || ((behavior == RuleChainingBehavior.UpdateOnly) && (action is RuleUpdateAction))) { ICollection<string> sideEffects = action.GetSideEffects(validation); if (sideEffects != null) { foreach (string symbol in sideEffects) symbols[symbol] = null; } } } return symbols.Keys; }
private static RuleSymbolInfo AnalyzeRule(RuleChainingBehavior behavior, Rule rule, RuleValidation validator, Tracer tracer) { RuleSymbolInfo rsi = new RuleSymbolInfo(); if (rule.Condition != null) { rsi.conditionDependencies = rule.Condition.GetDependencies(validator); if ((rsi.conditionDependencies != null) && (tracer != null)) tracer.TraceConditionSymbols(rule.Name, rsi.conditionDependencies); } if (rule.thenActions != null) { rsi.thenSideEffects = GetActionSideEffects(behavior, rule.thenActions, validator); if ((rsi.thenSideEffects != null) && (tracer != null)) tracer.TraceThenSymbols(rule.Name, rsi.thenSideEffects); } if (rule.elseActions != null) { rsi.elseSideEffects = GetActionSideEffects(behavior, rule.elseActions, validator); if ((rsi.elseSideEffects != null) && (tracer != null)) tracer.TraceElseSymbols(rule.Name, rsi.elseSideEffects); } return rsi; }
private static void AnalyzeRules(RuleChainingBehavior behavior, List<RuleState> ruleStates, RuleValidation validation, Tracer tracer) { int i; int numRules = ruleStates.Count; // if no chaining is required, then nothing to do if (behavior == RuleChainingBehavior.None) return; // Analyze all the rules and collect all the dependencies & side-effects RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[numRules]; for (i = 0; i < numRules; ++i) ruleSymbols[i] = AnalyzeRule(behavior, ruleStates[i].Rule, validation, tracer); for (i = 0; i < numRules; ++i) { RuleState currentRuleState = ruleStates[i]; if (ruleSymbols[i].thenSideEffects != null) { currentRuleState.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].thenSideEffects, ruleSymbols); if ((currentRuleState.ThenActionsActiveRules != null) && (tracer != null)) tracer.TraceThenTriggers(currentRuleState.Rule.Name, currentRuleState.ThenActionsActiveRules, ruleStates); } if (ruleSymbols[i].elseSideEffects != null) { currentRuleState.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].elseSideEffects, ruleSymbols); if ((currentRuleState.ElseActionsActiveRules != null) && (tracer != null)) tracer.TraceElseTriggers(currentRuleState.Rule.Name, currentRuleState.ElseActionsActiveRules, ruleStates); } } }
internal static IList<RuleState> Preprocess(RuleChainingBehavior behavior, ICollection<Rule> rules, RuleValidation validation, Tracer tracer) { // start by taking the active rules and make them into a list sorted by priority List<RuleState> orderedRules = new List<RuleState>(rules.Count); foreach (Rule r in rules) { if (r.Active) orderedRules.Add(new RuleState(r)); } orderedRules.Sort(); // Analyze the rules to match side-effects with dependencies. // Note that the RuleSet needs to have been validated prior to this. AnalyzeRules(behavior, orderedRules, validation, tracer); // return the sorted list of rules return orderedRules; }
public RuleSet() { this.behavior = RuleChainingBehavior.Full; this.syncLock = new object(); this.rules = new List <Rule>(); }
internal static IList<RuleState> Preprocess(RuleChainingBehavior behavior, ICollection<Rule> rules, RuleValidation validation, Tracer tracer) { List<RuleState> ruleStates = new List<RuleState>(rules.Count); foreach (Rule rule in rules) { if (rule.Active) { ruleStates.Add(new RuleState(rule)); } } ruleStates.Sort(); AnalyzeRules(behavior, ruleStates, validation, tracer); return ruleStates; }
private static ICollection<string> GetActionSideEffects(RuleChainingBehavior behavior, IList<RuleAction> actions, RuleValidation validation) { Dictionary<string, object> dictionary = new Dictionary<string, object>(); foreach (RuleAction action in actions) { if ((behavior == RuleChainingBehavior.Full) || ((behavior == RuleChainingBehavior.UpdateOnly) && (action is RuleUpdateAction))) { ICollection<string> sideEffects = action.GetSideEffects(validation); if (sideEffects != null) { foreach (string str in sideEffects) { dictionary[str] = null; } } } } return dictionary.Keys; }
private static void AnalyzeRules(RuleChainingBehavior behavior, List<RuleState> ruleStates, RuleValidation validation, Tracer tracer) { int count = ruleStates.Count; if (behavior != RuleChainingBehavior.None) { RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[count]; int index = 0; while (index < count) { ruleSymbols[index] = AnalyzeRule(behavior, ruleStates[index].Rule, validation, tracer); index++; } for (index = 0; index < count; index++) { RuleState state = ruleStates[index]; if (ruleSymbols[index].thenSideEffects != null) { state.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].thenSideEffects, ruleSymbols); if ((state.ThenActionsActiveRules != null) && (tracer != null)) { tracer.TraceThenTriggers(state.Rule.Name, state.ThenActionsActiveRules, ruleStates); } } if (ruleSymbols[index].elseSideEffects != null) { state.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].elseSideEffects, ruleSymbols); if ((state.ElseActionsActiveRules != null) && (tracer != null)) { tracer.TraceElseTriggers(state.Rule.Name, state.ElseActionsActiveRules, ruleStates); } } } } }