Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

microsoft press windows workflow foundation step by step phần 6 potx
MIỄN PHÍ
Số trang
35
Kích thước
560.6 KB
Định dạng
PDF
Lượt xem
1440

microsoft press windows workflow foundation step by step phần 6 potx

Nội dung xem thử

Mô tả chi tiết

Chapter 8 Calling External Methods and Workflows 179

10. This activates the Browse And Select A .NET Type dialog box. Select Workflow2 in the left

pane, which displays the Workflow2 type in the right pane. Select the Workflow1 type

(Workflow2.Workflow1 is the fully qualified name) in the right pane and click OK.

11. Visual Studio then examines the Workflow2 workflow and displays its graphical

representation inside the InvokeWorkflow activity in the visual workflow designer.

12. The workflow implementations are now complete, so we can add them as references to

the main WorkflowInvoker application. From Solution Explorer, right-click the Work￾flowInvoker project and select Add Reference. When the Add Reference dialog box

appears, click the Projects tab. Select both Workflow1 and Workflow 2 from the list and

click OK.

180 Part II Working with Activities

13. Next add the code to create and start the instance. Locate this line of code in

Program.cs:

Console.WriteLine("Waiting for workflow completion.");

14. Add this code following the line of code you just located:

// Create the workflow instance.

WorkflowInstance instance =

workflowRuntime.CreateWorkflow(typeof(Workflow1.Workflow1));

// Start the workflow instance.

instance.Start();

15. We’ll now add a small amount of code to the host application simply to tell us when

each workflow completes. Insert the following code in the event handler for

WorkflowCompleted:

if (e.WorkflowDefinition is Workflow1.Workflow1)

Console.WriteLine("Workflow 1 completed.");

else

Console.WriteLine("Workflow 2 completed.");

waitHandle.Set();

The first workflow to complete sets the AutoResetEvent we’re using to force the application to

wait for workflow completion. We could add code to force the application to wait for both

workflows, but for demonstration purposes this should suffice. If you compile and execute

the WorkflowInvoker application, you’ll see console output similar to what you see in

Figure 8-4. If the output messages appear in a slightly different order, don’t be alarmed. This is

the nature of multithreaded programming...

Figure 8-4 The WorkflowInvoker application console output

If you want to continue to the next chapter, keep Visual Studio 2005 running and turn to

Chapter 9, “Logic Flow Activities.” It’s one thing to crunch numbers, but we also need tools to

make decisions, and that’s the next topic.

If you want to stop, exit Visual Studio 2005 now, save your spot in the book, and watch your

favorite movie on DVD. Be sure to fast-forward through any boring parts.

Chapter 8 Calling External Methods and Workflows 181

Chapter 8 Quick Reference

To Do This

Design workflow/host data transfers Create an interface with methods designed to pass

the data back and forth. Be sure to add the

ExternalDataExchange attribute, as well as the correla￾tion attributes, as we did in the sample application.

Create the “data available” event arguments Derive an event argument class from

ExternalDataEventArgs, and anoint it with

information you need to pass back and forth.

Create the external data service This is a somewhat complex task in that you must write

a lot of code yourself to manage the data (which can

come from any number of workflow instances). But

in general, you create a class (the connector) that

manages the data (and is plugged into the workflow

runtime because it manages workflow state) and

another class (the service) that the host application (or

invoking workflow) uses to hook the “data available”

event and read (or write) the data.

Create the communications-based activities With your interface in hand, run wca.exe. The wca.exe

tool creates a pair of activities for you: one to send

data to the external (workflow) process and one to

receive data. In this chapter, we looked only at sending

data, but in Chapter 17 we’ll revisit this topic and build

a bidirectional interface.

Receive data in your host application (or

calling workflow)

Using the service class you created, hook the “data

available” event and call the services “read” method.

Invoke secondary workflows Add an instance of InvokeWorkflow to your workflow

process, and provide the data type of the workflow to

be invoked. Note you have to add a reference to the

secondary workflow to accomplish this.

Tải ngay đi em, còn do dự, trời tối mất!
microsoft press windows workflow foundation step by step phần 6 potx | Siêu Thị PDF