| ILOG Rules for .NET User Guides > Walkthroughs > Walkthrough: Hello World |
Walkthrough: Hello World |
PREVIOUS NEXT |
This walkthrough presents the following fundamental procedures for creating a business rule application with ILOG Rules for .NET.
In this walkthrough, you create a console application that uses a very simple business rule to display a message in a command window.
You develop business rule applications for the .NET environment within a Visual Studio solution.
The business object model defines the business domain: the things of interest to the business, and a vocabulary for writing rules about them. The vocabulary of the business rules is implemented as annotations to the types in the business object model.
To set up the business object model you:
using System;
namespace ClassLibrary1{
// Class to print a message
public class Message
{
// Prints a message to the console
public void PrintMessage(string msg)
{
Console.WriteLine(msg);
}
}
}
Imports System
' Class to print a message
Public Class Message
' Prints a message to the console
Public Sub PrintMessage(ByVal msg As String)
Console.WriteLine(msg)
End Sub
End Class
The business logic of an application is the part that implements the policies of the business. For example, the following is a policy that could be part of the business logic of an application that manages company's relationship with its customers: clients in the Gold service program are upgraded to the Platinum service program after they have renewed their annual subscription five times.
In ILOG Rules for .NET you implement the business logic of an application using business rules. To define the business logic for this business rule application you:
The completed rule reads as follows:
Then print the Message: "Hello world!";
| Note |
| This business rule has no conditions and, therefore, always executes. Typically, however, business rules have conditions that must be met for the rules to be executed. |
The application logic of an application is the part that performs tasks such as database management, and handling interactions with users. In a business rule application, the application logic includes the part of the application that embeds the rule engine, which executes business rules. Using a rule engine enables you to manage the business logic with processes external to the application.
To define the application logic you:
using System;
using System.IO;
using ILOG.Rules;
using ClassLibrary1;
namespace ConsoleApplication1{
public class RuleExecuter{
public static void Main(){
// Create a rule engine in which to execute the ruleset.
RuleEngine engine = new RuleEngine();
// Create the message object which is the subject of the
// rules in the ruleset.
Message hello = new Message();
// Load the ruleset into the rule engine.
// The ruleset is generated when you build the rule project.
engine.RuleSet = new BusinessRules1();
// Add the object to the rule engine's working memory.
engine.Assert(hello);
// Execute the ruleset.
// The rule engine evaluates the conditions in the ruleset
// using the objects in the working memory. The rule
// engine initiates the actions of the rules whose
// conditions are true.
engine.Execute();
//Get the user's input to quit the application.
Console.WriteLine();
Console.WriteLine("To exit, press ENTER.");
Console.In.ReadLine();
}
}
}
Imports System
Imports System.IO
Imports ClassLibrary1
Imports ILOG.Rules
Module Module1
Sub Main()
' Create a rule engine in which to execute the ruleset.
Dim engine As New RuleEngine
' Load the ruleset into the rule engine.
' The ruleset is generated when you build the rule project.
engine.RuleSet = New BusinessRules1
' Create the message object which is the subject of the
' rules in the ruleset.
Dim hello As New Message
' Add the object to the rule engine's working memory.
engine.Assert(hello)
' Execute the ruleset.
' The rule engine evaluates the conditions in the ruleset
' using the objects in the working memory. The rule
' engine initiates the actions of the rules whose
' conditions are true.
engine.Execute()
' Get the user's input to quit the application.
Console.WriteLine()
Console.WriteLine("Press ENTER to exit.")
Console.In.ReadLine()
End Sub
End Module
You can test the business rule application within Visual Studio.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |