Workflow designer
Even a simple workflow design makes it difficult for you to view the entire workflow graph. Fortunately, the designer has some very useful tool areas to help us work in a large workflow. Click the collapse link in the upper-right corner of the designer. The workflow diagram is shown in the Figure1-20.
This allows you to quickly see the top-level activities. Click expand all. All the activities are displayed, but now you can only see a part of the workflow diagram. Click the overview button in the lower-right corner to display a window showing the entire workflow diagram. You can drag to your favorite place. Close the overview window and click the fit to screen button. At this time, the designer will zoom quickly to adapt the workflow diagram to the screen size and display the entire workflow diagram. Depending on the size of your monitor, it may be too small. You can click the drop-down list in the lower right corner to resize the workflow chart. Finally, you click the "zoom in" button (also in the lower right corner), and the workflow chart changes back to the original 100% status.
Double-click the sound Bell activity. "Sound bell" will show itself and its sub-activities. To help you know where the focus is in the workflow, the designer provides us with a navigation bar, as shown in the Figure1-21.
You can click any link in the navigation bar. Click the workflow1 link to display the entire workflow diagram.
Let's take a deeper look
Let's take a look at what we have done. First, I have mentioned that workflows are defined using XAML files. So far, you have used a graphical method to define a workflow. Now let's take a look at how the designer actually generates the workflow design. In Solution Explorer, right-click the sequence. XAML file and select Code view ). You will see a warning: the file has been opened. Click Yes to close the designer window .. The XAML code will be shown in the Listing1-2.
I want to show some rows in bold to help you find the top-level activity. First, the variables node defines two variables (variables ). Next is a writeline activity named "hello" and an if activity named "adjust for PM ". Next, a while activity is called "sound bells", a writeline activity is called "display time", and an if activity is called "greeting ".
One of the key points I want you to know is that there is no Execution code here. This file is just a set of attributes. For example, to increment counter, you may want to see the following code:
Counter = counter + 1;
Here, an assign is used to include a counter and a counter + 1. Put counter = counter + 1 in the assign activity. Code is only executed in the active class, but there is no executable code in the workflow definition.
Different from previous versions
If you have used a previous workflow version (Version 3.0 or 3.5), you may want to know what the difference is. WF 4.0 is completely different from the original version. Previous versions of the program can run well in. net4.0, because the previous activities and services have basically not changed. The WF 4.0 is a completely new design. Activities and services of WF 4.0 cannot be run in previous versions. So you can use WF 3.5 or WF 4.0. However, you cannot switch back and forth. Except for a small part of the script, we will discuss it later.
In WF 3.5, there is a code class and a design view class. The Code class contains the application serving codeactivity, the definition of Class Members, and the definition of event delegation. In WF 4.0, There is no code class. Codeactivety is not found in WF 4.0. To make up for this function, WF 4.0 provides the function implemented in codeactivity before the activity is implemented. Writeline and assign are two such activities. If the predefined activity does not meet your needs, you can create a user activity and use codeactivity to implement the required functions.
Another difference is that WF 4.0 explicitly uses variables (variables) and arguments (parameters ). Because there is no code file here, you cannot simply add class members to meet your program development needs. Here, you need to define variables and arguments in a way specific to the workflow (the specific definition has been described. If you do not understand it, please refer to the previous discussion ).
Finally, you may notice that there is no workflow runtime in program. cs. In the previous version, you will create a class for workflow runtime and then call its createworkflow () method. In WF 4.0, you only need to call the following code:
Workflowinvoker. Invoke (New workflow1 ());
There are many differences, such as the absence of a state machine workflow. I will not elaborate on it because the purpose of this book is not to tell the differences between WF 4.0. I don't want to talk about some obvious changes. You should start your brain to think.