Welcome

You have reached the blog of Keith Elder. Thank you for visiting! Feel free to click the twitter icon to the right and follow me on twitter.

Building an English-Based Rules Engine in .NET with IronRuby Slides and Demo

Posted by Keith Elder | Posted in .Net, C#, CodeMash, IronRuby, Presentations, Speaking | Posted on 19-01-2012

3

As promised at CodeMash to those that attended my session I finally am getting around to getting the slides and demo from my talk posted to my web server. You can download everything at this URL location:

http://keithelder.net/Presentations/RulesEngineWithIronRuby/RulesEngineWithIronRuby.zip 

What you will need to run the demo:

  • Visual Studio 2010

To run the demo you should be able unzip it, open it up in Visual Studio and hit F5.

Once the demo opens you’ll be presented with this.

SNAGHTML29cde5e7

In the middle of the screen you’ll see sample rules for the survey already loaded.

To convert these rules to Ruby script click on the “SurveyRuleSet” option listed under “Rule Sets”. This will load all of the available rules for that rule set.

SNAGHTML29d09da1

Once you have the rules loaded for the SurveyRuleSet you can then click “Convert To Ruby Script” button and the English text in the middle of the page will be converted into Ruby Script.

SNAGHTML29d205e5

Once you have the Ruby script generated click the “Use Script in Survey”.

SNAGHTML29d4666b

This will open a form that has questions and answers.

SNAGHTML29d5267f

Once the form is open just press “Submit” and the rules will fire. You can close the form, change the rules, re-gen the script and then re-run the form to see new rule values run.

When the “Submit” button on the Survey form is called, this is when the IronRuby engine gets invoked.

You can also load the SouthernRuleSet and then load the pre-typed Southern rules to see a “Southern DSL” of the same rules.

In Visual Studio you can open the SurveyRuleSet.cs file and uncomment the other attributes to enable Spanish instead of English (just as an example).

DISCLAIMER

What you should try to take away from this the most are what it is doing and what is possible. We are running something very similar to this in production so this isn’t smoke and mirrors. There are a lot of things that are missing in the demo, but they are completely doable with some additional work. For example grouping isn’t done in this example, other rules like greater than, lesser than etc could all be added to the base ruleset class. Use your imagination and go wild.

Enjoy.