Business Rules Engine

When developing an application, model rules are vital such as; validating data outside of application codes for a direct hands-on-approach. The Business Rules Framework is a Microsoft .NET class library, which provides an engine to link highly readable, declarative, semantically rich rules to any business objects. It provides a convenient way for business clients building applications to define and change rules without impacting application code. Once rules are written in code, compiling and deploying the application each time for any further changes in rules would be required.

Scenario

Business users have the permissions to publish and deploy rules and there is no out-of-box monitoring way to track changes. We have two testing environments which we need to keep in sync to generate similar testing results. Users make changes in one environment, but don’t notify administrators to push changes in the other system. It is required to have some mechanism that communicates any modification in business rules.

Solution

There is an audit-trail table “re_audittrail” in BRE database “BizTalkRuleEngineDB,” which records all changes in any rule. We can write a small application which polls on a table and sends a notification in case a new entry is made in the audit-trail table. Once we have notification, then we can export relevant policy/vocabulary from one environment to import to the other.

It can be achieved in different ways:

  • Write a windows application to check changes in database and send alerts

BizTalk-BRE-1

Another simple way is to write a PowerShell script which involves the following steps:

  • Import SQLPS module
  • Create a timestamp file to read and save last execution date time
  • Create SQL Statement to fetch changes based on last timestamp
  • Connect to SQL Server and check for any changes based on timestamp
  • Send email to specific users in case any changes are found
  • Schedule script through Windows Task Scheduler to run each night

Below is the PowerShell code snippet to achieve this:

BizTalk-BRE-2

This script along with timestamp.txt file can be saved on the server and scheduled to run by using windows scheduler:

BizTalk-BRE-3