Creating and executing a rule engine for .NET

To create and run a rule engine for .NET object, you create the engine object, build the working memory, set the parameters, and execute.

About this task

The following example shows you how to create and execute a rule engine.

Procedure

To create and execute a rule engine for .NET object:

  1. Create the engine object.
    RuleFlowEngine engine = engineDefinition.CreateEngine();
  2. Build the working memory by adding objects and ruleset parameter values.
    ICollection<Object> wm = new List<Object>();
    wm.Add( myObject1 );
    ...
    wm.Add( myObjectN);
    EngineInput input = engine.CreateEngineInput();
    input.WorkingMemory = wm;
  3. Set the parameters if applicable.
    input["myParameter"] = myValue;
  4. Run the engine.
    try {
     EngineOutput output = engine.Execute( input );
    catch ( Exception e ) {
    ...
    }

Example

Here is the entire code sample.

RuleFlowEngine engine = engineDefinition.CreateEngine();
ICollection<Object> wm = new List<Object>();
wm.Add( myObject1 );
...
wm.Add( myObjectN);
EngineInput input = engine.CreateEngineInput();
input.WorkingMemory = wm;
input["myParameter"] = myValue;
try {
 EngineOutput output = engine.Execute( input );
catch ( Exception e ) {
...
}