注:
l         这是一篇翻译,来自http://msdn2.microsoft.com/en-us/library/aa480213.aspx
l         对于一些细节我没有完全翻译
l         增加了一些我的注释,在“[]”里面
l         主要是给朋友们介绍一下这方面的情况
Vihang Dalal
Software Development Engineer Test
Microsoft Corporation
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()
·                           internal sealed class WorkflowLoader : WorkflowDesignerLoader
·                           {
·                              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 
·                                 }
·                           }

加载工作流,显示

·                           // Create new Design surface and loader (created as shown above)
·                            
·                           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,用来显示菜单命令。这些代码用来增加一些额外的命令菜单
·               // Create a new context menu
·               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();
·                     }
·               }

这样,在界面上就可以显示出你自己的上下文菜单了
关于菜单命令的响应处理:
·               // Invoke the standard command with the command id of the command clicked
·               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函数和后台编译后的代码的关联。
其后台代码可能这样
·               // create code member method

·               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));


 
的定义可能这样:
·               public partial class Workflow1 : SequentialWorkflowActivity
·               {
·                       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:
这段代码用来处理状态机
1.                          // Save the layout in case of State Machine Workflow
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.                             using (XmlReader xmlReader = XmlReader.Create(layoutFile))
15.                                LoadDesignerLayout(xmlReader, out loaderrors);
16.                          }
http://msdn2.microsoft.com/en-us/library/Aa480213.wfdsgnrehst09(en-us,MSDN.10).gif
7:其他功能Compile Workflow.(编译处理)
 
·                 WorkflowCompiler compiler = new WorkflowCompiler();
·               WorkflowCompilerParameters parameters = new WorkflowCompilerParameters();
·                
·               // adding the code beside file and XAML file to the arraylist of files to 
·               // be compiled
·               ArrayList files = new ArrayList();
·               files.Add(this.loader.Xoml);
·               files.Add(codeBesideFile);
·                
·               // adding the rules file to the resources
·               string resources = @"/resource:" + rulesFile + "," + this.NameSpace + "." + this.TypeName + "." + "rules";
·               parameters.CompilerOptions += resources;
·                
·               parameters.OutputAssembly = "CustomWorkflow" + Guid.NewGuid().ToString() + ".dll";
·                
·               // Compile the workflow
·               WorkflowCompilerResults results = compiler.Compile(parameters, strArr);
 

 
结论
WWF提供了一组API,可以让你自定义自己的脱离vs2005环境的WWF设计器。这个设计器可以提供更高性能的功能,也可给客户定制设计器,还可以提供rules support的无缝连接

 

Custom Windows workflow Desiger 自定义Windows工作流设计器相关推荐

  1. Windows Workflow Foundation(1)- Windows Workflow Foundation 概述

    Windows Workflow Foundation(第一章)- Windows Workflow Foundation 概述 工作流概述 活动(Activity)是工作流的基本单元,用于描述实际进 ...

  2. baq在聊天中啥意思,Epicor 10在BPM工作流设计器中链接BAQ(避免自定义代码)

    目前,我的任务是检查由Epicor创建的BPM,该BPM未按预期运行.目前BPM基于下面的代码,其目的是参考系统中的订单,以及如果价格发生变化,订单/部件将反映新价格的时间.看起来代码导致不正确的价格 ...

  3. bpmn-js + vue实现工作流设计器

    bpmn-js + vue实现工作流设计器 1.bpmn-js初体验 安装vue 使用vue-cli创建项目 安装bpmn-js 简单的查看工作流图形的例子 使用中间遇到的问题 2.新需求:可以拖拽自 ...

  4. [WF4.0]工作流设计器Rehosting(一)

    因为WF4.0使用WPF做可视化设计,能够利用WPF的数据绑定和其他一些内部实现,极大的简化了工作流设计器的开发工作:不用像3.5和3.0中那样,要开发一些服务类来支持工作流的设计操作. 首先看看Wo ...

  5. 一招搞定可视化工作流设计器开发 巧用draw2d绝战可视化工作流设计器 友好的开源协议MIT

    技术岛公众号 工作流通常会使用xml进行管理与配置,之间流转关系使用不同的xml节点进行配置,看着xml文件,很难直接Get到流程之间的流转关系.如果使用可视化的呈现来展现工作流,则很好的解决这个问题 ...

  6. 基于springboot+element ui+vue的java快速开发平台,集成html5工作流设计器,flowable, element ui 表单设计器

    前后端分离.maven多模块开发,方便多人协同开发 后端选型:springboot2 + mybatis + shiro + jwt token + flowable 前端选型:vue + eleme ...

  7. 基于地图的工作流设计器,及基于地图的业务流程办理界面(二)

    基于地图的工作流设计器,及基于地图的业务流程办理界面(二) ---------------------------------------------------------------------- ...

  8. 【转】Silverlight全开源工作流设计器

    声明 此工作流是作者自行构思和设计的被动式数据触发模式的工作流.没有遵循各种现有的工作流设计标准(如WFMC或WSFL),也没有与其他工作流通用性的接口规范.这里体现更多的是作者对工作流的使用思想,及 ...

  9. js 图形化工作流设计器

    最近比较闲,打算开发一个用js 写的 图形化工作流设计器,附上草图一张,要看运行效果请下载附件,这个版本还在开发中,以后会持续更新,直到满意为止.上面的列子虽然变形,我还是贴出来了,给大家一个直观的感 ...

最新文章

  1. Python 技术篇 - python3使用speech库常见问题原因及解决方法
  2. <马哲>科学技术在社会发展中的作用2017-12-27
  3. python正则表达式指南_Python正则表达式指南(转)
  4. 机器学习理论《统计学习方法》学习笔记:第三章 k近邻法
  5. Hessian序列化复杂对象
  6. 转换流/序列化/反序列化
  7. java导入包srcy有红叉_eclipse导入项目后出现红色叉号的解决方案
  8. paip.wscript.shell.run路径空格与VBs转义符 作者Attilax , EMAIL:1466519819@qq.com ,112237553@qq.com 来源:attilax
  9. [从零开始学FPGA编程-4]:快速入门篇 - 操作步骤1 - 常见可编程器件PROM、PLA、PAL、GAL、CPLD、FPGA
  10. Cropper详细笔记
  11. php7.4 ffi,PHP7.4中FFI的介绍(代码示例)
  12. 计算机二级ms在线模拟,2018年全国计算机二级在线自测模拟考场/网页版:MS Office高级应用(含真题及答案)...
  13. 动物识别系统代码python_人工智能-动物识别专家系统算法Python + Pyqt 实现
  14. JavaScript-ES6-基础语法
  15. shell脚本之AWK-AWK的变量和AWK运算符
  16. 回答阿里社招面试如何准备,顺便谈谈对于Java程序猿学习当中各个阶段的建议 - 左潇龙 - 博客园...
  17. 聊聊并发编程的12种业务场景
  18. 进程文件: dllhost 或者 dllhost.exe
  19. hifi android 手机吗,手机真能玩HiFi吗?手机玩HiFi必备的APP
  20. 在Hbuilder上使用GitHub

热门文章

  1. 外文翻译原文附在后面_外文翻译及外文原文(参考格式).doc
  2. [Codeforces 940E]Cashback(dp+set)
  3. CodeForces - 940E Cashback (DP+思维模型)
  4. ASEMI代理ON/安森美FGH40N60SMD原厂渠道车规级IGBT
  5. 用Python爬取微博热搜数据
  6. 高通平台之TP代码分析
  7. 流量就是这么省出来的
  8. jQuery设置内容以及属性
  9. php7不再把十六进制当数字,php7 参数、整形及字符串处理机制修改实例分析
  10. 网络填坑之路(6)ethtool - 命令管理以太网卡