internal ConditionErrorEventArgs(Exception exception, Expression expression, Tuple tuple, Fact fact) : base(exception) { _tuple = tuple; _fact = fact; Condition = expression; }
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); }
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; }
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()); }
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); }
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); }
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; }
protected override void UnsatisfiedFactUpdate(IExecutionContext context, Fact fact) { //Do nothing, since fact type will never change }
public void Add(Tuple tuple, Fact fact) { _tuples.Add(tuple); _facts.Add(fact); }
public TResult Invoke(IExecutionContext context, NodeInfo nodeInfo, Fact fact) { return(Invoke(context, nodeInfo, null, fact)); }
protected virtual void UnsatisfiedFactUpdate(IExecutionContext context, Fact fact) { ForceRetract(context, fact); }
public override void PropagateUpdate(IExecutionContext context, Fact fact) { //Do nothing }
public void Remove(Tuple tuple, Fact aggregateFact) { var list = GetList(AggregationAction.Removed); list.Add(tuple, aggregateFact); }
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; }
public void Remove(Fact fact) { _facts.Remove(fact); }
public bool Contains(Fact fact) { return _facts.Contains(fact); }
public void Add(Fact fact) { _facts.Add(fact); }
public TupleFactKey(Tuple tuple, Fact fact) { _tuple = tuple; _fact = fact; }
protected bool MatchesConditions(Tuple left, Fact right) { return(Conditions.All(joinCondition => joinCondition.IsSatisfiedBy(left, right))); }
public override bool IsSatisfiedBy(Fact fact) { return(Conditions.All(c => c.IsSatisfiedBy(fact))); }
public abstract void PropagateRetract(IExecutionContext context, Fact fact);
public void FactUpdated(Fact fact) { var handler = FactUpdatedEvent; if (handler != null) { var @event = new WorkingMemoryEventArgs(fact); handler(this, @event); } }
protected IEnumerable <Tuple> MatchingTuples(IExecutionContext context, Fact fact) { return(LeftSource.GetTuples(context).Where(tuple => MatchesConditions(context, tuple, fact))); }
public override bool IsSatisfiedBy(IExecutionContext context, Fact fact) { bool isMatchingType = FilterType.IsAssignableFrom(fact.FactType); return(isMatchingType); }
protected bool MatchesConditions(IExecutionContext context, Tuple left, Fact right) { return(Conditions.All(joinCondition => joinCondition.IsSatisfiedBy(context, left, right))); }
public abstract bool IsSatisfiedBy(IExecutionContext context, Fact fact);
private void PropagateAggregateAssert(IExecutionContext context, Tuple tuple, Fact aggregateFact) { if (aggregateFact != null) { var newTuple = new Tuple(tuple, aggregateFact, this); Sink.PropagateAssert(context, newTuple); } }
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); } }
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); } } }
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); } } }
public override bool IsSatisfiedBy(Fact fact) { bool isMatchingType = FilterType.IsAssignableFrom(fact.FactType); return(isMatchingType); }
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); } }
internal FactInfo(Fact fact) { _fact = fact; }
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); }
public bool Contains(Fact fact) { return(_facts.Contains(fact)); }
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); } }
private void PropagateAggregateUpdate(IExecutionContext context, Tuple tuple, Fact aggregateFact) { if (aggregateFact != null) { MemoryNode.PropagateUpdate(context, tuple, aggregateFact); } }
public void RemoveFact(Fact fact) { _factMap.Remove(fact.RawObject); }
private void PropagateAggregateRetract(IExecutionContext context, Tuple tuple, Fact aggregateFact) { if (aggregateFact != null) { MemoryNode.PropagateRetract(context, tuple, aggregateFact); context.WorkingMemory.RemoveFact(aggregateFact); } }
public void SetFact(Fact fact) { _factMap[fact.RawObject] = fact; }
internal WorkingMemoryEventArgs(Fact fact) { _fact = fact; }
public void Modify(Tuple tuple, Fact aggregateFact) { var list = GetList(AggregationAction.Modified); list.Add(tuple, aggregateFact); }
private void PropagateMatchedAssert(IExecutionContext context, Tuple tuple, Fact fact) { var childTuple = new Tuple(tuple, fact, this); Sink.PropagateAssert(context, childTuple); }