private IEnumerable <ICompiledRule> CompileRule(IReteBuilder reteBuilder, IRuleDefinition ruleDefinition) { var rules = new List <ICompiledRule>(); var transformation = new RuleTransformation(); var transformedRule = transformation.Transform(ruleDefinition); var ruleDeclarations = transformedRule.LeftHandSide.Exports.ToList(); var dependencies = transformedRule.DependencyGroup.Dependencies.ToList(); var terminals = reteBuilder.AddRule(transformedRule); foreach (var terminal in terminals) { IRuleFilter filter = CompileFilters(transformedRule, ruleDeclarations, terminal.FactMap); var rightHandSide = transformedRule.RightHandSide; var actions = new List <IRuleAction>(); foreach (var action in rightHandSide.Actions) { var ruleAction = ExpressionCompiler.CompileAction(action, ruleDeclarations, dependencies, terminal.FactMap); actions.Add(ruleAction); } var rule = new CompiledRule(ruleDefinition, ruleDeclarations, actions, filter, terminal.FactMap); BuildRuleNode(rule, terminal); rules.Add(rule); } return(rules); }
private ICompiledRule CompileRule(IReteBuilder reteBuilder, IRuleDefinition ruleDefinition) { var transformation = new RuleTransformation(); var transformedRule = transformation.Transform(ruleDefinition); var ruleDeclarations = transformedRule.LeftHandSide.Declarations.ToList(); var ruleDependencies = transformedRule.DependencyGroup.Dependencies.Select(x => x.Declaration).ToList(); IEnumerable <IRuleDependency> dependencies = CompileDependencies(transformedRule); IEnumerable <ITerminalNode> terminals = reteBuilder.AddRule(transformedRule); IRuleFilter filter = CompileFilters(transformedRule, ruleDeclarations); var rightHandSide = transformedRule.RightHandSide; var actions = new List <IRuleAction>(); foreach (var action in rightHandSide.Actions) { var ruleAction = ExpressionCompiler.CompileAction(action, ruleDeclarations, ruleDependencies); actions.Add(ruleAction); } var rule = new CompiledRule(ruleDefinition, ruleDeclarations, actions, dependencies, filter); BuildRuleNode(rule, terminals); return(rule); }
public BenchmarkRuleAction() { Expression <Action <IContext, string, int, decimal> > expression = (c, s, i, d) => PerformAction(c, s, i, d); var element = Element.Action(expression); var map = IndexMap.CreateMap(element.Imports, element.Imports); _ruleAction = ExpressionCompiler.CompileAction(element, element.Imports.ToList(), new List <DependencyElement>(), map); var compiledRule = new CompiledRule(null, element.Imports, new [] { _ruleAction }, null, map); var tuple = ToTuple("abcd", 4, 1.0m); var activation = new Activation(compiledRule, tuple); _actionContext = new ActionContext(Context.Session, activation, CancellationToken.None); }