微軟推出的工作流程引擎: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,微軟的這一個算是功能強大的了