public override void PropagateAssert(IExecutionContext context, IList <Tuple> tuples) { var joinedSets = JoinedSets(context, tuples); var aggregation = new Aggregation(); foreach (var set in joinedSets) { var matchingFacts = new List <Fact>(); foreach (var fact in set.Facts) { if (MatchesConditions(context, set.Tuple, fact)) { matchingFacts.Add(fact); } } IAggregator aggregator = CreateAggregator(set.Tuple); var results = aggregator.Add(set.Tuple, matchingFacts); aggregation.Add(set.Tuple, results); } PropagateAggregation(context, aggregation); }
public override void PropagateRetract(IExecutionContext context, List <Tuple> tuples) { var aggregation = new Aggregation(); using (var counter = PerfCounter.Retract(context, this)) { foreach (var tuple in tuples) { IFactAggregator aggregator = RemoveFactAggregator(context, tuple); if (aggregator != null) { aggregation.Remove(tuple, aggregator.AggregateFacts); } } counter.AddInputs(tuples.Count); counter.AddOutputs(aggregation.Count); } PropagateAggregation(context, aggregation); }
public override void PropagateRetract(IExecutionContext context, IList <Fact> facts) { var joinedSets = JoinedSets(context, facts); var aggregation = new Aggregation(); foreach (var set in joinedSets) { if (set.Facts.Count == 0) { continue; } var matchingFacts = GetMatchingFacts(context, set); if (matchingFacts.Count > 0) { IFactAggregator aggregator = GetFactAggregator(set.Tuple); if (aggregator != null) { RetractFromAggregate(context, aggregator, aggregation, set.Tuple, set.Facts); } } } PropagateAggregation(context, aggregation); }
private void AddAggregationResult(Aggregation aggregation, Tuple tuple, IEnumerable <AggregationResult> results) { foreach (var result in results) { switch (result.Action) { case AggregationAction.Added: var addedFact = CreateAggregateFact(result.Aggregate); aggregation.Add(tuple, addedFact); break; case AggregationAction.Modified: var modifiedFact = GetAggregateFact(result.Aggregate, result.Previous); aggregation.Modify(tuple, modifiedFact); break; case AggregationAction.Removed: var removedFact = RemoveAggregateFact(result.Aggregate); aggregation.Remove(tuple, removedFact); break; } } }
private void ResetAggregator(Aggregation aggregation, Tuple tuple, IFactAggregator aggregator) { tuple.RemoveState <IFactAggregator>(this); aggregation.Remove(tuple, aggregator.AggregateFacts); }
private void RetractFromAggregate(IExecutionContext context, IFactAggregator aggregator, Aggregation aggregation, Tuple tuple, IList <Fact> facts) { try { aggregator.Remove(aggregation, tuple, facts); } catch (AggregateExpressionException e) { bool isHandled = false; context.EventAggregator.RaiseAggregateFailed(context.Session, e.InnerException, e.Expression, e.Tuple, e.Fact, ref isHandled); if (!isHandled) { throw new RuleExpressionEvaluationException("Failed to evaluate aggregate expression", e.Expression.ToString(), e.InnerException); } ResetAggregator(aggregation, tuple, aggregator); } }
private void PropagateAggregation(IExecutionContext context, Aggregation aggregation) { PropagateAggregateRetracts(context, aggregation); PropagateAggregateAsserts(context, aggregation); PropagateAggregateUpdates(context, aggregation); }
private void RetractFromAggregate(AggregationContext context, IFactAggregator aggregator, Aggregation aggregation, Tuple tuple, List <Fact> facts) { try { aggregator.Remove(context, aggregation, tuple, facts); } catch (ExpressionEvaluationException e) { if (!e.IsHandled) { throw new RuleLhsExpressionEvaluationException("Failed to evaluate aggregate expression", e.Expression.ToString(), e.InnerException); } ResetAggregator(aggregation, tuple, aggregator); } }
public void Remove(Aggregation aggregation, Tuple tuple, IEnumerable <Fact> facts) { var results = _aggregator.Remove(tuple, facts); AddAggregationResult(aggregation, tuple, results); }
public void Modify(AggregationContext context, Aggregation aggregation, Tuple tuple, IEnumerable <Fact> facts) { var results = _aggregator.Modify(context, tuple, facts); AddAggregationResult(aggregation, tuple, results); }
private void ResetAggregator(IExecutionContext context, Aggregation aggregation, Tuple tuple, IFactAggregator aggregator) { context.WorkingMemory.RemoveState <IFactAggregator>(this, tuple); aggregation.Remove(tuple, aggregator.AggregateFacts); }