1

SETUP

We are using the Windows Workflow Rules Engine to implement a discounting system. Our rule setup is as follows:

Rule Name: 10% Discount on Foo Chairs
Priority: 0
Reevaluation: Never
Active: True
Condition: this.MatchesSKUs("SKU1", "SKU2")
Then Actions: this.ForMatchingSkus.ApplyDiscount(.10m)

We have several such rules defined and some products may fall under more than one rule. Within our "cart" object we have a method that executes the rule engine.

var discountEngine = new DiscountEngine(discountRuleSetEnabled);
var execution = new RuleExecution(validation, discountEngine);
discountEngine.ruleExecution = execution;
if (discountRuleSet.RuleSet != null)
{ discountRuleSet.RuleSet.Execute(execution); }

Discounts are working all well and good and everything is almost fine.

ISSUE

As the rules are executing I need to keep track of rules that are actually used and provide a discount > 0. For instance the rule above ultimately runs the

ApplyDiscount(decimal discountPercent)

method, which tacks on a discount object to the cart line item. I need to know that this instance of "Apply Discount" was called via the 10% Discount on Foo Chairs rule. I've tried various methods but can't find where the context of each rule is passed along. I've been looking at the ActivityExecutionContext object but I'm having trouble getting the context within the condition or action methods that I have setup.

4
  • 3
    I know nothing about WF but have experience with several other rules engines. Just out of curiosity: what do you do if the business decides to change a condition, or priority, or action of any of your rule? Re-test, re-compile, re-deploy?
    – user896952
    Oct 16, 2011 at 4:44
  • We have a test set we can run through before we publish any rule changes to the live environment.
    – user26901
    Oct 16, 2011 at 15:36
  • But you do have to recompile the project, right?
    – user896952
    Oct 16, 2011 at 15:41
  • No, the rules are serialized into an XML string and stored in the database. The Workflow Foundation has a control that allows you to design the rules and we just save them to the database.
    – user26901
    Oct 17, 2011 at 0:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.