微軟推出的工作流程引擎:Windows Workflow Foudation

來源:互聯網
上載者:User
微軟推出的工作流程引擎: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,微軟的這一個算是功能強大的了


































聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.