Click here to Skip to main content
11,804,566 members (96,631 online)
Click here to Skip to main content

Use Rules In Your Applications

, 29 Aug 2006 CPOL 83.4K 2.4K 92
Rate this:
Please Sign up or sign in to vote.
A Rules Engine class library with source code and documentation
Overview of first Use Case


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.


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.


  • 29th August, 2006: Initial post


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


About the Author

Jeff Bramlett
Software Developer (Senior)
United States United States

You may also be interested in...

Comments and Discussions

GeneralThe License is LGPL not CPOL Pin
CyborgDE11-Jun-11 3:38
memberCyborgDE11-Jun-11 3:38 
QuestionHow to match variables plz. help me [modified] Pin
ShyamPrasadP5-Dec-10 20:05
memberShyamPrasadP5-Dec-10 20:05 
GeneralQuestion Pin
chazim12-Nov-10 8:20
memberchazim12-Nov-10 8:20 
GeneralRe: Question Pin
Jeff Bramlett12-Nov-10 15:03
memberJeff Bramlett12-Nov-10 15:03 
GeneralRe: Question Pin
terryterryd14-Apr-11 2:08
memberterryterryd14-Apr-11 2:08 
GeneralRe: Question Pin
Jeff Bramlett12-Nov-10 15:05
memberJeff Bramlett12-Nov-10 15:05 
QuestionHow to use loops Pin
Sumit Prakash Sharma20-Apr-09 2:17
memberSumit Prakash Sharma20-Apr-09 2:17 
QuestionNeed Help ! Pin
rajalakshmiam16-Apr-09 23:51
memberrajalakshmiam16-Apr-09 23:51 
GeneralBroken Links Pin
chris lambrou1-Mar-09 19:05
memberchris lambrou1-Mar-09 19:05 
GeneralGUI for making new rules and editing the existing one Pin
Banty Nigam12-Feb-09 20:29
memberBanty Nigam12-Feb-09 20:29 
NewsGood article Pin
Arash Aghlara2-Aug-08 22:12
memberArash Aghlara2-Aug-08 22:12 
GeneralAuthor's Web Site Pin
vextant10-Feb-08 18:15
membervextant10-Feb-08 18:15 
GeneralRe: Author's Web Site Pin
ARUVAL3-Mar-08 6:21
memberARUVAL3-Mar-08 6:21 
GeneralNxBre Pin
Tim Schwallie26-Jan-07 11:03
memberTim Schwallie26-Jan-07 11:03 
GeneralRe: NxBre Pin
Jeff Bramlett29-Jan-07 8:33
memberJeff Bramlett29-Jan-07 8:33 
GeneralThank you, this is impressive. Pin
Grav-Vt29-Nov-06 13:48
memberGrav-Vt29-Nov-06 13:48 
QuestionHow to create rules? Pin
victorvieira1-Nov-06 4:53
membervictorvieira1-Nov-06 4:53 
AnswerRe: How to create rules? Pin
jeff_bramlett@hotmail.com2-Nov-06 0:40
memberjeff_bramlett@hotmail.com2-Nov-06 0:40 
AnswerRe: How to create rules? Pin
jeff_bramlett@hotmail.com2-Nov-06 0:48
memberjeff_bramlett@hotmail.com2-Nov-06 0:48 
QuestionReturning a String result Pin
Rob_Jurado8-Sep-06 12:49
memberRob_Jurado8-Sep-06 12:49 
Questionlooking for a Trigger by name Pin
Rob_Jurado6-Sep-06 10:53
memberRob_Jurado6-Sep-06 10:53 
AnswerRe: looking for a Trigger by name Pin
Jeff Bramlett6-Sep-06 14:06
memberJeff Bramlett6-Sep-06 14:06 
GeneralNice work Pin
Rob_Jurado5-Sep-06 12:42
memberRob_Jurado5-Sep-06 12:42 
GeneralThanks for posting Pin
jruvelIGN30-Aug-06 7:15
memberjruvelIGN30-Aug-06 7:15 
GeneralRe: Thanks for posting Pin
Jeff Bramlett30-Aug-06 7:27
memberJeff Bramlett30-Aug-06 7:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151002.1 | Last Updated 29 Aug 2006
Article Copyright 2006 by Jeff Bramlett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid