예제 #1
0
 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
파일: FactTest.cs 프로젝트: hebert26/NRules
        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
파일: TypeNode.cs 프로젝트: zhjrate/NRules
        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
파일: FactInfo.cs 프로젝트: hebert26/NRules
 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);
        }