Samples > Rule Engine Integration > How to Execute Rules in the .NET Rule Engine

This sample can only be opened and run in the Samples Console. The Java and .NET files for this sample are located in <InstallDir>/jrules2dotnet/samples/JRules2DotNet.

The sample shows how to convert a JRules ruleset archive to a ruleset assembly that is loadable by the .NET rule engine. The complete chain is shown: compilation in Java, execution in Java, repackaging of the ruleset, compilation in C#, execution in C#.

Note
This sample only works on the Microsoft Windows platform if you have .NET 2.0 framework and Visual JSharp 2.0, or Visual Studio .NET 2005 correctly installed.

In this sample, Rule Studio has been used to write rules against a Java XOM. The rule project contains a ruleflow, ruleset parameters, BAL rules and decision tables. The ruleflow consists of a main flow task, several rule tasks that use different engine algorithms, and some ruleflow guards. The ruleset archive has been pre-generated and is considered as a piece of data.

When the sample is run, the Java XOM and application are compiled and the application is executed using the ruleset, to serve as a reference for the subsequent .NET execution.

The ruleset archive extracted from the rule project is then repackaged into its .NET equivalent, a ruleset assembly.

The .NET XOM is then compiled using Microsoft .NET compilation tools and the .NET application is compiled using Microsoft .NET compilation tools. The .NET application is then executed with this ruleset assembly and you can compare the execution result with the execution result from the previous Java execution to see that they are identical.

Key Features

Key features include:

Running this Sample

This sample can only be opened and run in the Samples Console. The Java and .NET files for this sample are located in <InstallDir>/jrules2dotnet/samples/JRules2DotNet.

To run this sample:

  1. Locate the JRules2DotNet sample in the Samples Console.
  2. Execute the run.bat command to launch a full compilation, translation, and execution sequence as a single Windows batch command.
  3. Or:
    Execute the run command, which launches the following sequence of Ant tasks:
    1. The build.java command, which builds the Java source files contained in the java/XOM/src and java/Application/src directories and places them in the java/XOM/classes and java/Application/classes directories respectively.
    2. The run.java command, which executes the Java application using the compiled Java XOM and the data/archive.jar Ruleset Archive.
    3. The build.xom.net command compiles the .NET XOM into an assembly. This command uses Microsoft .NET Framework 2.0 tools to build the CS/XOM solution.
    4. The build.app.net command, which compiles the .NET application into an executable file. This command uses Microsoft .NET Framework 2.0 tools to build the CS/Application solution.
    5. The package.net command, which packages the data\archive.jar ruleset archive with the data\archive.b2x mapping file into the generated\archive.dll .NET ruleset assembly for the .NET Rule engine.
    6. The run.net command, which runs the .NET application.
  4. Compare the results with the Java reference application.

In both the Java and .NET applications, three different borrowers apply for different loans, and a report is computed. The first loan is accepted, the second loan is rejected because the incoming data is detected by the rules as invalid, the third loan is rejected because the debt would be too high for the borrower's income.

In each case, after the ruleset is executed, the following information is displayed:

Source Files

This sample is located in <InstallDir>/jrules2dotnet/samples/JRules2DotNet.

The Java source files are in the directories java/XOM/src and java/Application/src. The main files used are:

The C# source files are located in the directories CS/XOM/XOM and CS/Application. The main files used are:

Highlights

The build.xml file shows how to automate the generation of a .NET ruleset assembly from a JRules ruleset archive in Java-centric production environments. The MSBuild.exe tool is not in the system path, so the Ant script locates it in the installation directory of the .NET framework.

The run.bat file shows how to automate the generation of a .NET ruleset assembly from a JRules ruleset archive in a .NET-centric production environment. The run.bat script first compiles and runs the rule application in Java, then delegates the compilation, packaging and execution of the .NET rule application to a Build.csproj file. The Build.csproj file is then executed by the .NET framework's MSBuild.exe tool.

The ruleset packager requires the Microsoft .NET Framework 2.0 and Visual JSharp 2.0 to be installed. A full install of Visual Studio 2005 includes these two packages.

The compilation of rule-based .NET applications requires only the Microsoft .NET Framework 2.0, the ILOG.Rules.JRules2DotNet.dll and ILOG.Rules.RuleEngine.dll assemblies. The ruleset assembly is not required for compilation as it is loaded at runtime (as can be seen in the Entrypoint.cs file).

Rebuilding this Sample

To rebuild the sample to its original state:

  1. Execute the clean target
  2. The run.bat or the run targets rebuild and execute everything.

Related Concepts

Deployment to .NET

Related Tasks

Deploying Rules to .NET

Related Reference

JRules to .NET Tools

Related Samples and Tutorials

Import Samples and Tutorials Wizard