LoadedRuleset Class
Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository
Summary
Holds the live versions of the rules that a RuleQuery named, and of every rule they call or execute, as one ruleset for the Rules Engine.
Syntax
public class LoadedRuleset
You never create this class. Context.GetRules(..) returns it (see below). Pass its Xml property to the constructor of Evaluator<TSource> as it is, and use Rule(..) to find the ID of the rule to evaluate.
The ruleset holds the called rules too, so the engine finds them without a rule resolver. The document carries nothing for recording: evaluating it leaves no trace in the repository. An application that has the Audit library loads its rules through AuditRecorder.GetRules(..) instead, which returns the same rules stamped for recording.
A ruleset is a snapshot. A version that is made live after the ruleset was loaded does not change it. Create the evaluator once and keep it for as long as the ruleset is current, and call GetRules(..) again to pick up newer versions.
Properties
Rules
Type: System.Collections.Generic.IReadOnlyList<LoadedRule>
Gets every rule in the ruleset: those the query asked for first, in order of name, then the rules they call.
Xml
Type: System.String
Gets the XML of the ruleset: the Rule XML of each live version as it is stored, in one document, for the constructor of the evaluator.
Methods
Rule(..)
Returns: CodeEffects.Rule.Repository.LoadedRule - The rule, or null when the ruleset has none that matches.
public LoadedRule Rule(string name)
public LoadedRule Rule(Guid id)
Finds a rule of the ruleset by its name or by its ID. When two rules share a name, the one the query asked for is returned before one that is only called.
Parameters
- name (
System.String) - The name of the rule. Names are compared exactly, including case.
- id (
System.Guid) - The ID of the rule.
Static Method That Returns It
Context.GetRules(..)
Returns: CodeEffects.Rule.Repository.LoadedRuleset - The ruleset of the live rules the query names.
public static LoadedRuleset GetRules(IDbProvider dbProvider, RuleQuery query)
Loads the live versions of the rules a RuleQuery names, and the live versions of every rule they call, in one ruleset. It reads the database every time it is called.
Parameters
- dbProvider (
CodeEffects.Rule.Connection.IDbProvider) - The database provider of the Rule Repository.
- query (
CodeEffects.Rule.Common.Models.RuleQuery) - Which rules to load.
Exceptions
CodeEffects.Rule.Common.RuleException - The provider or the query is null; no rule with a live version matches the query; a rule asked for by ID or name does not exist or has no live version; a rule calls a rule that has no live version; or a live version is not a rule's XML. The message says which.
Example
using CodeEffects.Rule.Common.Models;
using CodeEffects.Rule.Engine;
using CodeEffects.Rule.Repository;
LoadedRuleset ruleset = Context.GetRules(dbProvider, RuleQuery.BySource("MyApp.Orders.Order"));
var evaluator = new Evaluator<Order>(ruleset.Xml, new EvaluationParameters());
bool approved = evaluator.Evaluate(order, ruleset.Rule("Approve large orders").Id);