制作自定义工作流(WWF)设计器
注:
l 这是一篇翻译,来自http://msdn2.microsoft.com/en-us/library/aa480213.aspx
l 对于一些细节我没有完全翻译
l 增加了一些我的注释,在“[]”里面
l 主要是给朋友们介绍一下这方面的情况
Vihang Dalal
Software Development Engineer Test
Microsoft Corporation<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
May 2006
应用于:
Windows Workflow Foundation beta 2.2
Microsoft Visual C# Version 2.0
Visual Studio 2005
demo下载:Download the code sample, WorkflowDesignerControl.exe.
摘要:如果你在vs2005里面安装了Visual Studio 2005 extensions for Windows Workflow Foundation,你就可以使用WWF的可视化编辑器了。这篇文章就是介绍如何在自己的程序中使用这个设计器的一些方法。并且附带有一个简单的例子程序[注:确实可以使用,默认顺序工作流,可以在程序中修改实现。]
主要内容包括
l 自定义设计器的介绍
l 自定义设计器的类
l 主要功能和自定义的服务(Services)
l 结论
l 更多资源
自定义设计器的介绍:
这篇文章主要讲述了如何使用设计器的api,以及其他扩展。
我们为什么会用到自定义设计器?
l 自定义自己的视图,可以增加/减少一些实现
l 在现有的程序中加入自己的设计器
l [我用的Web Developer 2005 Express,所以我无法安装WWF设计器,只能用这个了]
什么时候用到这个设计器?
l 设计时:可以创建、编辑工作流
l 运行时:可以跟踪工作流状态
这里提供的例子程序可以独立于vs2005开发工具之外单独运行
自定义设计器的类
主要包括:DesignSurface, WorkflowView, and WorkflowDesignerLoader
DesignSurface使用WorkflowDesignerLoader来创建活动(Activety)树和其他组建的树;WorkflowView则用来显示工作流实例(一个xml文件)的默认视图.
DesignSurface提供一个环境(self-contained)来显示设计器组件
WorkflowDesignerLoader可以用来加载(PerformLoad())和卸载(PerformFlush())一个工作流的定义。开发者可以使用者个类来自定义工作流保存的方式,可以序列化到自己的媒介中(数据库…)
WorkflowView是用来显示一个具体的工作流实例的。他借助DesignSurface来显示其中activety的信息。同时他也提供很多用于显示时的控制事件(OnLayout() and OnPaint()),还提供诸如SaveWorkflowAsImage()之类的函数。
下边这段代码可以用来制作一个简单的winform的设计器
创建自定义WorkflowDesignerLoader:(重写PerformLoad() and PerformFlush())
· {
· protected override void PerformLoad(IDesignerSerializationManager serializationManager)
· {
· base.PerformLoad(serializationManager);
· // Implement the logic to read from the serialized state,
· // create the activity tree and the corresponding designer
· // tree and add it to the designer host
· }
·
· protected override void PerformFlush(IDesignerSerializationManager manager)
· {
· // Implement the logic to save the activity tree to a
· // serialized state along with any code beside elements
· }
· }
加载工作流,显示
·
· DesignSurface designSurface = new DesignSurface();
· WorkflowLoader loader = new WorkflowLoader();
·
· // load the design surface using the loader. This will call the
· // PerformLoad method on the loader, create the activity tree and
· // add the corresponding designer components to the designer host
·
· designSurface.BeginLoad(loader);
·
· // Get the designer host and retrieve the corresponding root component
· IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
· if (designerHost != null && designerHost.RootComponent != null)
· {
· // Get the designer associated with the root component
· IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
· if (rootDesigner != null)
· {
· this.designSurface = designSurface;
· this.loader = loader;
·
· // Assign the default view of the rootdesigner to WorkflowView
· this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
·
· // Add the workflow view control to winforms app
· this.workflowViewSplitter.Panel1.Controls.Add(this.workflowView);
· this.workflowView.Focus();
· this.propertyGrid.Site = designerHost.RootComponent.Site;
· }
· }
还需要一个DesignerHost类,用来装载各种服务,和向外提供各类服务接口。
http://msdn2.microsoft.com/en-us/library/Aa480213.wfdsgnrehst02(en-us,MSDN.10).gif
主要功能和自定义的服务(Services)
System.Workflow.ComponentModel提供了一些默认类的实现,比方说“IIdentifierCreationService, IReferenceService, IworkflowCompilerOptionsService”等。但是如果要自定义设计器,可能需要你客户化自己的实现类(Service)
1:上下文菜单和通用设计器的功能(Context Menu And Common Designer Features:);
菜单WorkflowMenuCommandService继承自MenuCommandService,用来显示菜单命令。这些代码用来增加一些额外的命令菜单
· ContextMenu contextMenu = new ContextMenu();
· Dictionary<CommandID, string> selectionCommands = new Dictionary<CommandID, string>();
·
· // Add the required commands
· selectionCommands.Add(WorkflowMenuCommands.Cut, "Cut");
· selectionCommands.Add(WorkflowMenuCommands.Copy, "Copy");
· selectionCommands.Add(WorkflowMenuCommands.Paste, "Paste");
· selectionCommands.Add(WorkflowMenuCommands.Delete, "Delete");
· foreach (CommandID id in selectionCommands.Keys)
· {
· MenuCommand command = FindCommand(id);
· if (command != null)
· {
· // For each command create a new menu item and add an
· MenuItem menuItem = new MenuItem(selectionCommands[id], new EventHandler(OnMenuClicked));
· menuItem.Tag = command;
· contextMenu.MenuItems.Add(menuItem);
· }
· }
·
· // Handle the event when the MenuItem is clicked
· private void OnMenuClicked(object sender, EventArgs e)
· {
· // Retrieve the menu item that was clicked
· MenuItem menuItem = sender as MenuItem;
· if (menuItem != null && menuItem.Tag is MenuCommand)
· {
· // invoke the command corresponding to the menu item clicked
· MenuCommand command = menuItem.Tag as MenuCommand;
· command.Invoke();
· }
· }
这样,在界面上就可以显示出你自己的上下文菜单了
关于菜单命令的响应处理:
· this.workflowDesignerControl1.InvokeStandardCommand(WorkflowMenuCommands.Expand);
·
· public void InvokeStandardCommand(CommandID cmd)
· {
· IMenuCommandService menuService =
· GetService(typeof(IMenuCommandService)) as IMenuCommandService;
· if (menuService != null)
· menuService.GlobalInvoke(cmd);
· }
http://msdn2.microsoft.com/en-us/library/Aa480213.wfdsgnrehst03(en-us,MSDN.10).gif
2:生成后台代码MemberCreationService,和EventBindingService
MemberCreationService可以用来生成关于Member,Filed的之类的定义
EventBindingService则可以生成和设计界面上事件关联的代码的映射。比方说“CodeActivty”要执行的代码xxx_Excute函数和后台编译后的代码的关联。
· CodeMemberMethod method = new CodeMemberMethod();
· method.Name = methodName;
· method.Parameters.AddRange(paramCollection);
· method.ReturnType = new CodeTypeReference(returnType);
· method.Attributes = modifiers;
·
· //push the method into the code compile unit
· typeDeclaration.Members.Insert(index, method);
·
· // refresh the code compile unit
· TypeProvider typeProvider = (TypeProvider)this.serviceProvider.GetService(typeof(ITypeProvider));
· typeProvider.RefreshCodeCompileUnit(this.ccu,new EventHandler(RefreshCCU));
其后台代码可能这样
· {
· private void EventHandler(object sender, System.EventArgs e)
· {
· }
· }
xml的定义可能这样:
3:显示工具箱的ToolBoxService
这个类继承自:IToolboxService,他可以显示工作流设计中需要的各类组件。
http://msdn2.microsoft.com/en-us/library/Aa480213.wfdsgnrehst04(en-us,MSDN.10).gif
4:显示组件属性的ActivityBind Dialog: IPropertyValueUIService
一般使用PropertyValueUIItem来传递数据
http://msdn2.microsoft.com/en-us/library/Aa480213.wfdsgnrehst05(en-us,MSDN.10).gif
5:Rules Dialog:用来编辑各种Rule。
这个用来编辑rule,ruleSet
http://msdn2.microsoft.com/en-us/library/Aa480213.wfdsgnrehst07(en-us,MSDN.10).gif
6:处理状态机State Machine Features:
这段代码用来处理状态机
2. string layoutFile = Path.Combine(Path.GetDirectoryName(this.xoml), Path.GetFileNameWithoutExtension(this.xoml) + ".layout");
3. ActivityDesigner rootdesigner = host.GetDesigner(rootActivity) as ActivityDesigner;
4. XmlWriter layoutwriter = XmlWriter.Create(layoutFile);
5. IList errors = null;
6. SaveDesignerLayout(layoutwriter, rootdesigner, out errors);
7. layoutwriter.Close();
8.
9. // Load the layout
10. string layoutFile = Path.Combine(Path.GetDirectoryName(this.xoml), Path.GetFileNameWithoutExtension(this.xoml) + ".layout");
11. if (File.Exists(layoutFile))
12. {
13. IList loaderrors = null;
14.
制作自定义工作流(WWF)设计器相关推荐
- 基于Vue实现的Activiti工作流Web设计器
真正的大师,永远都怀着一颗学徒的心! 一.项目简介 基于Vue实现的Activiti工作流Web设计器 二.实现功能 支持生成xml文件 支持生成子流程 支持连线 组件有:起点.终点.判断.条件.任务 ...
- vue自定义表单设计器思路
Vue是一种流行的JavaScript框架,用于构建Web应用程序.Vue的灵活性使得它成为一种非常适合创建自定义表单设计器的框架.本文将介绍如何使用Vue实现一个自定义表单设计器,并最终实现单据自定 ...
- 制作风车-Apace组态设计器
Apace实时数据库产品系列中提供了强大的组态设计功能,并通过Javascript脚本能制作出模拟真实场景的制动组态画面,最终在silverlight上呈现给客户. 下面就基于该组态设计器制作一个电厂 ...
- java代码制作activiti会签_activiti设计器会签人员配置
使用activiti设计器进行流程图绘制,并且配置会签和或签人员,我也是在学习中,通过不断查阅资料,总结了三种方式配置会签人员 在配置人员之前,我们先说一下多实例类型 并行和串行 并行:并行代表同时进 ...
- [转]由于项目原因看了一下vml,写了一个Web工作流的设计器雏形!
主要使用了vml三个对象.line,group,RoundRect. 这里是运行截图: 测试环境:ie7(winxp). ie6 (win2003) 如果是发布到iis目录下运行,那么在ie安全级 ...
- Custom Windows workflow Desiger 自定义Windows工作流设计器
注: l 这是一篇翻译,来自http://msdn2.microsoft.com/en-us/library/aa480213.aspx l 对于一些细节我没有完全翻译 ...
- Web工作流(流程图)设计器的方案研究及功能实现之bpmn-js简易教程
前言 本文以2020年10月为时间节点,功能早就做了,但文章一直没有写 研究过程 根据项目需求,需要实现一个工作流/流程图设计器,并且可配置流转.活动节点.流程的各项属性,也是研究了多个方案 自研方案 ...
- [WF4.0]工作流设计器Rehosting(一)
因为WF4.0使用WPF做可视化设计,能够利用WPF的数据绑定和其他一些内部实现,极大的简化了工作流设计器的开发工作:不用像3.5和3.0中那样,要开发一些服务类来支持工作流的设计操作. 首先看看Wo ...
- Flex写的一个工作流设计器原型
流程设计器是编辑流程模版的工具,可视化的流程设计器能直观的编辑流程模版,所见即所得,如下图是我们要做的流程设计器: 流程模版存放流程流转所需要的信息,使用流程设计器来管理流程模版是比较常见的方式,我见 ...
最新文章
- 分布式服务化系统一致性的“最佳实干”--转
- 神策数据:从技术视角看,如何更多、更好、更快地实施A/B试验
- 操作系统实验报告5:进程的创建和终止
- 偏向锁的获取和撤销逻辑
- [渝粤教育] 西南科技大学 工程力学 在线考试复习资料
- python thread join timeout_了解thread.join(超时)
- Linux 命令(50)—— date 命令
- 【Python】Python简介
- httpd在嵌入式中应用
- PDF.js插件 | 在线PDF阅读插件,支持手机在线阅读
- matlab画圆的命令_matlab画圆命令
- 利用Java开源库把汉字转拼音(推荐OK)_爱题巴.爱技术.小川哥_百度空间
- 2022年最新软件测试面试题+答案解析(每日20题,持续更新中)【六】
- 慎用!3个容易被打的Python恶搞脚本!
- 坐标测量机的定位误差和测长不确定度有何区别,如何表示?
- Apache AXIS 1.4 RCE
- 基础——树莓派3B配置
- python实现图片压缩_python如何实现图片压缩
- Docker Nginx 如何重新加载配置
- 如何加强大数据安全管理和防护
热门文章
- 信息学奥赛一本通 1962:【13NOIP普及组】表达式求值 | 洛谷 P1981 [NOIP2013 普及组] 表达式求值
- 信息学奥赛一本通(1102:与指定数字相同的数的个数)
- 4-adjacent(AtCoder-2686)
- 图论 —— 网络流 —— 最大流 —— FF 算法与 EK 算法
- 字符串处理 —— 回文串相关 —— 添加/删除字符后是否为回文串
- 机器翻译(洛谷-P1540)
- 42 CO配置-控制-产品成本控制-成本对象控制-实际成本核算/物料分类帐-激活实际成本核算
- java代码鸟飞_180行原生js代码实现简易版飞行的小鸟游戏
- linux PCI驱动调用字符设备驱动方式
- python io密集型应用案例-Python中单线程、多线程和多进程的效率对比实验实例