workflow,WorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0

开篇

上篇我们主要是讲述了《WorkFlow设计篇Step.6—InvokeMethod调用对象或类型方法-WF4.0》如何使用InvokeMethod完成工作流的设计与开发,本篇我们将要开始讲述
扩展篇的内容,主要是讲述如何使用集合Collection在工作流中的用法。

摘要

本篇我们是扩展篇的第一篇,本篇主要是讲述Collection的用法,一般来说我们对集合的操作,无非就是以下几种,增、删、查这几种,所以WF默认提供了一下四种
集合活动:
imageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
具体的作用,我想大家从字面上也能看出来个八九不离十,下面我们就具体的使用细节来说明下吧。
最后,我们来整理个流程,把这四类集合的活动,全部集成到一个流程中看看吧。

大纲

1、开篇
2、摘要
3、大纲
4、集合活动的用法

集合的用法

1、AddToCollection活动

1、新建一个控制台项目:
imageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
2、将相应的节点添加到设计器中:
imageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
3、在顺序控制流中拖拽一个AddToCollection活动,选中该活动并查看相关属性,按F4 如下:
imageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
4、我们在sequence内定义一个变量,是集合类型的,比如Ilist,我们设置AddToCollection活动的相关属性:
a、添加变量:
imageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
并且给MyCollection必须要初始化,否则会报错:
imageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
b、设置AddToCollection活动的属性如下:
imageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
5、我们添加个foreach活动。循环输出集合中的内容:
imageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
6、F5,运行查看结果吧,看看是否结果与我们的预期相符:
imageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
上面我们就完成了AddToCollection活动的说明,其他的几个活动的用法也相仿。
下面我们就来看看ClearCollection的用法吧,该活动的主要作用是将集合内的Item清空。

2、ClearCollection活动

关于Clear的具体作用就是清空具体的目标集合内的所有项,具体的用法,我们下面来一一道来:
1、新建一个活动文件,并拖拽一个sequence与AddToCollection,并添加一个ClearCollection活动:
imageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
2、设置ClearCollection活动的相关属性如下:
imageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
3、接着我们来添加几个WriteLine活动,来标识WF流程的开始和结束,并记录每个操作的具体内容如下:
imageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
imageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
imageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
上面的内容,有点多,所以我拆开截图了,不过上面的几幅图拼一起就是完整的了,还望大家如果有看不明白的请看代码吧:
4、F5,运行后,查看具体的运行结果吧,看看是不是我们想要的,看看在执行完毕ClearCollection活动后,集合还会不会输出结果呢?
imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
5、为了更清晰的演示,我们在上面多加几个AddToCollection活动,向集合内部多加一些Item吧:
imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
6、继续F5,查看运行效果吧:
imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
7、大伙应该发现了,其实我们上面的AddToCollection并不是特别的方便使用,我们在实际的场景中可能是使用While循环来添加节点吧?
或者是其他的循环方式,下面我们通过循环来向集合中添加元素。
a、定义MyFlag变量,Int32类型,定义在sequence上,用户控制循环的次数
imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
b、删除原来的AddToCollection活动,添加While活动如下:
imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow
c、F5运行,查看运行输出的效果,看看和我们想的是否一样:
imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow

源码下载

download233232222222imageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageimageWorkFlow扩展篇Step.1—集合分组下的活动使用[上]-WF4.0workflow

更多交流

官方博客:http://www.smarteas.net/
官方网站:http://www.agilelab.cn/
如果您在使用AgileEAS.NET开发平台中有什么问题,请使用如下几种联系方式或者沟通方式。
1、邮箱方式:
魏琼东: [email protected] 手机:18629261335 博客:http://eastjade.cnblogs.com/
殷长波:[email protected] 博客: http://www.cnblogs.com/onmyway/
何戈洲:[email protected] 博客:http://www.cnblogs.com/hegezhou_hot/
2、QQ交流群:
AgileEAS.NET平台交流群:120661978(超级群)[新建]
Tags: 

延伸阅读

最新评论

发表评论