Datasheet
Chapter 1: Workfl ow Programming Principles
15
if (!workflowQueuingService.Exists(this.Name))
workflowQueuingService.CreateWorkflowQueue(this.Name, true);
}
protected override void Uninitialize(System.IServiceProvider provider)
{
WorkflowQueuingService workflowQueuingService =
provider.GetService(typeof(WorkflowQueuingService))
as WorkflowQueuingService;
if (workflowQueuingService.Exists(this.Name))
workflowQueuingService.DeleteWorkflowQueue(this.Name);
}
protected override ActivityExecutionStatus Execute(
ActivityExecutionContext executionContext)
{
WorkflowQueuingService workflowQueuingService =
executionContext.GetService < WorkflowQueuingService > ();
WorkflowQueue workflowQueue =
workflowQueuingService.GetWorkflowQueue(this.Name);
if (workflowQueue.Count > 0)
{
object data = workflowQueue.Dequeue();
// Consume the data here
return ActivityExecutionStatus.Closed;
}
workflowQueue.QueueItemAvailable +=
new EventHandler < QueueEventArgs > (WorkflowQueue_QueueItemAvailable);
return ActivityExecutionStatus.Executing;
}
void WorkflowQueue_QueueItemAvailable(object sender, QueueEventArgs e)
{
ActivityExecutionContext activityExecutionContext =
sender as ActivityExecutionContext;
WorkflowQueuingService workflowQueuingService =
activityExecutionContext.GetService < WorkflowQueuingService > ();
WorkflowQueue workflowQueue =
workflowQueuingService.GetWorkflowQueue(e.QueueName);
object data = workflowQueue.Dequeue();
// Consume the data
activityExecutionContext.CloseActivity();
}
}
}
As mentioned earlier, you will not directly use lower - level objects such as workflow queues and
WorkflowQueuingService to implement custom activities in SharePoint. However, you do need a solid
understanding of these lower - level objects and the fundamental role they play in WF in order to be a
successful activity developer. Such an understanding is the key to understanding standard SharePoint
workflow activities and workflow programming discussed throughout this book.
c01.indd 15c01.indd 15 8/25/08 4:02:55 PM8/25/08 4:02:55 PM