微软推出的工作流引擎:Windows Workflow Foudation,简单介绍一下
这是原文:
https://msdn.microsoft.com/windowsvista/building/workflow/default.aspx?pull=/library/en-us/dnlong/html/WWFGetStart.asp
这是下载地址
http://www.microsoft.com/downloads/details.aspx?familyid=7096d039-2638-4f63-8654-d2e5d98fa417&displaylang=en
这个开发环境需要安装在vs2005里面。
可以选择你的workflow引擎的Host
他处理的主要有两类工作流:顺序工作流(Sequential Workflow )和状态机工作流(State Machine Workflow ):
A sequential workflow is ideal for operations expressed by a pipeline of steps that execute one after the next until the last activity completes. Sequential workflows, however, are not purely sequential in their execution. They can still receive external events or start parallel tasks, in which case the exact sequence of execution can vary somewhat.
A state machine workflow is made up of a set of states, transitions, and actions. One state is denoted as a start state, and then, based on an event, a transition can be made to another state. The state machine workflow can have a final state that determines the end of the workflow.
有可视化的设计界面,就像设计一个aspx页面一样,把各个活动(activities )当成控件向里拖放。每个工作项就像一个控件,那工作流则一个窗体,可以直接写代码,比如MessageBox.Show.
To continue with the Windows Forms analogy, a workflow is like a form, whereas activities are like controls.
这个窗体也可以保存成xml格式的,但是.cs文件还是那样子。这是他实际做的
this.Activities.Add(this.code1);
this.DynamicUpdateCondition = null;
this.ID = "Workflow1";
FirstName.Direction = System.Workflow.ComponentModel.ParameterDirection.In;
FirstName.Name = "FirstName";
FirstName.Type = typeof(string);
可以设置端点调试工作流。
传递数据:有两种方式Param 和 event 。可以自己设置需要的Param (就是一些共有的属性而以)
数据的提供和处理还是Host要做的,比如,要出低一些参数进来,还一个把Host上的时间联系到workflow上。下边是一个窗体(Host)的一个按钮的事件处理代码
Dictionary parameters = new Dictionary();
parameters.Add("FirstName", txtFirstName.Text);
parameters.Add("LastName", txtLastName.Text);
// Start the workflow
Guid instanceID = Guid.NewGuid();
_wr.StartWorkflow(workflowType, instanceID, parameters);
流程处理上,功能很强大,可以设计诸如 IfElse,while,WaitForData,Suspend,Listen,Delay,EventDriven 等30多种。
开发一个Activity:
public partial class SendMailActivity : System.Workflow.ComponentModel.Activity
{
public SendMailActivity()
{
InitializeComponent();
}
protected override Status Execute(ActivityExecutionContext context)
{
:
}
}
状态机工作流比较麻烦,这是初始化一个状态机工作流:
private void StartWorkflowRuntime()
{
// Create a new Workflow Runtime for this application
_runtime = new WorkflowRuntime();
// Register event handlers for the WorkflowRuntime object
_runtime.WorkflowTerminated += new
EventHandler(WorkflowRuntime_WorkflowTerminated);
_runtime.WorkflowCompleted += new
EventHandler(WorkflowRuntime_WorkflowCompleted);
// Create a new instance of the StateMachineTrackingService class
_stateMachineTrackingService = new StateMachineTrackingService(_runtime);
// Start the workflow runtime
_runtime.StartRuntime();
// Add a new instance of the OrderService to the runtime
_orderService = new OrderService();
_runtime.AddService(_orderService);
}
在.net2.0里面EventHandler其实做了功能上的扩充
这是其中一步的处理
private Guid StartOrderWorkflow(string orderID) { // Create a new GUID for the WorkflowInstanceId Guid instanceID = Guid.NewGuid(); // Load the OrderWorkflows assembly Assembly asm = Assembly.Load("OrderWorkflows"); // Get a type reference to the OrderWorkflows.Workflow1 class Type workflowType = asm.GetType("OrderWorkflows.Workflow1"); // Start a new instance of the state machine with state tracking support StateMachineInstance stateMachine = _stateMachineTrackingService.RegisterInstance(workflowType, instanceID); stateMachine.StateChanged += new EventHandler(StateMachine_StateChanged); stateMachine.StartWorkflow(); _stateMachineInstances.Add(instanceID.ToString(), stateMachine); // Return the workflow GUID return instanceID; }
可以和微软其他的产品集成,比如biztalk,office之类的
相对其他的工作流引擎,比如osworkflow,微软的这一个算是功能强大的了