Datasheet

Chapter 1: Work ow Programming Principles
8
Listing 1 - 2 presents an example of the implementation of the Initialize method of an activity whereby the
activity creates a workflow queue.
Listing 1 - 2: A typical implementation of the Initialize method
Using System;
using System.Workflow.ComponentModel;
using System.Workflow.Runtime;
namespace Chapter1
{
public class CustomActivity : Activity
{
protected override void Initialize(IServiceProvider provider)
{
WorkflowQueuingService workflowQueuingService =
provider.GetService(typeof(WorkflowQueuingService))
as WorkflowQueuingService;
if (!workflowQueuingService.Exists(this.Name))
workflowQueuingService.CreateWorkflowQueue(this.Name, true);
}
}
}
Follow these steps to create a workflow queue:
1. Invoke the GetService method on the IServiceProvider object, passing in the Type object that
represents the type of workflow queuing service to access the WorkflowQueuingService service:
WorkflowQueuingService workflowQueuingService =
provider.GetService(typeof(WorkflowQueuingService))
as WorkflowQueuingService;
2. Invoke the Exists method on the WorkflowQueuingService service, passing in the workflow
queue name to ensure that the service does not already contain a workflow queue with the same
name. If your custom activity needs to create only a single workflow queue, use the name of
your activity as the workflow queue name. The name of your activity is set by the workflow
designer that uses your activity. You can access this name through the Name property of your
activity:
if (!workflowQueuingService.Exists(this.Name))
3. If the workflow queuing service does not already contain a workflow queue with the same
name, then invoke the CreateWorkflowQueue method on the WorkflowQueuingService service,
passing in the workflow queue name to create the workflow queue:
workflowQueuingService.CreateWorkflowQueue(this.Name, true);
You will see throughout this book that you don t need to create workflow queues when programming
SharePoint activities, because SharePoint workflow programming abstracts you away from workflow
queues. That said, you still need to have a solid understanding of workflow queues to understand
SharePoint workflow programming, which is thoroughly covered throughout this book.
c01.indd 8c01.indd 8 8/25/08 4:02:53 PM8/25/08 4:02:53 PM