Hi everyone,
This
is to announce the latest new feature: Rule Categories. The updated source code
is available at http://dynamicdom.tigris.org/
Rule categories address the requirement for categorizing failed rules
into errors vs. warnings, but it also allows for a much more flexible
categorization such as “catastrophic, critical, recoverable” or “user,
system” or “General, Financial, UserDetails”…
etc. Basically, you choose your own categorization system. Here is an example:
<xr:ruleset context="/PurchaseOrder">
<xr:validate test="..." categories="error" />
<xr:validate test="..." categories="warning" />
</xr:ruleset>
If the first rule fails, for example, the error report will show
the error as follows (notice the categories attribute):
<xrr:error context="/PurchaseOrder" categories="error">
<xrr:message>...</xrr:message>
<xrr:node path="..." />
</xrr:error>
You can also categorize a rule under several categories by
using a space-separated list of
categories:
<xr:validate test="..." categories="error financial" />
Categories are also inherited from parent rulesets. For example:
<xr:ruleset context="/PurchaseOrder" categories="header">
<xr:validate test="..." categories="error" />
<xr:validate test="..." categories="warning" />
</xr:ruleset>
Or inherited from several up levels
of rulesets:
<xr:ruleset context="/PurchaseOrder/Item" categories="item">
<xr:ruleset context="ItemDetails" categories="financial">
<xr:validate test="..." />
</xr:ruleset>
</xr:ruleset>
In this example, although the rule does not have the ‘categories’
attribute, it inherits the “item” and “financial”
categories. If this rule fails, the error report will show the error as:
<xrr:error context="ItemDetails" categories="financial item">
<xrr:message>...</xrr:message>
<xrr:node path="..." />
</xrr:error>
And, in the XRules Object Model
you can access the categories using the “Catagories”
property of rule classes. Or, use the “EffectiveCategories”
property to get the rule categories including all categories inherited from
parent rulesets.
// Iterate
though the categories of a rule.
CategoriesList cat = myRule.EffectiveCategories;
if (cat.Count > 0)
{
foreach(string category in
cat)
{
// Iterate
through the categories.
}
}
Hope
you find this feature useful.
Regards,
Waleed