Prerequisites: A valid RuleApplicationDef
Namespaces: InRule.Repository, InRule.Repository.EndPoints, InRule.Repository.ViewsAndControllers
Classes: RuleApplicationDef, XmlSchemaDef, XmlSchemaDefController, AssemblyDef,
AssemblyDefController
References: InRule.Repository.dll
The following examples demonstrate how to dynamically generate a rule application schema using a .NET assembly and an XSD.
Generate Rule Application Schema using an XSD
// Create the schema def object using a name for the schema and the path to the Xsd file
XmlSchemaDef schemaDef = new XmlSchemaDef("XsdSchemaName", FilePath + "invoice.xsd");
// Embed the schema in the rule app (optional)
schemaDef.UseEmbeddedXsd = true;
// Set whether validation should run when loaded (default is true)
schemaDef.EnableXsdValidation = true;
// Add the schema def object to the rule application as an end point
ruleAppDef.EndPoints.Add(schemaDef);
// Create the schema controller which will do the import of the Xsd
XmlSchemaDefController controller = new XmlSchemaDefController(schemaDef);
// Do the import
controller.Import(FilePath + "invoice.xsd");
// Generate the rule application schema
string[] applyWarns = controller.Apply();
// Process warnings if there were any
if (applyWarns.Length > 0)
{
// handle warnings/errors
}
// Bind Fields that map to xs:enumeration restriction types to a ValueList during import
schemaDef.BindEnumerationFieldsToValueLists = true;
// Disable creation of Constraint rules for Fields that map to xs:enumeration restriction types during import
schemaDef.CreateConstraintsForEnumerationFields = false;
Generate Rule Application Schema using a .NET Assembly
// Create Assembly and Assembly controller def objects, set isSchema to true
AssemblyDef assemblyDef = new AssemblyDef("InvoiceObject", true);
AssemblyDefController assemblyDefController = new AssemblyDefController(assemblyDef)
// Import the assembly, notes can be captured during import
string[] importNotes = assemblyDefController.Import("InvoiceObjects.dll").EntityDefsInfo.Notes;
// Get top level class by alias
AssemblyDef.ClassInfo topLevelClass = assemblyDef.ClassInfos.GetByAliasName("Invoice");
// Select all dependent entities for the top level class
assemblyDefController.CheckAllSelectedDependentEntities(topLevelClass);
// Add the assembly to the EndPoints collection (will appear as schema in irAuthor)
ruleAppDef.EndPoints.Add(assemblyDef);
// Generate the schema, notes can be captured during schema generation
string[] applyNotes = assemblyDefController.Apply();
// Bind Fields that map to Enum types to a ValueList during import
assemblyDef.BindEnumerationFieldsToValueLists = true;
// Disable creation of Constraint rules for Fields that map to Enum types during import
assemblyDef.CreateConstraintsForEnumerationFields = false;
Generate Rule Application Schema using a Database
// Create new end point
DatabaseConnection sch =
(DatabaseConnection)ruleAppDef.EndPoints.Add(new DatabaseConnection("DbConn1", connectionString));
// Set up end point to be a schema
sch.IsSchemaDefining = true;
// Create controller that will perform the import
DatabaseConnectionController controller = new DatabaseConnectionController(sch);
// Do the import
controller.Import();
// Apply changes to the rule app, catching any errors that may have occurred
string[] errors = controller.Apply();
Comments
0 comments
Please sign in to leave a comment.