internal ConditionErrorEventArgs(Exception exception, Expression expression, Tuple tuple, Fact fact)
     : base(exception)
 {
     _tuple = tuple;
     _fact = fact;
     Condition = expression;
 }
示例#2
0
        public void Ctor_WhenFactPassed_ExposedAsRightFact()
        {
            //Arrange
            var fact = new Fact(1);

            //Act
            var target = new Tuple(new Tuple(), fact);

            //Assert
            Assert.AreEqual(fact, target.RightFact);
        }
示例#3
0
文件: BetaMemory.cs 项目: bza/NRules
 public Tuple FindTuple(Tuple leftTuple, Fact rightFact)
 {
     Dictionary<Fact, Tuple> subMap;
     if (_parentToChildMap.TryGetValue(leftTuple, out subMap))
     {
         Tuple childTuple;
         subMap.TryGetValue(rightFact ?? NullFact, out childTuple);
         return childTuple;
     }
     return null;
 }
示例#4
0
        public void Ctor_WhenFactPassed_ExposedAsRightFactAndChained()
        {
            //Arrange
            var fact = new Fact(1);

            //Act
            var target = new Tuple(new Tuple(null), fact, null);

            //Assert
            Assert.AreEqual(fact, target.RightFact);
            Assert.Contains(target, fact.ChildTuples.ToArray());
        }
示例#5
0
        public void FactType_WhenObjectPassed_ReturnsItsType()
        {
            //Arrange
            var obj = new DateTime();
            var target = new Fact(obj);

            //Act
            var actual = target.FactType;
            var expected = typeof (DateTime);

            //Assert
            Assert.AreEqual(expected, actual);
        }
示例#6
0
        public void Clear_WhenCalledOn1Tuple_ClearsItselfAndUnchainsFact()
        {
            //Arrange
            var fact = new Fact(1);
            var target = new Tuple(new Tuple(null), fact, null);

            //Act
            target.Clear();

            //Assert
            Assert.IsNull(target.RightFact);
            Assert.AreEqual(0, fact.ChildTuples.Count);
        }
示例#7
0
        public bool IsSatisfiedBy(IExecutionContext context, Tuple leftTuple, Fact rightFact)
        {
            var rightTuple = ((WrapperFact)rightFact).WrappedTuple;
            using (IEnumerator<Fact> leftEnumerator = leftTuple.Facts.GetEnumerator())
            using (IEnumerator<Fact> rightEnumerator = rightTuple.Facts.GetEnumerator())
            {
                AlignEnumerators(leftEnumerator, rightEnumerator, leftTuple.Count, rightTuple.Count);

                while (leftEnumerator.MoveNext() && rightEnumerator.MoveNext())
                {
                    if (leftEnumerator.Current != rightEnumerator.Current) return false;
                }
            }
            return true;
        }
示例#8
0
 protected override void UnsatisfiedFactUpdate(IExecutionContext context, Fact fact)
 {
     //Do nothing, since fact type will never change
 }
示例#9
0
 public void Add(Tuple tuple, Fact fact)
 {
     _tuples.Add(tuple);
     _facts.Add(fact);
 }
示例#10
0
 public TResult Invoke(IExecutionContext context, NodeInfo nodeInfo, Fact fact)
 {
     return(Invoke(context, nodeInfo, null, fact));
 }
示例#11
0
 protected virtual void UnsatisfiedFactUpdate(IExecutionContext context, Fact fact)
 {
     ForceRetract(context, fact);
 }
示例#12
0
 public override void PropagateUpdate(IExecutionContext context, Fact fact)
 {
     //Do nothing
 }
示例#13
0
        public void Remove(Tuple tuple, Fact aggregateFact)
        {
            var list = GetList(AggregationAction.Removed);

            list.Add(tuple, aggregateFact);
        }
示例#14
0
        public void SetInternalFact(INode node, Fact fact)
        {
            Dictionary<object, Fact> factMap;
            if (!_internalFactMap.TryGetValue(node, out factMap))
            {
                factMap = new Dictionary<object, Fact>();
                _internalFactMap[node] = factMap;
            }

            factMap[fact.RawObject] = fact;
        }
示例#15
0
 public void Remove(Fact fact)
 {
     _facts.Remove(fact);
 }
示例#16
0
 public bool Contains(Fact fact)
 {
     return _facts.Contains(fact);
 }
示例#17
0
 public void Add(Fact fact)
 {
     _facts.Add(fact);
 }
示例#18
0
 public TupleFactKey(Tuple tuple, Fact fact)
 {
     _tuple = tuple;
     _fact  = fact;
 }
示例#19
0
 protected bool MatchesConditions(Tuple left, Fact right)
 {
     return(Conditions.All(joinCondition => joinCondition.IsSatisfiedBy(left, right)));
 }
示例#20
0
 public override bool IsSatisfiedBy(Fact fact)
 {
     return(Conditions.All(c => c.IsSatisfiedBy(fact)));
 }
示例#21
0
 public abstract void PropagateRetract(IExecutionContext context, Fact fact);
示例#22
0
 public void FactUpdated(Fact fact)
 {
     var handler = FactUpdatedEvent;
     if (handler != null)
     {
         var @event = new WorkingMemoryEventArgs(fact);
         handler(this, @event);
     }
 }
示例#23
0
 protected IEnumerable <Tuple> MatchingTuples(IExecutionContext context, Fact fact)
 {
     return(LeftSource.GetTuples(context).Where(tuple => MatchesConditions(context, tuple, fact)));
 }
示例#24
0
        public override bool IsSatisfiedBy(IExecutionContext context, Fact fact)
        {
            bool isMatchingType = FilterType.IsAssignableFrom(fact.FactType);

            return(isMatchingType);
        }
示例#25
0
 protected bool MatchesConditions(IExecutionContext context, Tuple left, Fact right)
 {
     return(Conditions.All(joinCondition => joinCondition.IsSatisfiedBy(context, left, right)));
 }
示例#26
0
 public abstract bool IsSatisfiedBy(IExecutionContext context, Fact fact);
示例#27
0
 private void PropagateAggregateAssert(IExecutionContext context, Tuple tuple, Fact aggregateFact)
 {
     if (aggregateFact != null)
     {
         var newTuple = new Tuple(tuple, aggregateFact, this);
         Sink.PropagateAssert(context, newTuple);
     }
 }
示例#28
0
 public void RaiseFactRetracted(ISession session, Fact fact)
 {
     var handler = FactRetractedEvent;
     if (handler != null)
     {
         var @event = new WorkingMemoryEventArgs(fact);
         handler(session, @event);
     }
     if (_parent != null)
     {
         _parent.RaiseFactRetracted(session, fact);
     }
 }
示例#29
0
 private void PropagateAggregateRetract(IExecutionContext context, Tuple tuple, Fact aggregateFact)
 {
     if (aggregateFact != null)
     {
         Tuple childTuple = tuple.ChildTuples.FirstOrDefault(t => t.RightFact == aggregateFact);
         if (childTuple != null)
         {
             Sink.PropagateRetract(context, childTuple);
         }
     }
 }
示例#30
0
        public TResult Invoke(IExecutionContext context, NodeInfo 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);
                }
            }
        }
示例#31
0
 public void Add(Fact fact)
 {
     _facts.Add(fact);
 }
示例#32
0
        public override bool IsSatisfiedBy(Fact fact)
        {
            bool isMatchingType = FilterType.IsAssignableFrom(fact.FactType);

            return(isMatchingType);
        }
示例#33
0
 public void RaiseConditionFailed(ISession session, Exception exception, Expression expression, Tuple tuple, Fact fact)
 {
     var hanlder = ConditionFailedEvent;
     if (hanlder != null)
     {
         var @event = new ConditionErrorEventArgs(exception, expression, tuple, fact);
         hanlder(session, @event);
     }
     if (_parent != null)
     {
         _parent.RaiseConditionFailed(session, exception, expression, tuple, fact);
     }
 }
示例#34
0
 internal FactInfo(Fact fact)
 {
     _fact = fact;
 }
示例#35
0
        public void RemoveInternalFact(INode node, Fact fact)
        {
            Dictionary<object, Fact> factMap;
            if (!_internalFactMap.TryGetValue(node, out factMap)) return;

            factMap.Remove(fact.RawObject);
            if (factMap.Count == 0) _internalFactMap.Remove(node);
        }
示例#36
0
 public bool Contains(Fact fact)
 {
     return(_facts.Contains(fact));
 }
示例#37
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);
            }
        }
示例#38
0
 public void Remove(Fact fact)
 {
     _facts.Remove(fact);
 }
示例#39
0
 private void PropagateAggregateUpdate(IExecutionContext context, Tuple tuple, Fact aggregateFact)
 {
     if (aggregateFact != null)
     {
         MemoryNode.PropagateUpdate(context, tuple, aggregateFact);
     }
 }
示例#40
0
 public void RemoveFact(Fact fact)
 {
     _factMap.Remove(fact.RawObject);
 }
示例#41
0
 private void PropagateAggregateRetract(IExecutionContext context, Tuple tuple, Fact aggregateFact)
 {
     if (aggregateFact != null)
     {
         MemoryNode.PropagateRetract(context, tuple, aggregateFact);
         context.WorkingMemory.RemoveFact(aggregateFact);
     }
 }
示例#42
0
 public void SetFact(Fact fact)
 {
     _factMap[fact.RawObject] = fact;
 }
示例#43
0
 internal WorkingMemoryEventArgs(Fact fact)
 {
     _fact = fact;
 }
示例#44
0
        public void Modify(Tuple tuple, Fact aggregateFact)
        {
            var list = GetList(AggregationAction.Modified);

            list.Add(tuple, aggregateFact);
        }
示例#45
0
        private void PropagateMatchedAssert(IExecutionContext context, Tuple tuple, Fact fact)
        {
            var childTuple = new Tuple(tuple, fact, this);

            Sink.PropagateAssert(context, childTuple);
        }