creating custom activities in wfdownload.microsoft.com/download/f/3/3/f33d91df-d6e3-442a... ·...

Post on 14-Jul-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

K. MeenaDirectorSymIndia Training & Consultancy Pvt Ltdmeena@symindia.com

Extending Workflow Foundation

With Custom Activities

AgendaNeed

Activity Automation

Creating Simple Activities Basic Features

Advanced 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 Features

Advanced Features

Activity Component Model

Creating Composite Activities

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

Activities: An Extensible Approach

l General-purposel Define workflow

constructsl Create/Extend/

Compose activitiesl App-specific building

blocksl First-class citizens

Base Activity

Library

Custom Activity Libraries

Author new activity

Extend activity

Compose activitiesOut-of-Box

Activities

l 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 Attachments

Grant Permissions to an item

Copy List Item

Delete List Item Permission Assignment

Microsoft Dynamics CRM 4.0Wizard based Workflow Creation

Custom Activities

Get the next Birthday

Calculate Distance between Two zip codes

Calculate Credit Score

WF with other Microsoft Products

Microsoft Speech Server 2007CheckVoicePrintExistence

RegisterSpeakerVoicePrint

PerformDictation

AgendaNeed

Activity Automation

Basic Features

Advanced Features

Activity Component Model

Calculate Pi

InArgument<Int64> DecimalPlaces

OutArgument<string> PiAsString

Execute

Completed

Atomic Work

Prompt

InArgument<string> Question

OutArgument<string> Response

Execute

Completed

Bookmark Resumeyield

Continuation, Long Running, or Reactive Execution

Process TransferRequest

Receive RequestAuthorize 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

Activity

Workflow Runtime

Initialized Executing Closed

Compensating

Faulting

Activity Fault

Canceling

(dashed line if final)

Activity Automation - Basic

Activity begins in Initialized state

Runtime Moves it to Executing state when its work begins

Moves to Closed state when its work is completed

Initialized Executing Closed

AgendaNeed

Activity Automation

Creating Simple Activities Basic Features

Advanced Features

Activity Component Model

Creating Composite Activities

Derive From Activity Class

InitializeAllocate resources

Execute 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 tree

Runtime State - internal queues and data structures for scheduling and execution

Selectively exposesWorkflow runtime capabilities

Services

Additions

Custom propertiesIndependent

Dependent

Custom methods

Custom 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 Kumar

Director

SymIndia Training & Consultancy Pvt Ltd

AgendaNeed

Activity Automation

Creating Simple Activities Basic Features

Advanced Features

Activity Component Model

Creating Composite Activities

Activity State Model

Transition Initiator

Activity

Workflow Runtime

Initialized Executing Closed

Compensating

Faulting

Activity Fault

Exception Handling

In case of errorActivity handles the exception and continues

Activity does not handle the exception

Unhandled ExceptionsImmediate 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

Exception Handling

Propagation to parent of the fault activityCan be suppressed

scheduled only when the faulting activity transitions to Closed state

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

Scenario

A travel planning applicationBooking a flightWaiting for manager approvalPaying 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 logic

Indicate readiness to transition to Closed state

Called whenThe ActivityExecutionState is ‘Succeeded’

ActivityExecutionStatus to be ‘Closed’

Faulting & CompensationGayathri Kumar

Director

SymIndia Training & Consultancy Pvt Ltd

AgendaNeed Activity Automation Creating Simple Activities

Basic FeaturesAdvanced Features

Activity Component ModelCreating Composite Activities

Design Time Experience

Appearance

Custom context menus

Validations

Dynamic Properties

Activity Component ModelEach activity has an associated set of components

Components are associated through attributes on the Activity Definition

[Designer(typeof(MyDesigner))]

[CodeGenerator(typeof(MyCodeGen))]

[Validator(typeof(MyValidator))]

public class MyActivity: Activity {...}

Activity

Code Generator

Designer

Validator

SerializerServices

Toolbox Item

Design Time FeaturesGayathri Kumar

Director

SymIndia 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 burst

Subscribe for Closed Event of all children

In Closed event handlerCall CloseActivity only if every child is in Closed state (completed)

Sequencing or Interleaving?

WF runtime has no knowledge

Custom Composite

Derive fromSequenceActivity

CompositeActivityNo default logic for handling child activities

Override Execute method

Activity State Model

Transition Initiator

Activity

Workflow 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 itself

One of the child activities has faulted

Control Flow logic of the composite activity

Scenario: you try to sell your houseThru 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 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

Cancelling Child activitiesGayathri Kumar

Director

SymIndia Training & Consultancy Pvt Ltd

Dependency Properties -Attached

Composite activity registers a property

It is then used by child activities

ScenariosConnectionString property for each child activity

Maximum count / Retry for each child activity

Attached PropertiesGayathri Kumar

Director

SymIndia 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 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

More Examples

Repeated Execution of Child Activities

Prioritized Execution of Child Activities

GetApprovals‘M’ of ‘N’ will do

Activities with support forEvent handling

Transactions

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

Related Content

Overview of .NET Framework 4.0

Dublin: A Boon to WCF and WF Developers (for on-premise and cloud)

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.

top related