public RuleAction(LambdaExpression expression, IndexMap factIndexMap, IndexMap dependencyIndexMap) { _expression = expression; _factIndexMap = factIndexMap; _dependencyIndexMap = dependencyIndexMap; _compiledAction = FastDelegate.Create<Action<object[]>>(expression); }
public void Invoke(IExecutionContext context, IContext actionContext, Tuple tuple, IndexMap tupleFactMap, IEnumerable<IRuleDependency> dependencies) { var args = new object[_compiledAction.ParameterCount]; args[0] = actionContext; int index = tuple.Count - 1; foreach (var fact in tuple.Facts) { var mappedIndex = _factIndexMap[tupleFactMap[index]]; IndexMap.SetElementAt(ref args, mappedIndex, 1, fact.Object); index--; } index = 0; var dependencyResolver = context.Session.DependencyResolver; foreach (var dependency in dependencies) { var mappedIndex = _dependencyIndexMap[index]; if (mappedIndex >= 0) { var resolvedDependency = dependency.Factory(dependencyResolver, new ResolutionContext(context.Session, actionContext.Rule)); IndexMap.SetElementAt(ref args, mappedIndex, 1, resolvedDependency); } 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 TerminalNode(ITupleSource source, IndexMap factIndexMap) { _factIndexMap = factIndexMap; source.Attach(this); }
public BetaCondition(LambdaExpression expression, FastDelegate <Func <object[], bool> > compiledExpression, IndexMap factIndexMap) { _expression = expression; _factIndexMap = factIndexMap; _compiledExpression = compiledExpression; }
public BindingExpression(LambdaExpression expression, FastDelegate <Func <object[], object> > compiledExpression, IndexMap factMap) { Expression = expression; _compiledExpression = compiledExpression; _factMap = factMap; }
public static IndexMap Compose(IndexMap first, IndexMap second) { var map = first._map.Select(x => second[x]).ToArray(); return(new IndexMap(map)); }
public BetaCondition(LambdaExpression expression, IndexMap factIndexMap) { _expression = expression; _factIndexMap = factIndexMap; _compiledExpression = FastDelegate.BetaCondition(expression); }