1 / 19

Using the Workflow Foundation Rule Engine without using Workflow Foundation

Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group. Using the Workflow Foundation Rule Engine without using Workflow Foundation. My Story – Great Expectations. “... The rule engine will take care of that ...”

alena
Download Presentation

Using the Workflow Foundation Rule Engine without using Workflow Foundation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group Using the Workflow Foundation Rule Engine without using Workflow Foundation

  2. My Story – Great Expectations • “... The rule engine will take care of that ...” • “... Certainly the rule engine is flexible enough to add new rules ...” • “... Ahhh ... That’s just a business rule we’ll add ...” • “... We’ll need a complex busines rule engine to cater for all the scenarios ...” • “ ... We’ll update the rule engine ...”

  3. Typical Examples • Calculate tax, discount, etc • Medical claim assessment • Add message to account/order • Creating gift vouchers • Adding a free item based on your order • Fraud checking • Error and Message Logging

  4. The essence of a rule • if (condition) then (action1) else (action2) • if person's age is greater than 55 then discount = discount + 10% • if discount is greater than 12% then discount = 12%

  5. What should the “Rule Engine” do? • Ability to add rules on the fly • BONUS: easy editor • DOUBLE BONUS: a “busines person” can add rules • Save the rules (and load them) • Use .net objects used by application • Easy to hook into from application / domain layer • Let me code – no rule theory degree needed

  6. What are the options? • Code the rules in your code (not too flexible) • Create your own scripting language • Dependency Injection • Rule engines • Open source • C# - Drools.Net, NxBRE, SRE • Java – Drools, OpenRules, Mandarax, SweetRules • Third party • Use the WF rule engine (thanks Google!)

  7. WF – Workflow Foundation

  8. Using the Rules Engine • Add References • System.Workflow.Activities • System.Workflow.ComponentModel • Create Instance of RuleSet • RuleSet rules = new RuleSet();

  9. Using the Rules Engine (cont.) • Load Rules from file using (XmlTextReaderrulesReader = new XmlTextReader(filename)) { WorkflowMarkupSerializerserializer = new WorkflowMarkupSerializer(); rules = (RuleSet)serializer.Deserialize(rulesReader); }

  10. Using the Rules Engine (cont.) • Apply RulesRuleValidation validation = new RuleValidation(typeof(Order), null); RuleExecution execution = new RuleExecution(validation, newOrder); rules.Execute(execution);

  11. Demo – the basics • Loading rules from file • Editing rules • Applying rules • Saving rules

  12. Chaining • Order of rules • Rules impacting each other • A rule might cause another rule to become valid • Controlling chaining • Implicit • Explicit

  13. Rule Re-evalution options • "Always“ • Default behaviour for a rule. • The rules engine will always re-evaluate a rule with this setting, if the proper criteria are met. • This setting would not override a rule set chaining behaviour of "Sequential" • "Never“ • Turns off re-evaluation. • The rules engine only considers a rule "evaluated" if the rule executes a non-empty action. • Consider a rule that has Then actions, but no Else actions. If the rule is evaluated and its condition returns false, the rule is still a candidate for re-evaluation because the rule did not execute any actions.

  14. Demo – down the rabbit hole ... • Rule Re-Evaluation • Rule Chaining

  15. Where to next? • Instead of executing the rules from the UI, make the rule execution part of the class • Save rules in a database • Create a RuleRepository library

  16. What can you NOT do? • Return a value from a rule • Use delegates in the rule action • this.OrderItems.ForEach(delegate(OrderItem i) { i.DiscountAmount = 10; })

  17. References • http://odetocode.com/articles/458.aspx • http://blogs.microsoft.co.il/blogs/bursteg/archive/2006/10/11/RuleExecutionWithoutWorkflow.aspx • http://msdn.microsoft.com/en-us/library/aa480193.aspx • http://footheory.com/blogs/bennie/archive/2007/05/12/simple-application-extensibility-with-wf-rules.aspx • http://www.joshlane.net/blog/WindowsWorkflowRulesEngineWithoutWindowsWorkflow.aspx

  18. Questions?

More Related