Embedding InRule Default Editors

  • Updated

Namespaces: InRule.Repository, InRule.Repository.RuleElements, InRule.Authoring.Controls,
InRule.Authoring.Editors, InRule.Authoring.Editors.Controls
Classes:   RuleApplicationDef, ControlFactory
See Also: Opening a RuleApplicationDef for Authoring, WinForm Considerations
References: InRule.Repository.dll, InRule.Authoring.dll, InRule.Authoring.BusinessLanguage.dll, InRule.Authoring.Editors.dll, InRule.Common.dll

Loading the default editors

The following code works in WPF.  This same code can be used for retrieving all editors as the GetControl method takes a RuleRepositoryDefBase type.  The editor that is returned is based on the type of definition object that is passed in.  In this example, the Fire Notification Action is used.

// Create an instance of the control factory (consider keeping this at form level to reuse where
appropriate)
ControlFactory controlFactory = new ControlFactory();

// Load ruleapplicationdef
RuleApplicationDef ruleAppDef = RuleApplicationDef.Load(@"c:\work\mortgagecalculator.ruleapp");

// Load the rule application into the control factory
controlFactory.OpenRuleApplication(ruleAppDef);

// Get the entity
EntityDef entityDef = ruleAppDef.Entities["Mortgage"];

// Get the rule to edit (any RuleRepositoryDefBase can be passed in)
FireNotificationActionDef ruleDef = (FireNotificationActionDef)entityDef.GetRuleSet("PaymentRules").Rules["PaymentNotification"];

// Get the business language editor and load into ContentControl
var control = controlFactory.GetControl(ruleAppDef);

Saving the changes

// Get the control from the form
if (control is IValidatingEditor)
{
 // Save the changes back to the rule application
 ((IValidatingEditor)control).SaveValues();
}

// Dispose of the control if it implements IDisposable
if (control is IDisposable)
{
 ((IDisposable)control).Dispose();
}

// Save the rule application back to the file system (this can also be saved to the Catalog)
ruleAppDef.SaveToFile(@"c:\work\mortgagecalculator.ruleapp");

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.