Presentation is loading. Please wait.

Presentation is loading. Please wait.

Matt Winkler – Technical Evangelist WF Microsoft Corporation CON312.

Similar presentations


Presentation on theme: "Matt Winkler – Technical Evangelist WF Microsoft Corporation CON312."— Presentation transcript:

1

2 Matt Winkler – Technical Evangelist WF Microsoft Corporation http://blogs.msdn.com/mwinkle CON312

3 Introduction Rule execution Rule extensibility

4 Activity Library Workflow Runtime Engine Runtime Services Visual Studio Designer Long Running Logic Flexibility What is Workflow? Workflow is the software implementation of business process or business logic What’s the value of Workflow? Released Nov 2006 as a part of Windows Vista Transparency A Workflow Host Process Activity

5 Conditions Boolean expressions Rule If Condition THEN ELSE RuleSet Collection of rules Execution semantics

6 Simple semantics for defining discrete, atomic rules Aggregation of rules into rule sets that represent rich application behavior Modeling Power Declarative nature allows domain experts to concentrate on the business requirements Model-driven design allows for rich authoring and management tools Externalization of rule logic from application code Rapid deployment model Supporting impact analysis and simulation capabilities Approachability Ease of Change

7 Externalize decision details from process Create tooling for rule customization by non- developers Execute a set of rules against a set of facts Take advantage of complex execution semantics that are nearly impossible to model in code

8 Activity Conditions If-Else While Replicator Conditioned Activity Group (CAG) Conditions on Custom Activities Policy Activity Encapsulates the definition and execution of a RuleSet Custom Activities.NET Applications

9

10 Code conditions Fast, fast, fast Compiled into workflow Declarative conditions Externalized in.rules file Compiled into workflow, but easy to change

11 Versioning and Management Independent from the application Specialized management tools for rules Deployment and Compilation Ease of change No application recompilation Rules only deployment / No application redeployment

12 Use declarative, XAML-only workflows public WorkflowInstance CreateWorkflow( XmlReader workflowDefinitionReader, XmlReader rulesReader, Dictionary namedArgumentValues)

13 Use DynamicUpdate static void UpdateRules(WorkflowInstance instance) { WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); XmlTextReader reader = new XmlTextReader("..\\RealRules.rules"); RuleDefinitions rules = serializer.Deserialize(reader) as RuleDefinitions; WorkflowChanges changes = new WorkflowChanges( instance.GetWorkflowDefinition()); changes.TransientWorkflow.SetValue( RuleDefinitions.RuleDefinitionsProperty, rules); instance.ApplyWorkflowChanges(changes); }

14 Write a custom loader workflowRuntime.AddService(new CustomLoader()); class CustomLoader : DefaultWorkflowLoaderService { protected override Activity CreateInstance(Type workflowType) { Activity workflow = base.CreateInstance(workflowType); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); XmlTextReader reader = new XmlTextReader("..\\RealRules.rules"); RuleDefinitions rules = serializer.Deserialize(reader) as RuleDefinitions; workflow.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules); return workflow; }

15 Create rules service RuleSet Designer RuleSet Designer RuleSet Repository RuleSet Repository Host RuleSet Service Workflow1 Workflow2 Workflow3 Custom Policy Activity Custom Policy Activity Custom Policy Activity Custom Policy Activity Custom Policy Activity Custom Policy Activity

16 Option 1: Explicit Pattern Option2: Custom Loader Option 3: WorkflowChanges Option 4: CreateWF overload Outside WF YESNO When are the rules loaded? When policy activity executes When WF is loaded (initial, re- hydrated) When DynamicUpdates are made When instance is created Workflows with code- beside YES NO

17 RuleSetDialog ruleSetDialog = new RuleSetDialog(targetType, ruleSet); DialogResult result = ruleSetDialog.ShowDialog(); RuleSet newRuleSet = ruleSetDialog.RuleSet; Host RuleSet Editor WorkflowMarkupSerializer.Serialize(XmlWriter writer, object obj); Serialize Workflow Add RuleSetService to WorkflowRuntime WorkflowRuntime.AddService(new RuleSetService());

18 RuleValidation validation = new RuleValidation(targetObject.GetType(), null); RuleExecution execution = new RuleExecution(validation, targetObject, null); ruleSet.Execute(execution); Execute RuleSet ValidationErrorsCollection errors = validation.Errors; Validation Errors

19

20 Rulesets can get very big, (10,000+ rules) The rules engine tracks changes (side effects) of rule execution to enable rule re- execution We have fine grained control over execution Priority Chaining mechanisms Implicit Explicit “Partially Explicit”

21 Amount = $25 Total = $80 Discount = 10% Rule 1 (P0) If Total > $50 & < $100 Then Discount = 10% Rule 2 (P0) If Total >= $100 Then Discount = 15% Rule 3 (P0) If Amount > $0 Then Total = Total + Amount Rule 1 Rule 3 Rule 2 Execution Sequence $105 RuleSet 15%

22 Declaratively decorate methods in a class to allow rule engine to infer chaining behavior [RuleRead(path)] Indicate decorated method relies on variable in path [RuleWrite(path)] Indicate decorated method updates variable in path [RuleInvoke(methodName)] Indicate decorated method calls another method which updates a variable

23 Rule 1 (Priority =2) If 1==1 Then this.enumerator = this.collection.GetEnumerator() Rule 2 (Priority = 1) If this.enumerator.MoveNext() Then this.currentInstance = this.enumerator.Current Rules 3 – n (Priority = 0) // write these against currentInstance Rule n+1 (Priority = -1) If this.currentInstance == this.currentInstance Then Update(this/enumerator)

24

25

26 InRule TM for Windows® Workflow Foundation

27

28

29 RuleDefinitionsRuleSet 1 * Rule 1 * RuleSetReference -RuleSetName * -Name 1 Activity 11 RuleCondition RuleExpressionCondition CodeExpression RuleAction RuleStatementAction RuleHaltActionRuleUpdateAction CodeStatement

30 CodeArrayIndexerExpression CodeAssignStatement CodeBinaryOperatorExpression CodeCastExpression CodeDirectionExpression CodeExpressionStatement CodeFieldReferenceExpression CodeIndexerExpression CodeMethodInvokeExpression CodeMethodReferenceExpressio n CodePrimitiveExpression CodePropertyReferenceExpressi on CodeThisReferenceExpression CodeTypeReference CodeTypeReferenceExpression CodeObjectCreateExpression * CodeArrayCreateExpression * * New in NETFX 3.5

31

32 Re-use/share commonly used expressions and actions Choose text representation in the Rules editor Can participate in RuleSet validation and raise errors Can participate in the forward chaining analysis Access to ActivityExecutionContext (access to the running activities, host services, etc.) Raises the authoring semantic

33 Derives from CodeExpression Implements IRuleExpression public interface IRuleExpression { void AnalyzeUsage(RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier); CodeExpression Clone(); void Decompile(StringBuilder stringBuilder, CodeExpression parentExpression); RuleExpressionResult Evaluate(RuleExecution execution); bool Match(CodeExpression expression); RuleExpressionInfo Validate(RuleValidation validation, bool isWritten); }

34 Derives from RuleAction [Serializable] public abstract class RuleAction { public abstract RuleAction Clone(); public abstract void Execute(RuleExecution context); public abstract ICollection GetSideEffects(RuleValidation validation); public abstract bool Validate(RuleValidation validator); }

35

36 Given a rule action has access to ActivityExecutionInstance, we could schedule an activity to execute Gain the ability to model rule actions as activities (or a sequence of activities) Lose the ability to react to side effects from activity execution (chaining), but could re-run ruleset

37

38 Rules are an easy way to add flexible logic to your process Rules can be used stand-alone by any.NET application Management and tooling can be built on top of the rule API’s Custom actions and expressions make it easier to expose functionality to ruleset designers

39

40

41 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "Matt Winkler – Technical Evangelist WF Microsoft Corporation CON312."

Similar presentations


Ads by Google