Question

I have requirement to build new rule engine in which i have rule like this which is stored in Excel sheet, in tabular format.

<If>  "Name = Nita "
<Value> "200"
<else> "Name = Gita"
<value> "300"
<LookInto> "/Name/@Income"

I have two files say 1 n 2. i need to see in first file that whether Name is Nita or Gita. Based on execution i will get value. Now this result value i need to compare with second file , which is a xml file and whose path has been defined into .

can anybody suggest me that is there anything in C# that i can use effectively to develop the same,, or can anybody suggest me how i can achieve this with C#.. i need some idea for class design of the same.

I am using .Net 1.1.

Was it helpful?

Solution

Firstly, you need to create classes that can define your rules. Once you have this structure in place, you will be able to build an engine that utilises those classes.

I would look at creating something like:

class RuleEngine 
{
  public RuleMatch[] RuleMatches { get; set; }
  public void RunEngine(inputdata...) 
  {  
    // do processing in here
  }
}

class RuleMatch 
{
  public Rule[] Rules { get; set; }
  public Object ValueIfMatched { get; set; }
}

class Rule 
{
  public String FieldName { get; set; }
  public MatchType Match { get; set; }
  public Object Value { get; set; }
)

enum MatchType 
{
  Equal = 1,
  NotEqual = 2,
  GreaterThan = 4,
  LessThan = 8,
  Like = 16
}

Then go on from there....

This structure would be better if it was changed to have a group of rules that could be added to a group of rules, for example (a AND b) OR (c AND d) - I'll leave this to you to think about for now.


Please note I'm using some C# 3.0 constructs here, you will need to create full private properties in 1.1.

OTHER TIPS

You could create a DSL with boo, but I don't know if that will work with 1.1

You're going to be very limited by .NET 1.1. I think your first step will be to upgrade.

Subsequent steps could involve the rules engine built into Windows Workflow Foundation; this engine, and the graphical designers associated with it, were designed to be usable outside of WF.

Another thing to look at will be the Validation Application Block that is part of the Microsoft Enterprise Library.

None of these things existed six years ago when .NET 1.1 ruled the Earth.

Or you could just let someone else do this work and use a good .NET rules engine like InRule Technology's product, IBM/ILOG Rules for .Net or Blaze Advisor for .Net. They work well and will give you a powerful rules environment in .Net

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top