《WF in 24 Hours》读书笔记

1. 修改workflow1.xaml,添加Flowchart,添加Flowdesicion,添加CodeActivity2,并且名字改为下图所示:

2. CodeActivity1和2的代码如下:

 1     public sealed class CodeActivity1 : CodeActivity
 2     {
 3         // Define an activity input argument of type string
 4         public InArgument<string> Text { get; set; }
 5 
 6         // If your activity returns a value, derive from CodeActivity<TResult>
 7         // and return the value from the Execute method.
 8         protected override void Execute(CodeActivityContext context)
 9         {
10             Console.WriteLine("executed in the left branch");
11         }
12 }
13 
14     public sealed class CodeActivity2 : CodeActivity
15     {
16         // Define an activity input argument of type string
17         public InArgument<string> Text { get; set; }
18 
19         // If your activity returns a value, derive from CodeActivity<TResult>
20         // and return the value from the Execute method.
21         protected override void Execute(CodeActivityContext context)
22         {
23             Console.WriteLine("executed in the right branch");
24         }
25     }

3. 修改program.cs

 1         static void Main(string[] args)
 2         {
 3             // Add the parameters via a dictionary object
 4             Dictionary<string, object> parameters = new Dictionary<string, object>();
 5             parameters.Add("Amount", 1200);
 6 
 7             Activity workflow1 = new Workflow1();
 8             WorkflowInvoker.Invoke(workflow1, parameters);
 9 
10             // Pause the display
11             Console.WriteLine("Press enter to continue.");
12             Console.Read();
13         }

4. 打开Workflow1.xaml文件,设置Flowdecision的condition为Amount < 1000

5. 还是在workflow1.xaml中添加Argument

6. 运行。结果如下:

7. 修改program.cs的Amount为900,运行。结果如下:

原文地址:https://www.cnblogs.com/ilovewindy/p/3709334.html