Windows 工作流规则引擎 - 确定正在执行哪个规则
设置
我们正在使用 Windows 工作流规则引擎来实现折扣系统。我们的规则设置如下:
Rule Name: 10% Discount on Foo Chairs
Priority: 0
Reevaluation: Never
Active: True
Condition: this.MatchesSKUs("SKU1", "SKU2")
Then Actions: this.ForMatchingSkus.ApplyDiscount(.10m)
我们定义了多个此类规则,并且某些产品可能属于多个规则。在我们的“购物车”对象中,我们有一个执行规则引擎的方法。
var discountEngine = new DiscountEngine(discountRuleSetEnabled);
var execution = new RuleExecution(validation, discountEngine);
discountEngine.ruleExecution = execution;
if (discountRuleSet.RuleSet != null)
{ discountRuleSet.RuleSet.Execute(execution); }
折扣运作得很好,一切都几乎都很好。
问题
随着规则的执行,我需要跟踪实际使用的规则并提供折扣> 0. 例如,上面的规则最终运行该
ApplyDiscount(decimal discountPercent)
方法,该方法将折扣对象附加到购物车订单项。我需要知道这个“Apply Discount”实例是通过 10% Discount on Foo Chairs 规则调用的。我尝试了各种方法,但找不到每个规则的上下文传递的位置。我一直在查看 ActivityExecutionContext 对象,但在我设置的条件或操作方法中获取上下文时遇到问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论