internal ConditionErrorEventArgs(Exception exception, Expression expression, Tuple tuple, Fact fact)
     : base(exception)
 {
     _tuple = tuple;
     _fact = fact;
     Condition = expression;
 }
Example #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);
        }
Example #3
0
 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;
 }
Example #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());
        }
Example #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);
        }
Example #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);
        }
Example #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;
        }
Example #8
0
 protected override void UnsatisfiedFactUpdate(IExecutionContext context, Fact fact)
 {
     //Do nothing, since fact type will never change
 }
Example #9
0
 public void Add(Tuple tuple, Fact fact)
 {
     _tuples.Add(tuple);
     _facts.Add(fact);
 }
Example #10
0
 public TResult Invoke(IExecutionContext context, NodeInfo nodeInfo, Fact fact)
 {
     return(Invoke(context, nodeInfo, null, fact));
 }
Example #11
0
 protected virtual void UnsatisfiedFactUpdate(IExecutionContext context, Fact fact)
 {
     ForceRetract(context, fact);
 }
Example #12
0
 public override void PropagateUpdate(IExecutionContext context, Fact fact)
 {
     //Do nothing
 }
Example #13
0
        public void Remove(Tuple tuple, Fact aggregateFact)
        {
            var list = GetList(AggregationAction.Removed);

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

            return(isMatchingType);
        }
Example #25
0
 protected bool MatchesConditions(IExecutionContext context, Tuple left, Fact right)
 {
     return(Conditions.All(joinCondition => joinCondition.IsSatisfiedBy(context, left, right)));
 }
Example #26
0
 public abstract bool IsSatisfiedBy(IExecutionContext context, Fact fact);
Example #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);
     }
 }
Example #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);
     }
 }
Example #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);
         }
     }
 }
Example #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);
                }
            }
        }
Example #31
0
 public void Add(Fact fact)
 {
     _facts.Add(fact);
 }
Example #32
0
        public override bool IsSatisfiedBy(Fact fact)
        {
            bool isMatchingType = FilterType.IsAssignableFrom(fact.FactType);

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

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

            Sink.PropagateAssert(context, childTuple);
        }