Table of Contents

Interface ISession

Namespace
NRules
Assembly
NRules.dll

Represents a rules engine session. Created by ISessionFactory. Each session has its own working memory, and exposes operations that manipulate facts in it, as well as fire matching rules.

public interface ISession : ISessionSchemaProvider
Inherited Members

Properties

ActionInterceptor

Action interceptor for the current rules session. If provided, invocation of rule actions is delegated to the interceptor.

IActionInterceptor ActionInterceptor { get; set; }

Property Value

IActionInterceptor

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Agenda

Agenda, which represents a store for rule matches.

IAgenda Agenda { get; }

Property Value

IAgenda

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

AutoPropagateLinkedFacts

Controls how the engine propagates linked facts from rules that insert/update/retract linked facts in their actions. By default, AutoPropagateLinkedFacts is true and the engine automatically propagates linked facts at the end of the rule's actions. If AutoPropagateLinkedFacts is false, linked facts are queued, and have to be explicitly propagated by calling PropagateLinked() method.

bool AutoPropagateLinkedFacts { get; set; }

Property Value

bool

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

DependencyResolver

Rules dependency resolver for the current rules session.

IDependencyResolver DependencyResolver { get; set; }

Property Value

IDependencyResolver

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Events

Provider of events from the current rule session. Use it to subscribe to various rules engine lifecycle events.

IEventProvider Events { get; }

Property Value

IEventProvider

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Metrics

Provider of session performance metrics for the current rule session.

IMetricsProvider Metrics { get; }

Property Value

IMetricsProvider

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Methods

Fire()

Starts rules execution cycle. This method blocks until there are no more rules to fire.

int Fire()

Returns

int

Number of rules that fired.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Fire(int)

Starts rules execution cycle. This method blocks until maximum number of rules fired or there are no more rules to fire.

int Fire(int maxRulesNumber)

Parameters

maxRulesNumber int

Maximum number of rules to fire.

Returns

int

Number of rules that fired.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Fire(int, CancellationToken)

Starts rules execution cycle. This method blocks until maximum number of rules fired, cancellation is requested or there are no more rules to fire.

int Fire(int maxRulesNumber, CancellationToken cancellationToken)

Parameters

maxRulesNumber int

Maximum number of rules to fire.

cancellationToken CancellationToken

Enables cooperative cancellation of the rules execution cycle.

Returns

int

Number of rules that fired.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Fire(CancellationToken)

Starts rules execution cycle. This method blocks until there are no more rules to fire or cancellation is requested.

int Fire(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Enables cooperative cancellation of the rules execution cycle.

Returns

int

Number of rules that fired.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Insert(object)

Inserts new fact to the rules engine memory.

void Insert(object fact)

Parameters

fact object

Facts to insert.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

ArgumentException

If fact already exists in working memory.

InsertAll(IEnumerable<object>)

Inserts new facts to the rules engine memory.

void InsertAll(IEnumerable<object> facts)

Parameters

facts IEnumerable<object>

Facts to insert.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

ArgumentException

If any fact already exists in working memory.

PropagateLinked()

Propagates all queued linked facts.

IEnumerable<ILinkedFactSet> PropagateLinked()

Returns

IEnumerable<ILinkedFactSet>

Collection of propagated sets of linked facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Query<TFact>()

Creates a LINQ query to retrieve facts of a given type from the rules engine's memory.

IQueryable<TFact> Query<TFact>()

Returns

IQueryable<TFact>

Queryable working memory of the rules engine.

Type Parameters

TFact

Type of facts to query. Use object to query all facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Retract(object)

Removes existing fact from the rules engine memory.

void Retract(object fact)

Parameters

fact object

Fact to remove.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

ArgumentException

If fact does not exist in working memory.

RetractAll(IEnumerable<object>)

Removes existing facts from the rules engine memory.

void RetractAll(IEnumerable<object> facts)

Parameters

facts IEnumerable<object>

Facts to remove.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

ArgumentException

If any fact does not exist in working memory.

TryInsert(object)

Inserts a fact to the rules engine memory if the fact does not exist.

bool TryInsert(object fact)

Parameters

fact object

Fact to insert.

Returns

bool

Whether the fact was inserted or not.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryInsertAll(IEnumerable<object>)

Inserts new facts to the rules engine memory if the facts don't exist. If any of the facts exists in the engine, none of the facts are inserted.

IFactResult TryInsertAll(IEnumerable<object> facts)

Parameters

facts IEnumerable<object>

Facts to insert.

Returns

IFactResult

Result of facts insertion.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryInsertAll(IEnumerable<object>, BatchOptions)

Inserts new facts to the rules engine memory if the facts don't exist. If any of the facts exists in the engine, the behavior is defined by BatchOptions.

IFactResult TryInsertAll(IEnumerable<object> facts, BatchOptions options)

Parameters

facts IEnumerable<object>

Facts to insert.

options BatchOptions

Options that define behavior of the batch operation.

Returns

IFactResult

Result of facts insertion.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryRetract(object)

Removes a fact from the rules engine memory if the fact exists.

bool TryRetract(object facts)

Parameters

facts object

Fact to remove.

Returns

bool

Whether the fact was retracted or not.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryRetractAll(IEnumerable<object>)

Removes existing facts from the rules engine memory if the facts exist. If any of the facts don't exist in the engine, none of the facts are removed.

IFactResult TryRetractAll(IEnumerable<object> facts)

Parameters

facts IEnumerable<object>

Facts to remove.

Returns

IFactResult

Result of facts removal.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryRetractAll(IEnumerable<object>, BatchOptions)

Removes existing facts from the rules engine memory if the facts exist. If any of the facts don't exist in the engine, the behavior is defined by BatchOptions.

IFactResult TryRetractAll(IEnumerable<object> facts, BatchOptions options)

Parameters

facts IEnumerable<object>

Facts to remove.

options BatchOptions

Options that define behavior of the batch operation.

Returns

IFactResult

Result of facts removal.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryUpdate(object)

Updates a fact in the rules engine memory if the fact exists.

bool TryUpdate(object fact)

Parameters

fact object

Fact to update.

Returns

bool

Whether the fact was updated or not.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryUpdateAll(IEnumerable<object>)

Updates existing facts in the rules engine memory if the facts exist. If any of the facts don't exist in the engine, none of the facts are updated.

IFactResult TryUpdateAll(IEnumerable<object> facts)

Parameters

facts IEnumerable<object>

Facts to update.

Returns

IFactResult

Result of facts update.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

TryUpdateAll(IEnumerable<object>, BatchOptions)

Updates existing facts in the rules engine memory if the facts exist. If any of the facts don't exist in the engine, the behavior is defined by BatchOptions.

IFactResult TryUpdateAll(IEnumerable<object> facts, BatchOptions options)

Parameters

facts IEnumerable<object>

Facts to update.

options BatchOptions

Options that define behavior of the batch operation.

Returns

IFactResult

Result of facts update.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

RuleLhsExpressionEvaluationException

Error while evaluating any of the rules' left-hand side expressons. This exception can also be observed as an event LhsExpressionEvaluatedEvent.

AgendaExpressionEvaluationException

Error while evaluating any of the agenda expressions. This exception can also be observed as an event AgendaExpressionFailedEvent.

RuleRhsExpressionEvaluationException

Error while evaluating any of the rules' right-hand side expressions. This exception can also be observed as an event RhsExpressionFailedEvent.

Update(object)

Updates existing fact in the rules engine memory.

void Update(object fact)

Parameters

fact object

Fact to update.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

ArgumentException

If fact does not exist in working memory.

UpdateAll(IEnumerable<object>)

Updates existing facts in the rules engine memory.

void UpdateAll(IEnumerable<object> facts)

Parameters

facts IEnumerable<object>

Facts to update.

Remarks

Bulk session operations are more performant than individual operations on a set of facts.

Exceptions

ArgumentException

If any fact does not exist in working memory.

See Also