Presentation is loading. Please wait.

Presentation is loading. Please wait.

Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group.

Similar presentations


Presentation on theme: "Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group."— Presentation transcript:

1 Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group

2  My Story  More on Workflow Foundation  How to use the Rule Engine  Demo  Rule Theory  Demo

3  “... 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...”

4  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

5  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%

6  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

7  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!)

8  A programming model for building workflow- enabled applications in Windows  Added in.Net 3.0  Very powerful  Used by Sharepoint, CRM  Can persist state of the workflow (pause, continue, etc)  Contains a Rule engine  Can be used without all the WF infrastructure

9

10  Add References  System.Workflow.Activities  System.Workflow.ComponentModel  Create Instance of RuleSet  RuleSet rules = new RuleSet();

11  Load Rules from file using (XmlTextReader rulesReader = new XmlTextReader(filename)) { WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); rules = (RuleSet)serializer.Deserialize(rulesReader); }

12  Apply Rules RuleValidation validation = new RuleValidation(typeof(Order), null); RuleExecution execution = new RuleExecution(validation, newOrder); rules.Execute(execution);

13  Loading rules from file  Editing rules  Applying rules  Saving rules

14  Order of rules  Rules impacting each other  A rule might cause another rule to become valid  Controlling chaining  Implicit  Explicit

15  "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.

16  By default, the forward chaining in Windows Workflow is implicit.  The rules engine examines the expressions in each rule condition and each rule action to produce lists of dependencies and side effects.  We don't have to calculate dependencies manually.  For implicit chaining to work:  The rules engine has to be able to parse the rule expression.  If we have a rule that calls into compiled or third party code the rules engine cannot resolve the dependencies => chaining using metadata attributes or explicit actions.

17  You control the chaining by adding attributes to the methods  RuleWrite – a field or property that the method will change (a side effect of the method).  RuleRead – a field or property that the method will read (a dependency of the method).  RuleInvoke – a method that the current method will invoke. The engine will inspect the second method for additional attributes.

18  Sometimes you cannot add attributes to the code (3rd party code for example)  Update the rule to notify the engine about an update  Example of rule action this.AdjustBugForSecurity() Update("this/Bug/Priority/")

19  "Full Chaining "  Default rule set behavior, and provides us with the behavior we've described so far.  "Explicit Update Only"  Do not use implicit chaining.  Ignore RuleWrite and RuleRead attributes.  Only care about explicit Update statement  "Sequential "  Disables chaining altogether.  Execute rules only once and in the order specified by their respective Priority properties

20  Rule Re-Evaluation  Rule Chaining

21  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

22  Return a value from a rule  Use delegates in the rule action  this.OrderItems.ForEach(delegate(OrderItem i) { i.DiscountAmount = 10; })

23  http://odetocode.com/articles/458.aspx http://odetocode.com/articles/458.aspx  http://blogs.microsoft.co.il/blogs/bursteg/archive/2 006/10/11/RuleExecutionWithoutWorkflow.aspx http://blogs.microsoft.co.il/blogs/bursteg/archive/2 006/10/11/RuleExecutionWithoutWorkflow.aspx  http://msdn.microsoft.com/en- us/library/aa480193.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://footheory.com/blogs/bennie/archive/2007/05/12 /simple-application-extensibility-with-wf-rules.aspx  http://www.joshlane.net/blog/WindowsWorkflowRule sEngineWithoutWindowsWorkflow.aspx http://www.joshlane.net/blog/WindowsWorkflowRule sEngineWithoutWindowsWorkflow.aspx

24

25


Download ppt "Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group."

Similar presentations


Ads by Google