.Net WorkFlow 的简单例子

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="白天好!"}
}

}

}

}

};

}
}
}

时间: 2024-08-03 17:35:26

.Net WorkFlow 的简单例子的相关文章

从一个简单例子来理解js引用类型指针的工作方式

? 1 2 3 4 5 6 7 <script> var a = {n:1};  var b = a;   a.x = a = {n:2};  console.log(a.x);// --> undefined  console.log(b.x);// --> [object Object]  </script> 上面的例子看似简单,但结果并不好了解,很容易把人们给想绕了--"a.x不是指向对象a了么?为啥log(a.x)是undefined?".&

Hadoop RPC简单例子

jdk中已经提供了一个RPC框架-RMI,但是该PRC框架过于重量级并且可控之处比较少,所以Hadoop RPC实现了自定义的PRC框架. 同其他RPC框架一样,Hadoop RPC分为四个部分: (1)序列化层:Clent与Server端通信传递的信息采用了Hadoop里提供的序列化类或自定义的Writable类型: (2)函数调用层:Hadoop RPC通过动态代理以及java反射实现函数调用: (3)网络传输层:Hadoop RPC采用了基于TCP/IP的socket机制: (4)服务器端

extern外部方法使用C#简单例子

外部方法使用C#简单例子 1.增加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", SetLastError = true)] 3.声明外部方法public static extern int GetCurrentDirectory(int a, StringBuilder b); 4.对外部方法操作  GetCurrentDirectory(300, pathstring); using

事件简单例子

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Runtime.InteropServices; 6 7 namespace EventTest 8 { 9 /// <summary> 10 /// 事件订阅者类 11 /// </summary> 12 class Program 13 { 14 static v

spring mvc(注解)上传文件的简单例子

spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationContext.xml中 <bean id=”multipartResolver” class=”org.springframework.web.multipart.commons.CommonsMultipartResolver”/> 关于文件上传的配置不能少 大家可以看具体代码如下: web.xml &

自定义隐式转换和显式转换c#简单例子

自定义隐式转换和显式转换c#简单例子 (出自朱朱家园http://blog.csdn.net/zhgl7688) 例子:对用户user中,用户名first name和last name进行转换成合成一个限定长度为10个字符新name. 自定义隐式转换: namespace transduction { public partial class transductionForm : Form { public transductionForm() { InitializeComponent();

Workflow相关表简单分析

静态定义表(没有ITEM_KEY,因为ITEM_KEY代表一个wf实例) --获取item_type定义. SELECT * FROM wf_item_types t WHERE t.name= 'CUX_TEST'; /*查询指定ITEM_TYPE中新建的activitie定义(没有activity的id).*/ SELECT * FROM wf_activities_tlt WHERE t.item_type= 'CUX_0005' AND t.version= 1; /*查询指定PROCE

使用fastjson转换json的简单例子

pom添加依赖: <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.1.41</version> </dependency> 代码: package JsonTest.JsonTest; import java.util.ArrayList; import java.util.Hash

最简单例子图解JVM内存分配和回收

一.简介 JVM采用分代垃圾回收.在JVM的内存空间中把堆空间分为年老代和年轻代.将大量(据说是90%以上)创建了没多久就会消亡的对象存储在年轻代,而年老代中存放生命周期长久的实例对象.年轻代中又被分为Eden区(圣经中的伊甸园).和两个Survivor区.新的对象分配是首先放在Eden区,Survivor区作为Eden区和Old区的缓冲,在Survivor区的对象经历若干次收集仍然存活的,就会被转移到年老区. 简单讲,就是生命期短的对象放在一起,将少数生命期长的对象放在一起,分别采用不同的回收