| ILOG Rules for .NET User Guides > Rule Studio > Executing Rules > Creating an Engine and Executing a Ruleset |
Creating an Engine and Executing a Ruleset |
PREVIOUS NEXT |
To embed the rule engine into an application, you only need to add a few lines to create a rule engine, add objects to the working memory, load a ruleset and execute it.
// Create a rule engine instance. RuleEngine engine = new RuleEngine(); // Select the ruleset to be used. engine.RuleSet = new RuleProjectName();
To use ruleset parameters to present objects to the rule engine you use RuleEngine.SetParameterValue and RuleEngine.SetParameterValues.
// Set the ruleset parameters.
engine.SetParameterValue("parameterName", parameterValue);
engine.SetParameterValue("parameterName", parameterValue);
...
// Set the ruleflow on the engine.
engine.Ruleflow = engine.RuleSet.Ruleflows["package","ruleflow name"];
// Execute the business rules.
engine.Execute();
// Prepare the rule engine for another execution.
engine.RetractAll();
engine.Reset();
For example:
[C#]
using ILOG.Rules;
using CustomerBOM; // the business object model
...
RuleEngine engine = new RuleEngine();
engine.RuleSet = new CustomerRules();
Person billy = new Person(); // the object of interest
billy.name = "Billy";
engine.SetParameterValue("applicant", billy); // set the ruleset parameter
// Set the ruleflow - the Applications ruleflow in the CustomerRules package
engine.Ruleflow = engine.RuleSet.Ruleflows["CustomerRules", "Applications"];
engine.Execute();
engine.RetractAll();
engine.Reset();
[Visual Basic]
Imports ILOG.Rules
Imports CustomerBOM `the business object model
...
Dim engine As New RuleEngine
engine.RuleSet = New CustomerRules `the rules to execute
Dim billy As New Customer `the object of interest
billy.name = "Billy"
engine.SetParameterValue("applicant", billy)
`Set the ruleflow - the Applications ruleflow in the CustomerRules package.
engine.Ruleflow = engine.RuleSet.Ruleflows("CustomerRules", "Applications")
engine.Execute()
`Prepare the rule engine for another execution.
engine.RetractAll()
engine.Reset()
Rule Execution Modes | Retrieving Data and Events From the Engine | Setting an Exception Handler on the Engine Execution | Rule Application Sample | Reloading a Ruleset at Runtime
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |