Understanding the Workflow Runtime Engine
To illustrate defining a declarative rule condition, you will modify the previous While activity. First, you need to set the Condition property of the While activity to Declarative Rule Condition, rather than Code Condition. At this point, the existing GetAndValidateUserName() method could be deleted, as it will no longer be used. You also need to provide a new way to obtain the user name, as this was done in the GetAndValidateUserName() method.
Next, you need to give your declarative rule a name and conditional statement. This can be done using the integrated rule editor of Visual Studio. Simply click on the ellipse button (…) option of the ConditionName property.
Once you click the New button, you can then define the rule. Notice the following:
- You have access to the members of the WF class.
- You are specifying the same condition you entered in the previous GetAndValidateUserName() method.
You can enter either C# or VB code in the rule editor. However, once you click the OK button, VB tokens such as the Me keyword are automatically translated into C# equivalents (e.g., the this keyword).
After you click the OK button, you have a chance to name your condition. Assume you have named your condition IsNameLengthValid. Here is the end result of your operations.
When you define declarative rules, the IDE will create a brand-new *.rules file that is connected to the current workflow instance. You can view this new file via the Solution Explorer.
If you were to open this *.rules file, you would find markup similar to the following. Notice that there are ‘left’ and ‘right’ sides of the expression. Also notice the CodeBinaryOperatorExpression element defines an attribute named Operator, which represents the binary operator used in the rule.
The data within a *.rules file can either be shipped as a standalone file or embedded within the assembly as a binary resource. The default behavior is to embed the markup as a binary resource. If necessary, stand alone *.rules files can be dynamically read in to memory at runtime.
Copyright (c) 2008-2013. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.