Click here to Skip to main content
6,595,444 members and growing! (14,809 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
Views:40,990
Bookmarked:58 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
18 votes for this article.
Popularity: 5.79 Rating: 4.61 out of 5
1 vote, 5.6%
1
1 vote, 5.6%
2

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


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

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
GeneralHow to use loops PinmemberSumit Prakash Sharma3:17 20 Apr '09  
QuestionNeed Help ! Pinmemberrajalakshmiam0:51 17 Apr '09  
GeneralBroken Links Pinmemberchris lambrou20:05 1 Mar '09  
GeneralGUI for making new rules and editing the existing one PinmemberBanty Nigam21:29 12 Feb '09  
NewsGood article PinmemberArash Aghlara23:12 2 Aug '08  
GeneralAuthor's Web Site Pinmembervextant19:15 10 Feb '08  
GeneralRe: Author's Web Site PinmemberARUVAL7:21 3 Mar '08  
GeneralNxBre PinmemberTim Schwallie12:03 26 Jan '07  
GeneralRe: NxBre PinmemberJeff Bramlett9:33 29 Jan '07  
GeneralThank you, this is impressive. PinmemberGrav-Vt14:48 29 Nov '06  
GeneralHow to create rules? Pinmembervictorvieira5:53 1 Nov '06  
AnswerRe: How to create rules? Pinmemberjeff_bramlett@hotmail.com1:40 2 Nov '06  
GeneralRe: How to create rules? Pinmemberjeff_bramlett@hotmail.com1:48 2 Nov '06  
QuestionReturning a String result PinmemberRob_Jurado13:49 8 Sep '06  
Questionlooking for a Trigger by name PinmemberRob_Jurado11:53 6 Sep '06  
AnswerRe: looking for a Trigger by name PinmemberJeff Bramlett15:06 6 Sep '06  
GeneralNice work PinmemberRob_Jurado13:42 5 Sep '06  
GeneralThanks for posting PinmemberjruvelIGN8:15 30 Aug '06  
GeneralRe: Thanks for posting PinmemberJeff 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-2009
Web16 | Advertise on the Code Project