Extending Workflow Foundation With Custom Activities
-
Upload
rsnarayanan -
Category
Technology
-
view
2.441 -
download
3
Transcript of Extending Workflow Foundation With Custom Activities
K. MeenaDirectorSymIndia Training & Consultancy Pvt [email protected]
Extending Workflow FoundationWith Custom Activities
AgendaNeed Activity Automation Creating Simple Activities
Basic FeaturesAdvanced Features
Activity Component Model Creating Composite Activities
Objectives and Pre-requisites
ObjectivesUnderstand Activity AutomationDevelop Custom activities
Pre-requisite KnowledgeWF ArchitectureExperience in designing/developing WF based applications
AgendaNeed Activity Automation Creating Simple Activities
Basic FeaturesAdvanced Features
Activity Component Model Creating Composite Activities
Activity BasicsActivities 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
Activities: An Extensible Approach
General-purpose Define workflow constructs
Create/Extend/ Compose activities
App-specific building blocks
First-class citizens
Base ActivityLibrary
Custom Activity Libraries
Author new activity
Extend activity
Compose activitiesOut-of-Box
Activities
Vertical-specific activities & workflows
Domain-Specific Workflow Packages
Compliance
RosettaNet
CRM
IT Mgmt
Sae Fill
ExamplesCredit Process
Add Customer ProfileGet Black listed ListCompute Credit Score
Mortgage ProcessingGet Flood Insurance QuoteCompute Tax Prioritized Processing of Tasks
WF with other Microsoft Products
SharePoint 2007 Designer Send Email with List Item AttachmentsGrant Permissions to an itemCopy List ItemDelete List Item Permission Assignment
Microsoft Dynamics CRM 4.0Wizard based Workflow CreationCustom Activities
Get the next BirthdayCalculate Distance between Two zip codesCalculate Credit Score
WF with other Microsoft Products
Microsoft Speech Server 2007CheckVoicePrintExistenceRegisterSpeakerVoicePrintPerformDictation
AgendaNeedActivity Automation Basic FeaturesAdvanced FeaturesActivity Component Model
Calculate PiInArgument<Int64> DecimalPlaces
OutArgument<string> PiAsString
Execute
Completed
Atomic Work
PromptPrompt
InArgument<string> Question
OutArgument<string> Response
Execute
Completed
Bookmark ResumeResumeyieldyield
Continuation, Long Running, or Reactive Execution
Process TransferRequest
Receive Request Authorize Request
Execute
Completed
Composite execution
Schedule activity
Child completed
yield
Composite Activity
Activity Scheduling Pattern
FIFO dispatchScheduler Work Queue
Holds work items Non-preemptive behavior
Activity State Model
Transition Initiator
ActivityWorkflow Runtime
Initialized Executing Closed
Compensating
Faulting
Activity Fault
Canceling
(dashed line if final)
Activity Automation - Basic
Activity begins in Initialized stateRuntime Moves it to Executing state when its work beginsMoves to Closed state when its work is completed
Initialized Executing Closed
AgendaNeed Activity Automation Creating Simple Activities
Basic FeaturesAdvanced Features
Activity Component Model Creating Composite Activities
Derive From Activity ClassInitialize
Allocate resourcesExecute
Do work Indicate whether the activity completed its work or not
UnInitializeCleanup resources allocated during Initialize
OnClosedCleanup resources allocated during the execution of the activity
ActivityExecutionContext
Execution EnvironmentApplication State – Activity treeRuntime State - internal queues and data structures for scheduling and execution
Selectively exposesWorkflow runtime capabilities Services
Additions
Custom propertiesIndependentDependent
Custom methodsCustom Events
Dependency Properties
Centralized repository of a workflow's state Instance type
Data Binding at runtime To another activity’s property
Meta type of dependency propertyMandatory to be set to a literal value at design timeImmutable at run time
Attached PropertiesAn activity registers itOther activities make use of it
Simple Activity – Basic FeaturesGayathri KumarDirectorSymIndia Training & Consultancy Pvt Ltd
AgendaNeed Activity Automation Creating Simple Activities
Basic FeaturesAdvanced Features
Activity Component Model Creating Composite Activities
Activity State Model
Transition Initiator
ActivityWorkflow Runtime
Initialized Executing Closed
Compensating
Faulting
Activity Fault
Exception HandlingIn case of error
Activity handles the exception and continues Activity does not handle the exception
Unhandled ExceptionsImmediate transition to ‘Faulting’ state HandleFault method enqueuedDefault implementation moves activity to Closed state
Perform any cleanup work to free resourcesIndicate whether to move to Closed state or not
Exception HandlingPropagation to parent of the fault activity
Can be suppressedscheduled only when the faulting activity transitions to Closed state
CompensationMechanism 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
Scenario
A travel planning application Booking a flight Waiting for manager approval Paying for the flight
Long running ProcessNot 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.
Compensatable Activity
Implement ICompensatableActivityCompensate method
Short-running or Long running compensation logicIndicate readiness to transition to Closed state
Called whenThe ActivityExecutionState is ‘Succeeded’ActivityExecutionStatus to be ‘Closed’
Faulting & CompensationGayathri KumarDirectorSymIndia Training & Consultancy Pvt Ltd
AgendaNeed Activity Automation Creating Simple Activities
Basic FeaturesAdvanced Features
Activity Component Model Creating Composite Activities
Design Time Experience
Appearance Custom context menusValidationsDynamic Properties
Activity Component ModelEach activity has an associated set of componentsComponents are associated through attributes on the Activity Definition
[Designer(typeof(MyDesigner))]
[CodeGenerator(typeof(MyCodeGen))]
[Validator(typeof(MyValidator))]
public class MyActivity: Activity {...}
Activity
Code Generato
r
Designer
Validator
SerializerServices
Toolbox Item
Design Time FeaturesGayathri Kumar DirectorSymIndia Training & Consultancy Pvt Ltd
AgendaNeed Activity Automation Creating Simple Activities
Basic FeaturesAdvanced Features
Activity Component Model Creating Composite Activities
Typical Composite Activity Execution
Composite Activity
..
..
..
+= OnChildClosed
+= OnChildClosed
Execute()
Status.Closed()
Child Activity
Child Activity
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();}
}
Interleaving Start all activities in a burstSubscribe for Closed Event of all childrenIn Closed event handler
Call CloseActivity only if every child is in Closed state (completed)
Sequencing or Interleaving?
WF runtime has no knowledge
Custom Composite Derive from
SequenceActivityCompositeActivity
No default logic for handling child activities Override Execute method
Activity State Model
Transition Initiator
ActivityWorkflow Runtime
Initialized Executing Closed
Compensating
Faulting
Activity Fault
Canceling
(dashed line if final)
CancellationComposite Activity’s Parent invoking cancellation
Faulting Logical error within composite activity itselfOne of the child activities has faulted
Control Flow logic of the composite activityScenario: you try to sell your house
Thru newspaper ad, thru broker , internet ad‘Any one will do’
CancellationComposite should
not request any more activities to be executed
Composite should cancel all activities with status as “Executing”
Each child activity’s Cancel method invokedEach 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
Cancelling Child activitiesGayathri Kumar DirectorSymIndia Training & Consultancy Pvt Ltd
Dependency Properties - Attached
Composite activity registers a property It is then used by child activities Scenarios
ConnectionString property for each child activityMaximum count / Retry for each child activity
Attached PropertiesGayathri Kumar DirectorSymIndia Training & Consultancy Pvt Ltd
Pegasus Activity Library
Imaging Activities for WF and MOSSdeskew, 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.
Pegasus Activity Library
Workflow Take groups of images from a large microfiche image collectionTests them for inverted display and negates them if neededRemoves unsightly bordersPositions the new images on the pageSaves them as multi-page TIFF files
More Examples
Repeated Execution of Child ActivitiesPrioritized Execution of Child ActivitiesGetApprovals
‘M’ of ‘N’ will do Activities with support for
Event handlingTransactions
SummaryYou can extend workflow capabilities with Custom Activities
Simple / CompositeCustom Semantics / Model domain logic
Understanding Activity Automation is critical to writing custom activities
Rich Design time Experience Normal Execution cycle Compensation, Cancellation, Fault Handling
धन्यवा�दઆભા�ર ধন্য�বা�দ
ਧੰ�ਨਵਾ�ਦ
ଧନ୍ୟ�ବା�ଦ
நன்றி�
ధన్య�వాదాలు� ಧನ್ಯ�ವಾ�ದಗಳು
നി�ങ്ങള്ക്ക്� നിന്ദി�
question & answer
Related Content
Overview of .NET Framework 4.0Dublin: A Boon to WCF and WF Developers (for on-premise and cloud)
Resources
URLs with relevant Articleshttp://msdn.microsoft.com/en-us/magazine/cc163504.aspxhttp://msdn.microsoft.com/en-us/library/aa480200.aspxhttp://msdn.microsoft.com/hi-in/magazine/cc163414(en-us).aspx
“Essential Windows Workflow Foundation”Book by Dharma Shukla and Bob Schmidt
Track Resources
Resource 1
Resource 2
Resource 3
Resource 4
© 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.