brb.1977

Hi everyone:

I hope my question is basic. When I create a workflow I am creating a parameter collection and passing it into the CreateWorkflow() method off an instantiated runtime object. Here's the code:

Dim parameters As New System.Collections.Generic.Dictionary(Of String, Object)

parameters.Add("MySpecialID", MID)

Dim instance As WorkflowInstance = runtime.CreateWorkflow(workflowType, parameters)

 

On the workflow class (which is a state machine) I've added a public property which the parameter should map to. Here's the code:

Public Class SampleWorkflow

Inherits StateMachineWorkflowActivity

Private _mySpecialID As Object

Public Property MySpecialID() As Object

Get

Return _mySpecialID

End Get

Set(ByVal value As Object)

_mySpecialID= value

End Set

End Property

End Class

 

That works just fine. I wired up an event to handle workflowcompleted and I can see my original value returned. Here's that code:

 

Private Sub Runtime_WorkflowCompleted(ByVal sender As Object, ByVal e As WorkflowCompletedEventArgs) Handles runtime.WorkflowCompleted

Me.UpdateListItem(e.WorkflowInstance, "", "Completed")

MsgBox(e.OutputParameters("MySpecialID"))

End Sub

My host application simply queries the persisted workflows and displays a list of workflows that are currently running. What I really want to do is get the value of MySpecialID out of the workflow at any time. Essentially, I'm using WF to keep track of state, it doesn't know anything about our data. The value of MySpecialID is a unique identifier that I'm hoping will link the workflow with a particular account. Does this make sense

My question is: am I going about this the right way Is there a way to get that outputparameter at any time and not just when the workflow is completed Or is there something I can do with activities, etc.

 

I appreciate any help on this.

 

John

 

 

 

 



Re: Windows Workflow Foundation Parameter Dictionary that map to Public properties on the workflow

Jon Flanders

As a workflow is executing there are really three ways I can think of to get data from the workflow.

1) Use tracking. Tracking will allow you to get a "push" of data from the workflow. You can create an ActivityTrackPoint with a DataExtract which will pull the data from the workflow and push it to your tracking service.

2) Use a runtime service. The workflow (or activities in the workflow) can ask for this service and call a method on the service. This allows the workflow to notify the service of the data - and your service can update your UI.

3) You can use WorkflowInstance.GetWorkflowDefinition. This will run an Activity instance which you can cast to your type and get the property. The thing to remeber here is that this is a cloned "snapshot" of the activity at that moment in time. The activity could change on the very next call and would be out of sync. Tracking does have this same inherent risk.






Re: Windows Workflow Foundation Parameter Dictionary that map to Public properties on the workflow

brb.1977

Jon:

I appreciate your response. This seems like an awful lot of work to do to retrieve a value I set when I initially created the workflow. I'm afraid I might be going down a stupid path here.

btw, I am both tracking and persisting workflows currently.

When I create a workflow I am tying that workflow instance to an account in our database. At some point later on when that workflow has been revived I not only want to show the current state of the workflow, but what account that workflow is in reference to.

Is there an easier way to do this through the WF framework

 

 

 





Re: Windows Workflow Foundation Parameter Dictionary that map to Public properties on the workflow

Jon Flanders

My preferred methodology is using tracking. Since you already have tracking turned on - it isnt that difficult. Just change the TrackingProfile to do extracts of the data you are interested in. If you are using the OOB SqlTrackingService there is a query API which allows you to query the tracking database.




Re: Windows Workflow Foundation Parameter Dictionary that map to Public properties on the workflow

Tom Lake - MSFT

I have a sample that uses a that uses tracking to extract a workflow value at runtime, it can be found here.




Re: Windows Workflow Foundation Parameter Dictionary that map to Public properties on the workflow

Ethan Hunt

Jon,

I have the same issue as brb.1977 but mine is a little bit different. I'd like to write some values to the public property of workflow after executing some Activities. How do i achive this