示例#1
0
 public RuleAction(LambdaExpression expression, IndexMap factIndexMap, IndexMap dependencyIndexMap)
 {
     _expression = expression;
     _factIndexMap = factIndexMap;
     _dependencyIndexMap = dependencyIndexMap;
     _compiledAction = FastDelegate.Create<Action<object[]>>(expression);
 }
示例#2
0
        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);
                }
            }
        }
示例#3
0
 public TerminalNode(ITupleSource source, IndexMap factIndexMap)
 {
     _factIndexMap = factIndexMap;
     source.Attach(this);
 }
示例#4
0
 public BetaCondition(LambdaExpression expression, FastDelegate <Func <object[], bool> > compiledExpression, IndexMap factIndexMap)
 {
     _expression         = expression;
     _factIndexMap       = factIndexMap;
     _compiledExpression = compiledExpression;
 }
示例#5
0
 public BindingExpression(LambdaExpression expression, FastDelegate <Func <object[], object> > compiledExpression, IndexMap factMap)
 {
     Expression          = expression;
     _compiledExpression = compiledExpression;
     _factMap            = factMap;
 }
示例#6
0
        public static IndexMap Compose(IndexMap first, IndexMap second)
        {
            var map = first._map.Select(x => second[x]).ToArray();

            return(new IndexMap(map));
        }
示例#7
0
 public BetaCondition(LambdaExpression expression, IndexMap factIndexMap)
 {
     _expression         = expression;
     _factIndexMap       = factIndexMap;
     _compiledExpression = FastDelegate.BetaCondition(expression);
 }