Datasheet

Chapter 1: Work ow Programming Principles
14
3. It then invokes the GetWorkflowQueue method to access the WorkflowQueue object that
represents the workflow queue that the activity created in its initialization phase. Note
that the method passes the QueueName property of its second argument into the
GetWorkflowQueue method. This is not important in our case because this activity creates a
single workflow queue in its initialization phase. However, in cases where the activity creates
more than one workflow queue in its initialization phase, you should use the QueueName
property to ensure that you re accessing the right workflow queue.
WorkflowQueue workflowQueue =
workflowQueuingService.GetWorkflowQueue(e.QueueName);
4. The method then invokes the Dequeue method on the WorkflowQueue object to access the
deposited data, and consumes it:
object data = workflowQueue.Dequeue();
5. The WorkflowQueue_QueueItemAvailable method is part of the execution logic of our activity
because it was the Execute method of our activity that registered this method as an event
handler for the QueueItemAvailable event of the workflow queue. Once the event handler is
registered, our activity can resume its execution where it left off when the external entity finally
deposits the data into the workflow queue. The workflow run time expects every execution
method to notify it when the execution status of the activity changes. Such notification can occur
in two different forms.
If the method returns a value of the ActivityExecutionStatus type, then it must return the appro-
priate ActivityExecutionStatus enumeration value. Otherwise, it must invoke the appropriate
method on the ActivityExecutionContext to inform the workflow run time of the execution sta-
tus change. Execution methods such as Execute, Cancel, and HandleFault return a value of the
ActivityExecutionStatus type. Execution methods such as event handlers do not. In this case, the
WorkflowQueue_QueueItemAvailable method invokes the CloseActivity method on the Activi-
tyExecutionContext to inform the workflow run time that the execution logic of the current ac-
tivity is now completed:
activityExecutionContext.CloseActivity();
The following example presents the complete code for the custom activity that we ve been developing in
last few sections:
using System.Workflow.ComponentModel;
using System.Workflow.Runtime;
using System;
namespace Chapter1
{
public class CustomActivity : Activity
{
protected override void Initialize(IServiceProvider provider)
{
WorkflowQueuingService workflowQueuingService =
provider.GetService(typeof(WorkflowQueuingService))
as WorkflowQueuingService;
c01.indd 14c01.indd 14 8/25/08 4:02:55 PM8/25/08 4:02:55 PM