标签:
Program.cs 后台代码:
class Program
{
static void Main(string[] args)
{
//Activity workflow1 = new Workflow1();
//WorkflowInvoker.Invoke(new Workflow1());
WorkflowInvoker.Invoke(MyCodeWorkFlow.CreateWorkFlow());
Console.ReadLine();
}
}
WorkFlow 的例子 代码 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Statements;
namespace WorkflowConsoleApplication1
{
public class MyCodeWorkFlow
{
public static Activity CreateWorkFlow()
{
//定义两个变量:时钟响几次数,现在的时间(小时)
Variable<int> count = new Variable<int>()
{
Name="count",
Default=0
};
Variable<int> timeNowHour = new Variable<int>()
{
Name="timeNowHour",
Default=DateTime.Now.Hour
};
//Sequence 是Activity的子类,里面写逻辑思维
return new Sequence()
{
DisplayName = "Main Sequence",
Variables = { count, timeNowHour },//表示 全局变量可以在这个域 里使用
//声明一种活动
Activities = {
new WriteLine(){
DisplayName="问候",
Text="Hello World !"
},
new If()
{
DisplayName="判断",
Condition=ExpressionServices.Convert<bool>(u=>timeNowHour.Get(u)>12),
Then=new Assign<int>()//Assign 相当于 给某个变量赋值
{
To=timeNowHour,// 给 哪个 变量赋值
Value=new InArgument<int>(m=>timeNowHour.Get(m)-12) // 赋 什么值
}
},
new Sequence()
{
DisplayName="时钟报时",
Activities={
new While()
{
Condition=ExpressionServices.Convert<bool>(u=>count.Get(u)<timeNowHour.Get(u)),
Body=new Sequence()
{
Activities={
new Assign<int>(){To=count,Value=new InArgument<int>(m=>count.Get(m)+1)},
new WriteLine(){DisplayName="报时", Text=new InArgument<string>(u=>count.Get(u).ToString())},
//延时,每隔1秒 ,报时一次
new Delay(){Duration=TimeSpan.FromSeconds(1)}
}
}
}
}
},
new Sequence() //Sequence 可以理解成 内部类
{
DisplayName="当前时间",
Activities={
new WriteLine(){ Text=string.Format("当前时间为:"+DateTime.Now.ToString())}
}
},
new Sequence()
{
DisplayName ="根据时间的不同 来问好!",
Activities={
new If(){Condition=ExpressionServices.Convert<bool>(u=>DateTime.Now.Hour>=18),
Then=new WriteLine(){Text="晚上好!"},
Else=new WriteLine(){ Text="白天好!"}
}
}
}
}
};
}
}
}
标签:
原文地址:http://www.cnblogs.com/dlf-myDream/p/4617507.html