vic001

Does anyone have a design pattern for creating a workflow that allows passing properties from one activity to another.

It seems pointless having a workflow where custom activites cannot store a property at run-time for another activity to use at run-time because of activity cloning. I am trying to build a IVR workflow using Windows WF. One of the activites I created plays a wav file to the caller and waits for a response. Once a response is received the activity is closed and the response is stored in a property. The next activity needs to know what this response is in order to excecute. This next activity may be in another state, or within a while loop activity or ifelse activity etc...

I do not want to have to store these activity properties on the workflow class, because I am building a system for the end user to use. I do not know how they will use the properties of my activities at their run-time.

V

 



Re: Windows Workflow Foundation Design Pattern

Tom Lake - MSFT

Unfortunately this is one of the limitation of spawned contexts that you will run into for StateMachine workflows and activities like While, ConditionedActivityGroup and Replicator. If you want to access the activity property from a different state you will need to bind the property to a common workflow level variable. There is no work around for this. We are looking into fixing this in future versions.




Re: Windows Workflow Foundation Design Pattern

danroot

I just posted a possible pattern for handling these situations, but am looking for expert advice & testing: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1289480&SiteID=1

The idea is to add a property on the custom activity that can be used to get the current activity instance. In my implementation the property is called 'DynamicCopy', and uses a method that traverses the workflow looking for the activity by name- taking into account WhileActivity's behavior if any exist.

Other properties are added to the activity as usual with a backing field or dependancy property, and set normally in Execute or wherever else.

Then, the code that reads the property value looks like this:

this.myCustomActivity1.DynamicCopy.MyProperty

Again, I readily admit I may be missing something here- I've only tested this in a single, sequential workflow, and am new to WF. I'd really appreciate any suggestions or criticism. If it works, this pattern could probably be refactored to a base activity class, or using generics.







Re: Windows Workflow Foundation Design Pattern

vic001

This may work for setting/getting the properties while the while activity is executing but does not work if an activity wants to set the properties of another activity in a while loop before the while loop is excecuted. The first time the while activity executes it clones the activity and whatever properties were set, are then lost. Have you come across this scenario



Re: Windows Workflow Foundation Design Pattern

danroot

I see- slightly different problem from what I thought. There was a reply on that thread that seems like a better solution than what I had originally posted. You may want to give that a shot...





Re: Windows Workflow Foundation Design Pattern

vic001

when is the scheduled next release...



Re: Windows Workflow Foundation Design Pattern

Tom Lake - MSFT

Which version it will be fixed in still has not been decided but it will NOT be included with the Orcas changes.