One of the most useful features added to version 4.0 is the capability of organizing rules and logic into folders and loading the entire hierarchy as a RuleSet

Grouping and organizing rules and logic sources into folders is common sense, especially when you have many of these and you need to selectively load them as parts of different user stories or scenarios.

 

Let’s say you are writing a medical/health system and for a particular scenario you need to build a RuleSet like this:

image

whereby in each of these sections you have multiple different rules and logic.

One way of building a RuleSet is to recursively iterate in the folders, load the rule model and build your RuleSet. However, in version 4.x you can simply use something like

 private static IRuleSet LoadRuleSet()
 {
     // Load ruleset by folder address
     var rulesLocation = new DirectoryInfo(Environment.CurrentDirectory + "\\Rules");
     return RuleSetFactory.FromDirectory(rulesLocation);
 }

There are different deployment packages. One is based on a folder container and the other one is based on a zip container. If you use publisher, you can deploy your group of rules as a ZipPackage, and your RuleSet will be loaded from that zip file by using ‘RuleSetFactory.FromZipPackage’.

In Publisher you need to set your deployment mode to ZipPackage:

image

And when you publish you will have the zip package. Now you can do something like:

 private static IRuleSet LoadRuleSet()
 {
     // Load ruleset by package file address
     var packageFile = new FileInfo(Environment.CurrentDirectory + "\\Rules\\TreatmentRules.frpz");
     return RuleSetFactory.FromZipPackage(packageFile.OpenRead());
 }

As simple as that!

Last updated April 24th, 2017 at 05:43 pm, Published March 13th, 2014 at 05:43 pm