.Net WorkFlow 的簡單例子

來源:互聯網
上載者:User

標籤:

Program.cs 後台代碼:

class Program
{
static void Main(string[] args)
{
//Activity workflow1 = new Workflow1();
//WorkflowInvoker.Invoke(new Workflow1());
WorkflowInvoker.Invoke(MyCodeWorkFlow.CreateWorkFlow());
Console.ReadLine();
}
}

 

 

WorkFlow 的例子 代碼 :

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Statements;

namespace WorkflowConsoleApplication1
{
public class MyCodeWorkFlow
{
public static Activity CreateWorkFlow()
{
//定義兩個變數:時鐘響幾次數,現在的時間(小時)
Variable<int> count = new Variable<int>()
{
Name="count",
Default=0
};
Variable<int> timeNowHour = new Variable<int>()
{
Name="timeNowHour",
Default=DateTime.Now.Hour

};
//Sequence 是Activity的子類,裡面寫邏輯思維
return new Sequence()
{
DisplayName = "Main Sequence",
Variables = { count, timeNowHour },//表示 全域變數可以在這個域 裡使用
//聲明一種活動
Activities = {
new WriteLine(){
DisplayName="問候",
Text="Hello World !"
},
new If()
{
DisplayName="判斷",
Condition=ExpressionServices.Convert<bool>(u=>timeNowHour.Get(u)>12),
Then=new Assign<int>()//Assign 相當於 給某個變數賦值
{
To=timeNowHour,// 給 哪個 變數賦值
Value=new InArgument<int>(m=>timeNowHour.Get(m)-12) // 賦 什麼值
}
},
new Sequence()
{
DisplayName="時鐘報時",
Activities={
new While()
{
Condition=ExpressionServices.Convert<bool>(u=>count.Get(u)<timeNowHour.Get(u)),
Body=new Sequence()
{
Activities={
new Assign<int>(){To=count,Value=new InArgument<int>(m=>count.Get(m)+1)},
new WriteLine(){DisplayName="報時", Text=new InArgument<string>(u=>count.Get(u).ToString())},
//延時,每隔1秒 ,報時一次
new Delay(){Duration=TimeSpan.FromSeconds(1)}
}
}

}

}

},
new Sequence() //Sequence 可以理解成 內部類
{
DisplayName="目前時間",
Activities={
new WriteLine(){ Text=string.Format("目前時間為:"+DateTime.Now.ToString())}
}

},
new Sequence()
{
DisplayName ="根據時間的不同 來問好!",
Activities={
new If(){Condition=ExpressionServices.Convert<bool>(u=>DateTime.Now.Hour>=18),
Then=new WriteLine(){Text="晚上好!"},
Else=new WriteLine(){ Text="白天好!"}
}


}

}

}


};

}
}
}

 

.Net WorkFlow 的簡單例子

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.