Extending Workflow Foundation With Custom Activities

2,807 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,807
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
54
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Extending Workflow Foundation With Custom Activities

  1. 1. Extending Workflow Foundation With Custom Activities K. Meena Director SymIndia Training & Consultancy Pvt Ltd meena@symindia.com
  2. 2. Agenda Need Activity Automation Creating Simple Activities Basic Features Advanced Features Activity Component Model Creating Composite Activities
  3. 3. Objectives and Pre-requisites Objectives Understand Activity Automation Develop Custom activities Pre-requisite Knowledge WF Architecture Experience in designing/developing WF based applications
  4. 4. Agenda Need Activity Automation Creating Simple Activities Basic Features Advanced Features Activity Component Model Creating Composite Activities
  5. 5. Activity Basics Activities are the building blocks of workflows The unit of execution, re-use and composition Basic activities are steps within a workflow Composite activities contains other activities
  6. 6. Activities: An Extensible Approach Domain-Specific Base Activity Custom Activity Workflow Packages Library Libraries Compliance CRM Compose Extend activities activity Out-of-Box Sae Activities Fill RosettaNet Author new activity IT Mgmt l General-purpose l Define workflow l Create/Extend/ constructs Compose activities l Vertical-specific activities l App-specific building & workflows blocks l First-class citizens
  7. 7. Examples Credit Process Add Customer Profile Get Black listed List Compute Credit Score Mortgage Processing Get Flood Insurance Quote Compute Tax Prioritized Processing of Tasks
  8. 8. WF with other Microsoft Products SharePoint 2007 Designer Send Email with List Item Attachments Grant Permissions to an item Copy List Item Delete List Item Permission Assignment Microsoft Dynamics CRM 4.0 Wizard based Workflow Creation Custom Activities Get the next Birthday Calculate Distance between Two zip codes Calculate Credit Score
  9. 9. WF with other Microsoft Products Microsoft Speech Server 2007 CheckVoicePrintExistence RegisterSpeakerVoicePrint PerformDictation
  10. 10. Agenda Need Activity Automation Basic Features Advanced Features Activity Component Model
  11. 11. Atomic Work Execute InArgument<Int64> DecimalPlaces Calculate Pi Completed OutArgument<string> PiAsString
  12. 12. Continuation, Long Running, or Reactive Execution Execute InArgument<string> Question Prompt yield Bookmark Resume OutArgument<string> Response Completed
  13. 13. Composite Activity Composite execution Schedule activity Execute Authorize Receive Request Request yield Process Transfer Request Child completed Completed
  14. 14. Activity Scheduling Pattern FIFO dispatch Scheduler Work Queue Holds work items Non-preemptive behavior
  15. 15. Activity State Model Faulting Canceling Initialized Executing Closed Compensating Transition Initiator Workflow Runtime Activity (dashed line if final) Activity Fault
  16. 16. Activity Automation - Basic Initialized Executing Closed Activity begins in Initialized state Runtime Moves it to Executing state when its work begins Moves to Closed state when its work is completed
  17. 17. Agenda Need Activity Automation Creating Simple Activities Basic Features Advanced Features Activity Component Model Creating Composite Activities
  18. 18. Derive From Activity Class Initialize Allocate resources Execute Do work Indicate whether the activity completed its work or not UnInitialize Cleanup resources allocated during Initialize OnClosed Cleanup resources allocated during the execution of the activity
  19. 19. ActivityExecutionContext Execution Environment Application State – Activity tree Runtime State - internal queues and data structures for scheduling and execution Selectively exposes Workflow runtime capabilities Services
  20. 20. Additions Custom properties Independent Dependent Custom methods Custom Events
  21. 21. Dependency Properties Centralized repository of a workflow's state Instance type Data Binding at runtime To another activity’s property Meta type of dependency property Mandatory to be set to a literal value at design time Immutable at run time Attached Properties An activity registers it Other activities make use of it
  22. 22. Simple Activity – Basic Features Gayathri Kumar Director SymIndia Training & Consultancy Pvt Ltd
  23. 23. Agenda Need Activity Automation Creating Simple Activities Basic Features Advanced Features Activity Component Model Creating Composite Activities
  24. 24. Activity State Model Faulting Initialized Executing Closed Compensating Transition Initiator Workflow Runtime Activity Activity Fault
  25. 25. Exception Handling In case of error Activity handles the exception and continues Activity does not handle the exception Unhandled Exceptions Immediate transition to ‘Faulting’ state HandleFault method enqueued Default implementation moves activity to Closed state Perform any cleanup work to free resources Indicate whether to move to Closed state or not
  26. 26. Exception Handling Propagation to parent of the fault activity Can be suppressed scheduled only when the faulting activity transitions to Closed state
  27. 27. Compensation Mechanism by which previously completed work can be undone or compensated when a subsequent failure occurs Using Transactions to rollback ? Not possible when the workflow is long running
  28. 28. Scenario A travel planning application Booking a flight Waiting for manager approval Paying for the flight Long running Process Not practical for the steps to participate in the same transaction. Compensation could be used to undo the booking step of the workflow if there is a failure later in the processing.
  29. 29. Compensatable Activity Implement ICompensatableActivity Compensate method Short-running or Long running compensation logic Indicate readiness to transition to Closed state Called when The ActivityExecutionState is ‘Succeeded’ ActivityExecutionStatus to be ‘Closed’
  30. 30. Faulting & Compensation Gayathri Kumar Director SymIndia Training & Consultancy Pvt Ltd
  31. 31. Agenda Need Activity Automation Creating Simple Activities Basic Features Advanced Features Activity Component Model Creating Composite Activities
  32. 32. Design Time Experience Appearance Custom context menus Validations Dynamic Properties
  33. 33. Activity Component Model Each activity has an associated set of components Components are associated through attributes on the Activity Definition Designer Validator Services Activity Serializer [Designer(typeof(MyDesigner))] Code Generator [CodeGenerator(typeof(MyCodeGen))] [Validator(typeof(MyValidator))] Toolbox Item public class MyActivity: Activity {...}
  34. 34. Design Time Features Gayathri Kumar Director SymIndia Training & Consultancy Pvt Ltd
  35. 35. Agenda Need Activity Automation Creating Simple Activities Basic Features Advanced Features Activity Component Model Creating Composite Activities
  36. 36. Typical Composite Activity Execution Execute() Composite Activity Child += OnChildClosed Activity .. .. .. Child += OnChildClosed Activity Status.Closed()
  37. 37. Sequence Activity – Execute() protected override ActivityExecutionStatus Execute(ActivityExecutionContext context) { if (this.EnabledActivities.Count == 0) return ActivityExecutionStatus.Closed; Activity childActivity = this.EnabledActivities[0]; childActivity.Closed += OnClosed; context.ExecuteActivity(childActivity); return ActivityExecutionStatus.Executing; } Void OnClosed(object sender, ActivityExecutionStatusChangedEventArgs e) { ActivityExecutionContext context = sender as ActivityExecutionContext ; e.Activity.Closed -= this.OnClosed; int index = this.EnabledActivities.IndexOf(e.Activity); if ( index+1) == this.EnabledActivities.Count) context.CloseActivity(); else { Activity child = this.EnabledActivities[index+1]; child.Closed += this.OnClosed; context.ExecuteActivity(); } }
  38. 38. Interleaving Start all activities in a burst Subscribe for Closed Event of all children In Closed event handler Call CloseActivity only if every child is in Closed state (completed)
  39. 39. Sequencing or Interleaving? WF runtime has no knowledge
  40. 40. Custom Composite Derive from SequenceActivity CompositeActivity No default logic for handling child activities Override Execute method
  41. 41. Activity State Model Faulting Canceling Initialized Executing Closed Compensating Transition Initiator Workflow Runtime Activity (dashed line if final) Activity Fault
  42. 42. Cancellation Composite Activity’s Parent invoking cancellation Faulting Logical error within composite activity itself One of the child activities has faulted Control Flow logic of the composite activity Scenario: you try to sell your house Thru newspaper ad, thru broker , internet ad ‘Any one will do’
  43. 43. Cancellation Composite should not request any more activities to be executed Composite should cancel all activities with status as “Executing” Each child activity’s Cancel method invoked Each Child activity performs cleanup and closes Only when all child activities are in either ‘Closed’ or in ‘Initialized’ state Composite moves to ‘Closed’ state from the cancelling state
  44. 44. Cancelling Child activities Gayathri Kumar Director SymIndia Training & Consultancy Pvt Ltd
  45. 45. Dependency Properties - Attached Composite activity registers a property It is then used by child activities Scenarios ConnectionString property for each child activity Maximum count / Retry for each child activity
  46. 46. Attached Properties Gayathri Kumar Director SymIndia Training & Consultancy Pvt Ltd
  47. 47. Pegasus Activity Library Imaging Activities for WF and MOSS deskew, despeckle, border cropping, inverse text correction, removal of dot shading, line removal, character smoothing Scenario : Sharepoint workflow is triggered when users add faxed documents to a Sharepoint document library. Apply despeckle and deskew activities, convert the images into PDF format, and forward them to users.
  48. 48. Pegasus Activity Library Workflow Take groups of images from a large microfiche image collection Tests them for inverted display and negates them if needed Removes unsightly borders Positions the new images on the page Saves them as multi-page TIFF files
  49. 49. More Examples Repeated Execution of Child Activities Prioritized Execution of Child Activities GetApprovals ‘M’ of ‘N’ will do Activities with support for Event handling Transactions
  50. 50. Summary You can extend workflow capabilities with Custom Activities Simple / Composite Custom Semantics / Model domain logic Understanding Activity Automation is critical to writing custom activities Rich Design time Experience Normal Execution cycle Compensation, Cancellation, Fault Handling
  51. 51. Related Content Overview of .NET Framework 4.0 Dublin: A Boon to WCF and WF Developers (for on-premise and cloud)
  52. 52. Resources “Essential Windows Workflow Foundation” Book by Dharma Shukla and Bob Schmidt URLs with relevant Articles http://msdn.microsoft.com/en- us/magazine/cc163504.aspx http://msdn.microsoft.com/en- us/library/aa480200.aspx http://msdn.microsoft.com/hi- in/magazine/cc163414(en-us).aspx
  53. 53. Track Resources Resource 1 Resource 2 Resource 3 Resource 4
  54. 54. © 2009 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.

×