The document discusses extending workflow capabilities with custom activities in Workflow Foundation. It covers creating simple and composite activities, and key concepts like the activity state model, exception handling, cancellation, compensation, and the activity component model. The document provides examples of custom activities for tasks like image processing and approval workflows. It emphasizes that understanding activity automation is important for writing robust custom activities that handle execution, faults, and cancellation properly.
3. Agenda
Need
Activity Automation
Creating Simple Activities
Basic Features
Advanced Features
Activity Component Model
Creating Composite Activities
4. Objectives and Pre-requisites
Objectives
Understand Activity Automation
Develop Custom activities
Pre-requisite Knowledge
WF Architecture
Experience in designing/developing WF
based applications
5. Agenda
Need
Activity Automation
Creating Simple Activities
Basic Features
Advanced Features
Activity Component Model
Creating Composite Activities
6. 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
7. 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
8. 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
9. 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
10. WF with other Microsoft
Products
Microsoft Speech Server 2007
CheckVoicePrintExistence
RegisterSpeakerVoicePrint
PerformDictation
11. Agenda
Need
Activity Automation
Basic Features
Advanced Features
Activity Component Model
12. Atomic Work
Execute InArgument<Int64> DecimalPlaces
Calculate Pi
Completed OutArgument<string> PiAsString
13. Continuation, Long Running, or
Reactive Execution
Execute InArgument<string> Question
Prompt
yield Bookmark Resume
OutArgument<string> Response
Completed
14. Composite Activity
Composite execution
Schedule activity
Execute
Authorize
Receive Request
Request
yield Process
Transfer
Request
Child completed
Completed
16. Activity State Model
Faulting
Canceling
Initialized Executing Closed
Compensating
Transition Initiator
Workflow Runtime
Activity (dashed line if final)
Activity Fault
17. 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
18. Agenda
Need
Activity Automation
Creating Simple Activities
Basic Features
Advanced Features
Activity Component Model
Creating Composite Activities
19. 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
20. ActivityExecutionContext
Execution Environment
Application State – Activity tree
Runtime State - internal queues and data
structures for scheduling and execution
Selectively exposes
Workflow runtime capabilities
Services
22. 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
23. Simple Activity – Basic Features
Gayathri Kumar
Director
SymIndia Training & Consultancy Pvt Ltd
24. Agenda
Need
Activity Automation
Creating Simple Activities
Basic Features
Advanced Features
Activity Component Model
Creating Composite Activities
25. Activity State Model
Faulting
Initialized Executing Closed
Compensating
Transition Initiator
Workflow Runtime
Activity
Activity Fault
26. 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
27. Exception Handling
Propagation to parent of the fault activity
Can be suppressed
scheduled only when the faulting activity
transitions to Closed state
28. 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
29. 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.
30. 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’
34. 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 {...}
35. Design Time Features
Gayathri Kumar
Director
SymIndia Training & Consultancy Pvt Ltd
36. Agenda
Need
Activity Automation
Creating Simple Activities
Basic Features
Advanced Features
Activity Component Model
Creating Composite Activities
39. 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)
41. Custom Composite
Derive from
SequenceActivity
CompositeActivity
No default logic for handling child activities
Override Execute method
42. Activity State Model
Faulting
Canceling
Initialized Executing Closed
Compensating
Transition Initiator
Workflow Runtime
Activity (dashed line if final)
Activity Fault
43. 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’
44. 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
46. 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
48. 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.
49. 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
50. 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
51. 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
52.
53.
54. Related Content
Overview of .NET Framework 4.0
Dublin: A Boon to WCF and WF Developers (for
on-premise and cloud)
55. 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