extending workflow foundation with custom activities

57

Upload: rsnarayanan

Post on 27-Jun-2015

2.445 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Extending Workflow Foundation With Custom Activities
Page 2: Extending Workflow Foundation With Custom Activities

K. MeenaDirectorSymIndia Training & Consultancy Pvt [email protected]

Extending Workflow FoundationWith Custom Activities

Page 3: Extending Workflow Foundation With Custom Activities

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component Model Creating Composite Activities

Page 4: Extending Workflow Foundation With Custom Activities

Objectives and Pre-requisites

ObjectivesUnderstand Activity AutomationDevelop Custom activities

Pre-requisite KnowledgeWF ArchitectureExperience in designing/developing WF based applications

Page 5: Extending Workflow Foundation With Custom Activities

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component Model Creating Composite Activities

Page 6: Extending Workflow Foundation With Custom 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

Page 7: Extending Workflow Foundation With Custom 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

Page 8: Extending Workflow Foundation With Custom Activities

ExamplesCredit Process

Add Customer ProfileGet Black listed ListCompute Credit Score

Mortgage ProcessingGet Flood Insurance QuoteCompute Tax Prioritized Processing of Tasks

Page 9: Extending Workflow Foundation With Custom Activities

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

Page 10: Extending Workflow Foundation With Custom Activities

WF with other Microsoft Products

Microsoft Speech Server 2007CheckVoicePrintExistenceRegisterSpeakerVoicePrintPerformDictation

Page 11: Extending Workflow Foundation With Custom Activities

AgendaNeedActivity Automation Basic FeaturesAdvanced FeaturesActivity Component Model

Page 12: Extending Workflow Foundation With Custom Activities

Calculate PiInArgument<Int64> DecimalPlaces

OutArgument<string> PiAsString

Execute

Completed

Atomic Work

Page 13: Extending Workflow Foundation With Custom Activities

PromptPrompt

InArgument<string> Question

OutArgument<string> Response

Execute

Completed

Bookmark ResumeResumeyieldyield

Continuation, Long Running, or Reactive Execution

Page 14: Extending Workflow Foundation With Custom Activities

Process TransferRequest

Receive Request Authorize Request

Execute

Completed

Composite execution

Schedule activity

Child completed

yield

Composite Activity

Page 15: Extending Workflow Foundation With Custom Activities

Activity Scheduling Pattern

FIFO dispatchScheduler Work Queue

Holds work items Non-preemptive behavior

Page 16: Extending Workflow Foundation With Custom Activities

Activity State Model

Transition Initiator

ActivityWorkflow Runtime

Initialized Executing Closed

Compensating

Faulting

Activity Fault

Canceling

(dashed line if final)

Page 17: Extending Workflow Foundation With Custom Activities

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

Page 18: Extending Workflow Foundation With Custom Activities

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component Model Creating Composite Activities

Page 19: Extending Workflow Foundation With Custom 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

Page 20: Extending Workflow Foundation With Custom Activities

ActivityExecutionContext

Execution EnvironmentApplication State – Activity treeRuntime State - internal queues and data structures for scheduling and execution

Selectively exposesWorkflow runtime capabilities Services

Page 21: Extending Workflow Foundation With Custom Activities

Additions

Custom propertiesIndependentDependent

Custom methodsCustom Events

Page 22: Extending Workflow Foundation With Custom Activities

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

Page 23: Extending Workflow Foundation With Custom Activities

Simple Activity – Basic FeaturesGayathri KumarDirectorSymIndia Training & Consultancy Pvt Ltd

Page 24: Extending Workflow Foundation With Custom Activities

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component Model Creating Composite Activities

Page 25: Extending Workflow Foundation With Custom Activities

Activity State Model

Transition Initiator

ActivityWorkflow Runtime

Initialized Executing Closed

Compensating

Faulting

Activity Fault

Page 26: Extending Workflow Foundation With Custom Activities

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

Page 27: Extending Workflow Foundation With Custom Activities

Exception HandlingPropagation to parent of the fault activity

Can be suppressedscheduled only when the faulting activity transitions to Closed state

Page 28: Extending Workflow Foundation With Custom Activities

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

Page 29: Extending Workflow Foundation With Custom Activities

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.

Page 30: Extending Workflow Foundation With Custom Activities

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’

Page 31: Extending Workflow Foundation With Custom Activities

Faulting & CompensationGayathri KumarDirectorSymIndia Training & Consultancy Pvt Ltd

Page 32: Extending Workflow Foundation With Custom Activities

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component Model Creating Composite Activities

Page 33: Extending Workflow Foundation With Custom Activities

Design Time Experience

Appearance Custom context menusValidationsDynamic Properties

Page 34: Extending Workflow Foundation With Custom Activities

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

Page 35: Extending Workflow Foundation With Custom Activities

Design Time FeaturesGayathri Kumar DirectorSymIndia Training & Consultancy Pvt Ltd

Page 36: Extending Workflow Foundation With Custom Activities

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component Model Creating Composite Activities

Page 37: Extending Workflow Foundation With Custom Activities

Typical Composite Activity Execution

Composite Activity

..

..

..

+= OnChildClosed

+= OnChildClosed

Execute()

Status.Closed()

Child Activity

Child Activity

Page 38: Extending Workflow Foundation With Custom Activities

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();}

}

Page 39: Extending Workflow Foundation With Custom Activities

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)

Page 40: Extending Workflow Foundation With Custom Activities

Sequencing or Interleaving?

WF runtime has no knowledge

Page 41: Extending Workflow Foundation With Custom Activities

Custom Composite Derive from

SequenceActivityCompositeActivity

No default logic for handling child activities Override Execute method

Page 42: Extending Workflow Foundation With Custom Activities

Activity State Model

Transition Initiator

ActivityWorkflow Runtime

Initialized Executing Closed

Compensating

Faulting

Activity Fault

Canceling

(dashed line if final)

Page 43: Extending Workflow Foundation With Custom Activities

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’

Page 44: Extending Workflow Foundation With Custom Activities

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

Page 45: Extending Workflow Foundation With Custom Activities

Cancelling Child activitiesGayathri Kumar DirectorSymIndia Training & Consultancy Pvt Ltd

Page 46: Extending Workflow Foundation With Custom Activities

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

Page 47: Extending Workflow Foundation With Custom Activities

Attached PropertiesGayathri Kumar DirectorSymIndia Training & Consultancy Pvt Ltd

Page 48: Extending Workflow Foundation With Custom Activities

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.

Page 49: Extending Workflow Foundation With Custom Activities

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

Page 50: Extending Workflow Foundation With Custom Activities

More Examples

Repeated Execution of Child ActivitiesPrioritized Execution of Child ActivitiesGetApprovals

‘M’ of ‘N’ will do Activities with support for

Event handlingTransactions

Page 51: Extending Workflow Foundation With Custom Activities

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

Page 52: Extending Workflow Foundation With Custom Activities

धन्यवा�दઆભા�ર ধন্য�বা�দ

ਧੰ�ਨਵਾ�ਦ

ଧନ୍ୟ�ବା�ଦ

நன்றி�

ధన్య�వాదాలు� ಧನ್ಯ�ವಾ�ದಗಳು

നി�ങ്ങള്‍‌ക്ക്� നിന്ദി�

Page 53: Extending Workflow Foundation With Custom Activities

question & answer

Page 54: Extending Workflow Foundation With Custom Activities

Related Content

Overview of .NET Framework 4.0Dublin: A Boon to WCF and WF Developers (for on-premise and cloud)

Page 55: Extending Workflow Foundation With Custom Activities

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

Page 56: Extending Workflow Foundation With Custom Activities

Track Resources

Resource 1

Resource 2

Resource 3

Resource 4

Page 57: Extending Workflow Foundation With Custom Activities

© 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.