Assemblies required
The minimal assemblies required for embedding InRule controls for WPF (unless otherwise noted) include the following:
Assembly Name |
InRule.Authoring |
InRule.Authoring.BusinessLanguage |
InRule.Authoring.Editors |
InRule.Authoring.Windows |
InRule.Common |
InRule.Repository |
WPF assemblies are located in <InRule installation directory>\irSDK\bin.
Control Factory
The Control Factory is a class in The Rule Authoring Framework that abstracts much of the code required to create an instance of a control that can edit an InRule definition object (Entity, Rule Set, Rule, etc). The job of the Control Factory is to provide a control based on the type of object which is passed in.
Process
The typical process for embedding one of InRule's controls in WPF is as follows:
- Create an instance of the ControlFactory
- Load the Rule Application
- Load the Rule Application into the Control Factory
- Get the desired rule to be edited
- Call the GetControl method on the Control Factory passing the definition object to be edited.
- Load the control into the form. A common approach is to use the ContentControl available in WPF.
Sample code:
// Create control factory
var _controlFactory = new ControlFactory();
// Load the rule app
var _ruleAppDef = RuleApplicationDef.Load(@"C:\work\MortgageCalculator.ruleapp");
// Load the rule app into the control factory
_controlFactory.OpenRuleApplication(_ruleAppDef);
RuleSetDef langRule = _ruleAppDef.GetRuleSet("ValidateLoanInfo");
// Get the control and load it into the content control in the form
contentControl.Content = _controlFactory.GetControl(langRule);
Please see Embedding InRule Default Editors for more details.
Saving
Any changes that are made in an embedded control must be saved back to the rule application. Some changes are saved automatically back to the rule application. However, it is best to call the SaveValues method as shown below to ensure everything is saved correctly. Here is the code required to perform the save.
Note: This saves changes the RuleApplicationDef that is in memory, saving back to the file system or Catalog is a separate operation.
public void SaveRule(IValidatingEditor editor)
{
if (editor != null)
{
editor.SaveValues();
}
}
Controls with Display Options
Using the ControlFactory's GetControl method as described above will return the entire control as it is seen in irAuthor. This includes a label and image based on the type of control, a text box for updating the object's Name and a check box for enabling/disabling rules (if applicable). There are cases where it may not be desirable to have the entire editor displayed in an application. For this reason, the most commonly used controls can also be embedded without these extra items. The controls available in this manner are the Business Language, Decision Table and Condition editors. See Embedding the Language Rule Editor, Embedding the Decision Table Editor and Embedding the Condition Editor for samples of each.
Comments
0 comments
Please sign in to leave a comment.