-
Notifications
You must be signed in to change notification settings - Fork 18
Authoring Rules
OAT operates by checking if Rules apply to targeted objects. This page documents the format for specifying those rules.
A Rule
contains
-
Name
string -
Severity
int -
Description
string (optional) -
Clauses
List<Clause> (optional) -
Expression
string (optional) -
Target
string - Name of the object to apply to (optional)
A Rule
matches an Object when:
- The Object's type maps to the specified
Target
ORTarget
is null - AND any of
- The rule has no
Clauses
- The rule has no
Expression
AND all itsClauses
are true - The evaluation of the
Expression
is true
- The rule has no
A Clause
contains:
- An
Operation
- see Operations - A
Field
that the Clause applies to. This can be any property or field, or any sub-property or sub-field. If null the object itself is used. - A
Label
(required if using anExpression
in the associatedRule
). The Label may contain characters other than whitespace and parentheses. - List,
Data
as appropriate depending on theOperation
. - Dictionary<string,string>,
DictData
as appropriate depending on theOperation
.
The Expression
in a rule is a user specified boolean expression across the defined Clauses
' Labels in the Rule
.
These are some examples of Valid Expressions:
FOO
FOO AND BAR
FOO OR BAR NAND NOT BAZ OR (BAT123 XOR $B@A%N)
These are some examples of Invalid Expressions
FOO BAR OR // Each clause must be separated by an operator
((FOO OR BAR ) // Parenthesis must be balanced
F(OO OR BA)R // Clause Labels may not contain parenthesis
Expressions can be created using any of the standard boolean operators in addition to parenthesis.
OR
AND
NOR
NAND
XOR
NOT
To see if your rules are valid you can check if they have any violations. Each violation includes a message explaining the issue and where it is occurring.
var analyzer = new Analyzer();
var violations = analyzer.EnumerateRuleIssues(rules)
This is an example of a simple rule from the toll system demo in the walkthrough.
new VehicleRule("Normal Car"){
Cost = 3,
Severity = 1,
Target = "Vehicle",
Clauses = new List<Clause>()
{
new Clause("Weight", OPERATION.GT)
{
Data = new List<string>()
{
"1000"
}
}
}
}
This is an example of a more complicated rule which uses an OR
based Expression
in order to match either a weight limit or a large number of axles.
new VehicleRule("Heavy or long")
{
Cost = 10,
Severity = 3,
Expression = "Weight OR Axles",
Target = "Vehicle",
Clauses = new List<Clause>()
{
new Clause("Weight", OPERATION.GT)
{
Label = "Weight",
Data = new List<string>()
{
"4000"
}
},
new Clause("Axles", OPERATION.GT)
{
Label = "Axles",
Data = new List<string>()
{
"2"
}
}
}
},