Next Topic »
Using Rule Editor
Rule Editor is the client-side tool that is used by rule authors to create new business rules or load existing ones for modification, validation, or deletion.
Rule Editor consists of three elements:
is an optional UI element that sits on top of Rule Editor and helps to manage rules, and is enabled by default. Set the value of RuleEditor.ShowToolBar to False to remove it from the UI. This is an important piece of Code Effects' UI that deserves its own documentation topic.
Help String is an optional line of text that appears between the Toolbar and Rule Area, which helps the rule author to navigate through the rule elements as (s)he creates or modifies the rule. It also warns users about any kind of failure or exception. By default, this element is turned on and displays default English messages. Set the value of RuleEditor.ShowHelpString to False to remove it from the UI. All messages displayed by the Help Sting can be modified or even translated into other languages by utilizing the Help XML feature of Code Effects.
Rule Area is the panel at the bottom of Rule Editor that holds all elements of the business rule that the rule author is currently working on. Unless noted otherwise, the rest of this topic discusses the use of this Rule Editor element and its features.
You can change all default UI labels and messages to your own values by using the Help XML feature of the Rule Editor.
Users can use keyboard and gestures to auther business rules in the Rule Editor. We also support the Cut, Copy and Paste of rule elements. Details can be found in this article.
Rule Editor can operate in one of four modes, and it is very important that you understand what the modes are and how they operate.
When you first load a page with Rule Editor on it, the Rule Area will contain no rule elements, displaying only a default instructional message. Click inside the Rule Area, and select any field from the context menu. Note that Rule Editor now contains the initial if flow element and the field that you just selected. Now, select an operator from the next menu, enter the value of the condition, select a clause, and so on, and so forth. If enabled, the Help String displays dynamic instructions on what to do next.
As you can see, the Rule Editor allows you to build business rules of any complexity with no predefined UI controls to deal with or complicated formats to follow. To create a new rule, select the corresponding option from the Toolbar's Rules menu, add rule conditions to the Rule Area, name the rule, and save it. To load the existing rule for editing, select its name from the same Rules menu (assuming that your code loaded that rule in the menu when the page was loading.) (Re)name the rule, optionally describe it, and click the Save button to save the changes. Click the Delete button to delete the currently loaded rule. (The Delete button appears in the Toolbar only when an existing rule is loaded)
One of the most popular features of Code Effects' UI is its use of parentheses to set the order in which rule conditions are evaluated. Most traditional business rules engines require rule conditions to be manually combined into a large ruleset, with evaluation order/priority/salience being set for each individual condition. Code Effects business rules editor changes all that; its parentheses work intuitively:
Parentheses appear as the first item in relevant context menus. Rule Editor knows when to offer the opening parenthesis and where the closing one could be.
Note that the built-in rule validation (described in the next section) enforces the logical consistency of or and and clauses that "connect" conditions inside of a single rule level. This sounds complicated, but, in reality, it's not. You can get details by reading the Code Effects Basics topic (look for the definition of Clauses in there), but in simple terms, you cannot have different clauses on the same level (a level is a group of conditions separated by a single pair of parentheses). Examples:
NO: Check if ( A is B and C is not D or E is less than F )
YES: Check if ( A is B C is not D E is less than F )
YES: Check if (A is B C is not D E is less than F )
Most modern compilers and script interpreters evaluate the line if ( A == B && C != D || E < F ) to either True or False depending on the rules that they enforce internally, while the Rule Editor prefers not to confuse rule authors. Logically speaking, levels with different clauses are invalid, therefore, the rule validation treats such levels as invalid. Obviously, if a rule must have conditions joined by different clauses, the rule author can simply place each clause in its own level:
YES: Check if ( A is B ( C is not D E is less than F ) )
Automatic Rule Validation
Code Effects business rules engine comes with automatic rule validation. Every time a rule author tries to save or update a rule, Rule Editor forces it through its internal validation process. All your code has to do is to check if the value of the RuleEditor.IsValid property is True before continuing to save it:
if (ruleControl.IsEmpty || !ruleControl.IsValid)
// You don't really need to do anything if the rule is invalid, the Help String
// will display a proper error message demonstrated in the screenshot below
If the current rule is invalid, the Help String displays a warning message and the Rule Editor highlights each invalid element, allowing the rule author to hover the mouse over it to see the description of that particular problem.
Post your questions about Code Effects on Stackoverflow
and become a part of our growing community