AuditRuleset Class
Assembly: CodeEffects.Rule.Audit.dll
Namespace: CodeEffects.Rule.Audit
Summary
Holds the live versions of the rules that a RuleQuery named, and of every rule they call, as one ruleset for the Rules Engine, stamped with what the AuditRecorder needs to record their evaluations.
Syntax
public class AuditRuleset
You never create this class. AuditRecorder.GetRules(..) returns it. 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 class mirrors LoadedRuleset of the Repository library, with the stamps that recording needs.
The ruleset holds the called rules too, so the engine finds them without a rule resolver, and an evaluation of a rule that calls others is recorded as one record that names the version of each called rule.
A ruleset is a snapshot. A version that is made live after the ruleset was loaded does not change it, and the evaluations of an evaluator that was made from it are recorded against the versions it holds, which is what an audit should say. 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<AuditRule>
Gets every rule in the ruleset: those the query asked for first, then the rules they call.
Xml
Type: System.String
Gets the XML of the ruleset, for the constructor of the evaluator.
Methods
Rule(..)
Returns: CodeEffects.Rule.Audit.AuditRule - The rule, or null when the ruleset has none that matches.
public AuditRule Rule(string name)
public AuditRule 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.
Example
using CodeEffects.Rule.Audit;
using CodeEffects.Rule.Common.Models;
using CodeEffects.Rule.Engine;
AuditRuleset ruleset = audit.GetRules(RuleQuery.BySource("Order"));
var parameters = new EvaluationParameters();
audit.Attach(parameters);
var evaluator = new Evaluator<Order>(ruleset.Xml, parameters);
AuditRule rule = ruleset.Rule("Approve large orders");
bool approved = evaluator.Evaluate(order, rule.Id);