7.10. Custom Rules Editor

Many customers that I've worked with have ended up with a requirement to develop a custom UI with which their businesspeople can construct rules. We do, of course, have the Business Rule Composer for this purpose, but in some cases customers require a more restricted or cutdown design (to perhaps make it more suitable for a very nontechnical audience). Such a requirement should not be taken lightly, because rules editors not only enable you create new rules but should also perform validation (such as protecting rules designers from creating infinite loops).

The creation of rules via an API is fully supported and is provided within the Microsoft.RuleEngine namespace. Via this API, you can produce, for example, an ASP.NET Web application that significantly simplifies the rule design experience.

Rules creation is pretty straightforward and easy to understand using the API. Consider the following code. It implements a rule that uses a .NET class called Customer and then deploys the rule to the SQL-based rule store ready for execution. (We cover the custom deployment code in the next section.)

The PolicyTester class covered previously in this chapter could be used to directly execute the RuleSet when constructed instead of requiring formal deployment, which is used here:

The following rule:

IF Customer.Age < 21 AND Customer.Salary < "20,000"
THEN Customer.LoanRisk = "High"

is constructed in this code:

// Bind to the Customer class we will use in the Rule ClassBinding ...

Get Professional BizTalk® Server 2006 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.