| ILOG Rules for .NET User Guides > Rule Studio > Executing Rules > Retrieving Data and Events From the Engine |
Retrieving Data and Events From the Engine |
PREVIOUS NEXT |
To retrieve the values of the ruleset parameters when the ruleset has finished executing you use RuleEngine.GetParameterValues.
// Retrieve the value of ruleset parameters declared with the Out modifier IDictionary map = engine.GetParameterValues();
The rule engine API contains events that you can log to make sure that the ruleset executes correctly.
In ILOG Rules for .NET, you can trace rule execution using events.
The following sample shows how to trace:
When the events occur, the callbacks for the events are invoked. This implementation writes a string to the console window.
[C#]
public void MyMethod() {
// Create the rule engine
RuleEngine myEngine = new RuleEngine();
// Create the ruleset
RuleSet ruleset = new MyRuleSet();
// Register the 'RuleInstanceAdded'
// Agenda event
myEngine.Agenda.RuleInstanceAdded += new AgendaEventHandler(Agenda_RuleInstanceAdded);
// Register the 'ObjectAsserted'
// WorkingMemory event
myEngine.WorkingMemory.ObjectAsserted += new WorkingMemoryEventHandler(WorkingMemory_ObjectAsserted);
// Add an object into the working memory
myEngine.Assert(new MyBusinessObject());
// Launch the rule engine
myEngine.Execute();
// Reset the rule engine
myEngine.Reset();
}
private void Agenda_RuleInstanceAdded(object sender,
AgendaEventArgs args) {
Console.WriteLine(instance + " added to the agenda.");
}
private void WorkingMemory_ObjectAsserted(object sender,
WorkingMemoryEventArgs args) {
Console.WriteLine(obj + " added into the working memory.");
}
[Visual Basic]
Public Sub MyMethod() ` Create the rule engine Dim myEngine As RuleEngine = New RuleEngine ` Create the ruleset Dim ruleset As ruleset = New MyRuleSet ` Register the 'RuleInstanceAdded' ` Agenda event AddHandler myEngine.Agenda.RuleInstanceAdded, _ AddressOf Agenda_RuleInstanceAdded ` Register the 'ObjectAsserted' ` WorkingMemory event AddHandler myEngine.WorkingMemory.ObjectAsserted, _ AddressOf WorkingMemory_ObjectAsserted ` Add an object into the working memory myEngine.Assert(New MyBusinessObject) ` Launch the rule engine myEngine.Execute() ` Reset the rule engine myEngine.Reset() End Sub Private Sub Agenda_RuleInstanceAdded(ByVal sender As Object, _ ByVal args As AgendaEventArgs) Console.WriteLine(String.Concat(instance, " added to the agenda.")) End Sub `Agenda_RuleInstanceAdded Private Sub WorkingMemory_ObjectAsserted(ByVal sender As Object, _ ByVal args As WorkingMemoryEventArgs) Console.WriteLine(String.Concat(obj, " added into the working memory")) End Sub `WorkingMemory_ObjectAsserted
Engine Events Monitor Sample | Creating an Engine and Executing a Ruleset | Setting an Exception Handler on the Engine Execution
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |