5,542,300 members and growing! (17,899 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate License: The Code Project Open License (CPOL)

Use Rules In Your Applications

By Jeff Bramlett

A Rules Engine class library with source code and documentation
C#, Windows, Visual Studio, Dev

Posted: 29 Aug 2006
Updated: 29 Aug 2006
Views: 29,982
Bookmarked: 47 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 5.79 Rating: 4.61 out of 5
1 vote, 5.6%
1
1 vote, 5.6%
2
0 votes, 0.0%
3
4 votes, 22.2%
4
12 votes, 66.7%
5
Overview of first Use Case

Introduction

This Rules Engine was formulated from my need to provide automation based on external rules. The rules were to govern how the graphical user interface (GUI) behaved in response to Rule execution. De-coupling the rules of the application enabled me to then develop the GUI independently of the Rules and to develop the Rules independently of the application. The connection between the application and the rules is a rules engine whose responsibility is the execution of the rules and notifying the application of changes to variables.

This is the original intent of this Rules Engine, it has since evolved in scope and applicability.

Background

The original intent of this library precluded any notion of ambiguous or non-determinant rule execution. The original need required absolute determination of results since the automation of a GUI cannot resolve ambiguity. I decided to define Rules such that the Rule maker made the decision tree(s).

Rules engines that I have seen (Corticon's offering excepted) are built upon the RETE algorithm. This engine does not utilize the RETE algorithm. RETE can produce non-determinant results which can be disastrous to automation. RETE is better suited to analysis than automation.

This engine has evolved to accommodate various use cases.

Thread-safety is integral to the engine and is implemented using the ReaderWriter lock in .NET. Rule execution based on variable changes is implemented by defining "Triggers". Events for rule execution as well as variable changes are also defined.

Using the Code

The Rules Engine is utilized by instantiating a Rule Engine object from the class. The Rules Engine can then be loaded with Rules.

Instantiating a Rules Engine and adding delegates:

Variable _oVariableEngine = new VariableEngine();
RulesEngine _oRulesEngine = new RulesEngine();
_oRulesEngine.VarEngine = _oVariableEngine;

_oRulesEngine.VariableChanging += 
    new RulesEngine.VariableChangingDelegate(_oRulesEngine_VariableChanging);
_oRulesEngine.VariableChanged +=
    new RulesEngine.VariableChangedDelegate(_oRulesEngine_VariableChanged);
_oRulesEngine.VariableAdded +=
    new RulesEngine.VariableAddedDelegate(_oRulesEngine_VariableAdded);
_oRulesEngine.RuleEntered +=
    new RulesEngine.RuleEnteredDelegate(_oRulesEngine_RuleEntered);
_oRulesEngine.RuleComplete += 
    new RulesEngine.RuleCompleteDelegate(_oRulesEngine_RuleComplete);

Rules can be defined and loaded into the engine from any source. The source code contains a Reader/Writer Visual Studio Solution as well as an XML Schema (with documentation) for using an XML file to define and persist Rules.

Links of Interest

Points of Interest

  • Type-safe collections are implemented by extending CollectionBase and using a binary search algorithm to provide high performance access to any item in the collection.
  • Variables are class objects that have overloaded operators.
  • There is an Interface that allows any object to be used as a variable. Using DataSets as variables are implemented using this methodology
  • The source code contains the complete Visual Studio Solution of Jaxlab Rules Engine, complete Visual Studio Solution for Reader/Writer class, Rule XML Schema and documentation, complete documentation of Rules Engine (HTML and CHM).
  • A Rule can contain Rules to create rule trees to organize rules and rule processing.

History

  • 29th August, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jeff Bramlett


Website: http://www.devbyjeffbramlett.com
Occupation: Web Developer
Location: United States United States

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 15 of 15 (Total in Forum: 15) (Refresh)FirstPrevNext
Subject  Author Date 
NewsGood articlememberArash Aghlara23:12 2 Aug '08  
GeneralAuthor's Web Sitemembervextant19:15 10 Feb '08  
GeneralRe: Author's Web SitememberARUVAL7:21 3 Mar '08  
GeneralNxBrememberTim Schwallie12:03 26 Jan '07  
GeneralRe: NxBrememberJeff Bramlett9:33 29 Jan '07  
GeneralThank you, this is impressive.memberGrav-Vt14:48 29 Nov '06  
GeneralHow to create rules?membervictorvieira5:53 1 Nov '06  
AnswerRe: How to create rules?memberjeff_bramlett@hotmail.com1:40 2 Nov '06  
GeneralRe: How to create rules?memberjeff_bramlett@hotmail.com1:48 2 Nov '06  
QuestionReturning a String resultmemberRob_Jurado13:49 8 Sep '06  
Questionlooking for a Trigger by namememberRob_Jurado11:53 6 Sep '06  
AnswerRe: looking for a Trigger by namememberJeff Bramlett15:06 6 Sep '06  
GeneralNice workmemberRob_Jurado13:42 5 Sep '06  
GeneralThanks for postingmemberjruvelIGN8:15 30 Aug '06  
GeneralRe: Thanks for postingmemberJeff Bramlett8:27 30 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Aug 2006
Editor: Deeksha Shenoy
Copyright 2006 by Jeff Bramlett
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project