posted on Tuesday, June 27, 2006 9:43 PM
by
BayerWhite
Notifying the Runtime Host Of A Workflow's Current State
Not sure how to get your UI host to reflect the current state of a persisted workflow? I found a way to get your tracking service to send this information to the hosted runtime from the workflow. Tracking services can track information like previous, current and next state for workflows. When a workflow is hydrated, the hosted runtime needs information about the current state to update the UI, so it makes sense to send state information about the workflow to the hosted runtime using a tracking service.
Host
- Build a tracking service for the workflow. There is a great example of this in the Hands On Lab's.
- Add the Tracking Service to the workflow runtime using the AddService() method
- To see that the tracking service returns the current state, add the following code
void m_wfRuntime_WorkflowLoaded(object sender, WorkflowEventArgs e)
{
RentalCore.RentalTrackingService TrackSvc = (RentalCore.RentalTrackingService)m_wfRuntime.GetService(typeof(RentalCore.RentalTrackingService));
MessageBox.Show(TrackSvc.CurrentActivity);
}
Workflow
- Open up the workflow(.xoml) and override the following method
protected override void OnActivityExecutionContextLoad(IServiceProvider provider)
{
RentalCore.RentalTrackingService TrackSvc = (RentalCore.RentalTrackingService)provider.GetService(typeof(RentalCore.RentalTrackingService));
TrackSvc.CurrentActivity = base.CurrentStateName;
}
The code above grabs the tracking service from the workflow and sets a custom tracking service property, "CurrentActivity" to the workflow's "CurrentStateName". When the workflow is hydrated this method will run. When you run your solution, there should be a pop up demonstrating that the CurrentStateName is returned to the runtime host from the workflow.