I am trying to build Rules with my custom UI and execute with CodeDom for my workflow module. I don’t want to use the Rules interface which is given with WF. In order to build/ execute a Rule, I am creating a Condition and ThenAction/ElseActions. At present I am able to execute a single condition successfully. Means Suppose an Order Entity is there with the properties like OrderID, Amount, NoOfItems, Discount, and TotalAmount.
Able to Build the Below condition:
if (this.Amount > 1000)
thisDiscount = 100;
Building Left / Right conditions:
CodePropertyReferenceExpression technologyRef = new CodePropertyReferenceExpression(thisRef, " Amount");
CodePrimitiveExpression wfConstant = new CodePrimitiveExpression(1000);
// if ( this. Amount > 1000)
CodeBinaryOperatorExpression cond = new CodeBinaryOperatorExpression();
cond.Left = technologyRef;
cond.Operator = CodeBinaryOperatorType.GreaterThanOrEqual;
cond.Right = wfConstant;
Rule rule = new Rule("rule1");
rule.Condition = new RuleExpressionCondition(cond);
Not Able to Build the Below condition:
if (this.Amount > 1000 && NoOfItems > 5)
thisDiscount = 150;
Can anyone help me to build multiple conditions for a Rule? Means validation on multiple properties in a single IF statement.
The tree for your first condition would look something like this:
<
/ \
Amount 1000
And that's exactly how you represented it in your code: one CodeBinaryOperatorExpression
for the <
and then an expression for each of the children. Doing the same for the second expression is almost the same, but the tree will be bigger:
-----&&-----
/ \
< >
/ \ / \
Amount 1000 NoOfItems 5
That is, you will have one CodeBinaryOperatorExpression
that represents the &&
(CodeBinaryOperatorType.BooleanAnd
), whose left child will be the <
node and its right child will be the >
node.