| Samples > Rule Engine Integration > How to Execute Rules in the .NET Rule Engine |
How to Execute Rules in the .NET Rule Engine |
PREVIOUS NEXT |
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 include:
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:
JRules2DotNet sample in the Samples Console.
run.bat command to launch a full compilation, translation, and execution sequence as a single Windows batch command.
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.
run.java command, which executes the Java application using the compiled Java XOM and the data/archive.jar Ruleset Archive.
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.
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.
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.
run.net command, which runs the .NET 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:
true when the data is considered as valid, the second is true when the loan is approved)
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:
data/archive.jar. The ruleset archive that contains the rules for the engine in Java. This file is created as an export from the loanvalidation-rules rule project, which you can find in the directory: /studio/tutorials/shared/loanvalidation-rules.
Borrower.java, Loan.java and Report.java. These XOM class files are the same as the ones in the /studio/tutorials/shared/loanvalidation-xom Java project.
SimpleRuleEngineRunner.java. The application class that executes the loan validation rules on three different borrowers. This file is the same as the one used in the installdir/studio/tutorials/shared/loanvalidation-application Java project.
The C# source files are located in the directories CS/XOM/XOM and CS/Application. The main files used are:
generated/archive.dll. The generated ruleset assembly that contains the execution rules translated to the .NET XOM and system classes, using the data/archive.b2x mapping file.
Borrower.cs, Loan.cs, Report.cs. The XOM classes that is a port of the Java classes.
EntryPoint.cs. The application class that is a port of the SimpleRuleEngineRunner class.
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).
To rebuild the sample to its original state:
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |