public void Invoke(IExecutionContext context, IContext actionContext, Tuple tuple, FactIndexMap tupleFactMap) { var args = new object[_compiledAction.ParameterCount]; args[0] = actionContext; int index = tuple.Count - 1; foreach (var fact in tuple.Facts) { var mappedIndex = _actionFactMap.Map(tupleFactMap.Map(index)); FactIndexMap.SetElementAt(ref args, mappedIndex, 1, fact.Object); index--; } try { _compiledAction.Delegate.Invoke(args); } catch (Exception e) { bool isHandled; context.EventAggregator.RaiseActionFailed(context.Session, e, _expression, tuple, out isHandled); if (!isHandled) { throw new RuleActionEvaluationException("Failed to evaluate rule action", _expression.ToString(), e); } } }
public void Deactivate(IExecutionContext context, Tuple tuple, FactIndexMap tupleFactMap) { var activation = new Activation(Rule, tuple, tupleFactMap); context.Agenda.Deactivate(activation); context.EventAggregator.RaiseActivationDeleted(context.Session, activation); }
private ICompiledRule CompileRule(ReteBuilder reteBuilder, IRuleDefinition ruleDefinition) { var transformation = new RuleTransformation(); var transformedRule = transformation.Transform(ruleDefinition); var ruleDeclarations = transformedRule.LeftHandSide.Declarations.ToList(); IEnumerable <ITerminalNode> terminals = reteBuilder.AddRule(transformedRule); var rightHandSide = transformedRule.RightHandSide; var actions = new List <IRuleAction>(); foreach (var action in rightHandSide.Actions) { var factIndexMap = FactIndexMap.CreateMap(action.References, ruleDeclarations); var ruleAction = new RuleAction(action.Expression, factIndexMap); actions.Add(ruleAction); } var rule = new CompiledRule(ruleDefinition, actions); BuildRuleNode(rule, terminals); return(rule); }
public RuleAction(LambdaExpression expression, FactIndexMap actionFactMap) { _expression = expression; _actionFactMap = actionFactMap; _compiledAction = FastDelegate.Create <Action <object[]> >(expression); }
public TerminalNode(ITupleSource source, FactIndexMap factIndexMap) { _factIndexMap = factIndexMap; source.Attach(this); }