1. Open Visual Studio 2005 by going to the Start Menu Programs Microsoft Visual Studio 2005 Microsoft Visual Studio 2005
2. In Visual Studio 2005, select the File New Project menu command.
3. Visual Studio 2005 will display the New Project dialog window.
4. In the New Project dialog window, expand Visual C# Workflow in the Project Types tree on the left side.
5. Select the template named “Sequential Workflow Console Application” and enter the following values:
Name: HelloWorldWorkflow
Location: C:\Windows Workflow Foundation\Labs\Lab01
6. You should now have a new solution and workflow project.
7. The project template has a Workflow1.cs which we will remove as we will be using a simpler kind of workflow for this lab. Click on Workflow1.cs and press the DEL key. Click the okay button to confirm.
8. Right click on the HelloWorldWorkflow project in Solution Explorer and select Add New Item from the context menu.
9. In the Add New Item dialog window, select the item template named Sequential Workflow (with code separation) and click the Add button to add the new workflow to the HelloWorldWorkflow project.
Note: It may be easier to read the template names if you change the view of the Add New Item dialog to large Icons by clicking on the toolbar icon in the upper right corner.
10. The new Sequential Workflow project will now contain two files: Workflow1.xoml and Workflow1.xoml.cs. Workflow1.xoml contains the XML markup that represents the workflow type. Workflow1.xoml.cs contains the code-beside class for the workflow.
Task 2 – Add a code activity
1. Double click on the Workflow1.xoml file in Solution Explorer to open the Visual Studio workflow designer.
2. In the workflow designer, select the View Toolbox menu command to display the toolbox with available activities.
3. You may need to expand the Windows Workflow category in the toolbox to view the Windows Workflow Foundation activities.
4. Select the Code activity from the toolbox.
5. Drag and drop the Code activity to the design surface for the Sequential Workflow.
6. Notice the red exclamation mark on the new Code activity. Click the exclamation mark to view the smart tag and the reason for why it’s being displayed.
7. Selecting the smart tag will cause the Properties tool window to be displayed with the ExecuteCode property highlighted.
8. Enter the value codeActivity1_CodeHandler for the ExecuteCode property and press Enter.
9. This will cause a new method or handler to be added to the code-beside class for the workflow. Visual Studio will automatically open the Workflow1.xoml.cs code file and display the new codeActivity1_CodeHandler method. Alternatively, you can switch from the design view to the code-beside for the workflow by double-clicking on the activity or by selecting the View Code menu item.
10. The code-beside class is a partial class that inherits from the SequentialWorkflowActivity base class. This code-beside class will have the same name as the workflow. You should have the following code in your code-beside class:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace HelloWorldWorkflow
{
public partial class Workflow1 : SequentialWorkflowActivity
{
private void codeActivity1_CodeHandler(object sender, EventArgs e)
{
}
}
}
private void codeActivity1_CodeHandler(object sender, EventArgs e)
{
Console.WriteLine("Hello, World!");
}
For this exercise we are going to use the simple host in program.cs that comes with the project template that was selected. Alternatively, you could build your own workflow host application by using the workflow runtime APIs defined in the System.Workflow.Runtime namespace.
1. Open the Visual Studio workflow designer by double clicking on workflow1.xoml in the solution explorer.
2. Click on the codeActivity1 activity to select it and set a breakpoint on it.
3. To set the breakpoint right-click on the code1 activity and choose Breakpoint Insert Breakpoint.
4. You should now see a red circle to the left of the code1 activity.
6. The ConsoleTestHost will start a workflow instance and that instance will break in the debugger when it gets to the code activity. The yellow box indicates the activity that the debugger is stopped at
9. The workflow will now complete and the program finishes.
No comments:
Post a Comment