Click here to Skip to main content
Click here to Skip to main content

Use Rules In Your Applications

, 29 Aug 2006 CPOL
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

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)

Share

About the Author

Jeff Bramlett
Software Developer (Senior)
United States United States
Website: http://www.somedeveloper.us

Comments and Discussions

 
GeneralThe License is LGPL not CPOL PinmemberCyborgDE11-Jun-11 4:38 
QuestionHow to match variables plz. help me [modified] PinmemberShyamPrasadP5-Dec-10 21:05 
GeneralQuestion Pinmemberchazim12-Nov-10 9:20 
GeneralRe: Question PinmemberJeff Bramlett12-Nov-10 16:03 
GeneralRe: Question Pinmemberterryterryd14-Apr-11 3:08 
GeneralRe: Question PinmemberJeff Bramlett12-Nov-10 16:05 
QuestionHow to use loops PinmemberSumit Prakash Sharma20-Apr-09 3:17 
QuestionNeed Help ! Pinmemberrajalakshmiam17-Apr-09 0:51 
GeneralBroken Links Pinmemberchris lambrou1-Mar-09 20:05 
GeneralGUI for making new rules and editing the existing one PinmemberBanty Nigam12-Feb-09 21:29 
NewsGood article PinmemberArash Aghlara2-Aug-08 23:12 
GeneralAuthor's Web Site Pinmembervextant10-Feb-08 19:15 
GeneralRe: Author's Web Site PinmemberARUVAL3-Mar-08 7:21 
GeneralNxBre PinmemberTim Schwallie26-Jan-07 12:03 
GeneralRe: NxBre PinmemberJeff Bramlett29-Jan-07 9:33 
GeneralThank you, this is impressive. PinmemberGrav-Vt29-Nov-06 14:48 
QuestionHow to create rules? Pinmembervictorvieira1-Nov-06 5:53 
AnswerRe: How to create rules? Pinmemberjeff_bramlett@hotmail.com2-Nov-06 1:40 
AnswerRe: How to create rules? Pinmemberjeff_bramlett@hotmail.com2-Nov-06 1:48 
QuestionReturning a String result PinmemberRob_Jurado8-Sep-06 13:49 
Questionlooking for a Trigger by name PinmemberRob_Jurado6-Sep-06 11:53 
AnswerRe: looking for a Trigger by name PinmemberJeff Bramlett6-Sep-06 15:06 
GeneralNice work PinmemberRob_Jurado5-Sep-06 13:42 
GeneralThanks for posting PinmemberjruvelIGN30-Aug-06 8:15 
GeneralRe: Thanks for posting PinmemberJeff Bramlett30-Aug-06 8: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.141220.1 | Last Updated 29 Aug 2006
Article Copyright 2006 by Jeff Bramlett
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid