index > Windows Workflow Foundation > Pattern for updating custom Activity Properties without completin...

Pattern for updating custom Activity Properties without completin...

Hi

Most activities in my workflows are human activities and are therefore event-driven. The workflow blocks at each new activity waiting for a user to click "Complete" or "Approve" in the application GUI. These activities have a number of common business-logic properties, encapsulated in a custom base class. Example properties are: TargetCompletionTime, Priority, RequiresApproval etc. The values of these properties are tracked using TrackingExtracts and custom TrackingProfiles. This allows me to query the tracking service for the current state of my activities, including the values of the custom properties.

The complication is that I need to be allow my users to update the values of these activity properties at any time without closing the Activity. For example an administrator must be able to edit any current or future activity and change the priority, target time or assigned user. These changes need to be tracked so that the latest values can be shown to the executor of the activity.

I have been trying to do this via a parallel activity and external data exchange services. The parallel activity has one branch waiting in a loop for the update event on a subclass of HandleExternalEvent and the other branch waiting for the completion event on a 2nd HandleExternalEvent subclass (these two events are on different service interfaces). The update branch loops as it should not close the activity after an update. Does this sound reasonable? I had looked at the Listen activity for this but I think this is unsuitable as a message sent to the "update branch" will cause the parent Listen activity to complete.  I also have not been able to work out how I can send messages to the Update interface before the activity enters a wait state e.g. when it is a future activity.

I feel I must be missing a basic pattern for this very simple problem - my approach seems to need a lot of plumbing to just change the properties of a running activity. Considering this effort alongside the restrictions on inheriting from a composite activity and the complexities of tracking, and I am seriously starting to think it would be easier to store my custom activity state in my application database and only use WF to guide the activity flow.

Any suggestions on better ways of addressing what must be a very common task would be much appreciated.
Spigot

Why don't you give this a shot:

EventHandlingScopeActivity
HandleExternalEvent (completion event)
EventHandlersActivity
EventDrivenActivity
HandleExternalEvent (update event)

The above workflow snippet leverages the EventHandlingScopeActivity. The way this activity works is that it has a main body that consists of one activity, which begins executing immediately, and an optional EventHandlersActivity child, that can contain one or more EventDriven activities. If EventDriven activities are specified, then these events will be listened for in parallel to the executing body, and can be received over and over as long as the main body is not complete.

So in your scenario, you will have a HandleExternalEventActivity in the main body that is blocking, waiting to receive the completion event. In parallel though, you will have another HandleExternalEventActivity sitting in an EventDrivenActivity receiving and processing update events over and over until the completion event arrives and the whole thing is done executing.

Does this address your desired pattern?

Thanks!
Angel




Angel Azcarraga | Software Development Engineer in Test | Windows Workflow Foundation
Angel Azcarraga
Thanks for your quick reply Angel: yes, EventHandlingScopeActivity addresses this requirement perfectly.

I have another question about this approach:

Using this technique, is there any way I can send an Update message to a specific, named future activity? HandleExternalEvent always addresses the current waiting activity as far as I can see, but my sysadmins need to be able to select a future activity from a diagram/activity list and change some of its instance property values before it becomes active. I can't find any samples or documentation on sending an event to a specific, possibly non-active activity (past activities will not be updated in my application). I realise addressing a specific named activity in this way would be complicated by spawned contexts in loops etc., although in my case changing the properties for all spawned instances of an activity would suffice.

Thanks in advance.
Spigot

You can send messages for HandleExternalEvent activities that are not yet executing and they will be placed in a corresponding queue. They will not be received by the activity until it is executing though, so this will not address your needs.

One way you could achieve this is to make your root activity an EventHandlingScope. You can have a workflow-level event handler with a HandleExternalEvent activity that listens for a special event (e.g. UpdateActivity) that is triggered when your sysadmin selects an activity to update from their end. This message will contain the information needed to look this activity up (mainly the Name) and information about the update (maybe a dictionary keyed on property names). When this message is received, you can look up the corresponding activity and apply updates all from within the workflow. Since you're in the workflow, you'll have full information and access to the entire workflow and its state.

Hope this helps.

-Angel




Angel Azcarraga | Software Development Engineer in Test | Windows Workflow Foundation
Angel Azcarraga

That sounds like a good solution.  Can you clarify one thing: when you say "make your root activity an EventHandlingScope" do you mean:

(1) I should change the base class of my workflows from SequentialWorkflowActivity to EventHandlingScopeActivity, or

(2) that the parent SequentialWorkflowActivity should contain an EventHandlingScopeActivity as its first child, with all other activities within it?

If you mean option (1) and my workflow root activity is an EventHandlingScopeActivity instead of an SequentialWorkflowActivity, will the consequence not be a loss of important SequentialWorkflowActivity functionality like the public DynamicUpdateCondition property and the Completed/Initialized EventHandlers?

Spigot
reply 5

You can use google to search for other answers

 

More Articles

• The event that is fired in an activity when the workflow is added...
• Qury Regarding Long Running Workflows ....
• Workflow Designer Control Example
• WOTB (Way off Topic But..) What portal framework is the WWF site ...
• State Machine Workflow with partial Human Interaction
• In vs.net2005, how I set the IIS if I use HttpHandlers in the web...
• Code from the webcast.
• workflow versionning
• Activity.DesignMode true when initializing the workflow
• Rete algorithm- Can somebody help
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• avoid an activity to be removed
• Silly question about Sequential Workflows
• Custom activity: setting value of bound
• bind WF params to activity / default val
• HowTo make a StateMachine Workflow wait
• How do I keep the parent alive?
• Implement Custom Container Activity
• StateMachine Workflow event raise after
• Why to check base.ActiveView.AssociatedD
• Unexpected behavior in CAG - is this a b
• Exceptions While Creating the View
• Beta 1 Hands-On Lab
• two issue for Workflow,anyone can help me.
• Will there be a WF official release with
• Error compiling a Visual Studio solution

Hot Articles

• About RC2
• problems raising an event to a state mac
• Getting URL from a workflow hosted in AS
• Problem with SqlWorkflowPersistenceServi
• HIPAA 837 File Error
• Beta 2.2. Upgrade issue
• ActivityExecutionStatus Executing to Clo
• Hide "Bind to new member" tab
• How to implement custom rules using Rule
• Biztalk HWS
• Custom Activity - Probelm with EventSink
• Workflows termined due to not serializab
• Customizing ASP.NET page
• ManualWorkflowSchedulerService InvokeWor
• WorkFlow Deployment, Version Control and

Recommend Articles

• Beginner question - Using the book prese
• Getting Previous Activity
• Serious Problem in Loading Workflow
• Activity Properties and Conditions
• If the session lost , how to make the lo
• More simplistic conditions and branches
• Workflow management in Enterprise Enviro
• Error starting a workflow...
• Just discussing the ExpenseReporting Sam
• Problem adding a SetState Activity in a
• Pricing
• Compared to BPEL
• Understanding Code Separation
• Access from Access
• How to build a generic runtime host?