Beispiel #1
0
        public TResult Invoke(IExecutionContext context, NodeDebugInfo nodeInfo, Tuple tuple, Fact fact)
        {
            Exception exception = null;
            TResult   result    = default;

            try
            {
                result = _compiledExpression(fact);
                return(result);
            }
            catch (Exception e)
            {
                exception = e;
                bool isHandled = false;
                context.EventAggregator.RaiseLhsExpressionFailed(context.Session, e, _expression, _argumentMap, tuple, fact, nodeInfo, ref isHandled);
                throw new ExpressionEvaluationException(e, _expression, isHandled);
            }
            finally
            {
                if (context.EventAggregator.TraceEnabled)
                {
                    context.EventAggregator.RaiseLhsExpressionEvaluated(context.Session, exception, _expression, _argumentMap, result, tuple, fact, nodeInfo);
                }
            }
        }
Beispiel #2
0
        public bool IsSatisfiedBy(IExecutionContext context, NodeDebugInfo nodeInfo, Fact fact)
        {
            var       factValue = fact.Object;
            Exception exception = null;
            bool      result    = false;

            try
            {
                result = _compiledExpression.Delegate(factValue);
                return(result);
            }
            catch (Exception e)
            {
                exception = e;
                bool isHandled = false;
                context.EventAggregator.RaiseLhsExpressionFailed(context.Session, e, _expression, factValue, null, fact, nodeInfo, ref isHandled);
                if (!isHandled)
                {
                    throw new RuleLhsExpressionEvaluationException("Failed to evaluate condition", _expression.ToString(), e);
                }
                return(false);
            }
            finally
            {
                context.EventAggregator.RaiseLhsExpressionEvaluated(context.Session, exception, _expression, factValue, result, null, fact, nodeInfo);
            }
        }
Beispiel #3
0
        public object Invoke(IExecutionContext context, NodeDebugInfo nodeInfo, Tuple tuple)
        {
            var args  = new object[_compiledExpression.ArrayArgumentCount];
            int index = tuple.Count - 1;

            foreach (var fact in tuple.Facts)
            {
                IndexMap.SetElementAt(args, _factMap[index], fact.Object);
                index--;
            }

            Exception exception = null;
            object    result    = null;

            try
            {
                result = _compiledExpression.Delegate(args);
                return(result);
            }
            catch (Exception e)
            {
                exception = e;
                bool isHandled = false;
                context.EventAggregator.RaiseLhsExpressionFailed(context.Session, e, Expression, args, tuple, null, nodeInfo, ref isHandled);
                throw new ExpressionEvaluationException(e, Expression, isHandled);
            }
            finally
            {
                context.EventAggregator.RaiseLhsExpressionEvaluated(context.Session, exception, Expression, args, result, tuple, null, nodeInfo);
            }
        }
Beispiel #4
0
        public bool IsSatisfiedBy(IExecutionContext context, NodeDebugInfo nodeInfo, Tuple leftTuple, Fact rightFact)
        {
            var args  = new object[_compiledExpression.ArrayArgumentCount];
            int index = leftTuple.Count - 1;

            foreach (var fact in leftTuple.Facts)
            {
                IndexMap.SetElementAt(args, _factMap[index], fact.Object);
                index--;
            }
            IndexMap.SetElementAt(args, _factMap[leftTuple.Count], rightFact.Object);

            Exception exception = null;
            bool      result    = false;

            try
            {
                result = _compiledExpression.Delegate(args);
                return(result);
            }
            catch (Exception e)
            {
                exception = e;
                bool isHandled = false;
                context.EventAggregator.RaiseLhsExpressionFailed(context.Session, e, _expression, args, leftTuple, rightFact, nodeInfo, ref isHandled);
                if (!isHandled)
                {
                    throw new RuleLhsExpressionEvaluationException("Failed to evaluate condition", _expression.ToString(), e);
                }
                return(false);
            }
            finally
            {
                context.EventAggregator.RaiseLhsExpressionEvaluated(context.Session, exception, _expression, args, result, leftTuple, rightFact, nodeInfo);
            }
        }
Beispiel #5
0
 protected AlphaNode()
 {
     ChildNodes = new List <AlphaNode>();
     NodeInfo   = new NodeDebugInfo();
 }
Beispiel #6
0
 protected BetaNode()
 {
     NodeInfo = new NodeDebugInfo();
 }
Beispiel #7
0
 public TResult Invoke(IExecutionContext context, NodeDebugInfo nodeInfo, Fact fact)
 {
     return(Invoke(context, nodeInfo, null, fact));
 }
Beispiel #8
0
 public TResult Invoke(IExecutionContext context, NodeDebugInfo nodeInfo, Tuple tuple)
 {
     return(Invoke(context, nodeInfo, tuple, null));
 }