惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Last Watchdog
The Last Watchdog
S
Schneier on Security
C
Cisco Blogs
P
Privacy International News Feed
T
Tenable Blog
Spread Privacy
Spread Privacy
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
Project Zero
Project Zero
GbyAI
GbyAI
N
Netflix TechBlog - Medium
T
Tor Project blog
雷峰网
雷峰网
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threat Research - Cisco Blogs
Cyberwarzone
Cyberwarzone
L
LangChain Blog
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
C
Check Point Blog
G
Google Developers Blog
T
Tailwind CSS Blog
L
LINUX DO - 热门话题
宝玉的分享
宝玉的分享
IT之家
IT之家
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Announcements
Recent Announcements
T
The Exploit Database - CXSecurity.com
Hacker News: Ask HN
Hacker News: Ask HN
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Google Online Security Blog
Google Online Security Blog
Help Net Security
Help Net Security
H
Hacker News: Front Page
小众软件
小众软件
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
P
Privacy & Cybersecurity Law Blog
T
Threatpost

博客园 - gotolovo

导出csv 导出excel 正则学习电话匹配 logmanager des 加密 解密 - gotolovo c# 发送邮件 工作流学习过程-事务 工作流学习过程-状态机 蛋疼的viewstate 工作流学习过程-持久化服务 工作流学习过程-使用关联 工作流学习过程-本地服务之事件处理 工作流学习过程-本地服务之调用方法 工作流学习过程-验证活动 工作流学习过程-开篇 基本的几个排序算法 关于sql中时间的格式转换 数据行变列 请编程遍历页面上所有TextBox控件并给它赋值为空
工作流学习过程-自定义活动
gotolovo · 2010-10-22 · via 博客园 - gotolovo

工作流学习过程-自定义活动

例2:订单处理

顺序工作流如图:

 

后台代码:

代码

public sealed partial class OrderWorkflow : SequentialWorkflowActivity
{
public OrderWorkflow()
{
InitializeComponent();
}
public int AccountId { get; set; }
private double accountAmount;
private bool accountExist;public int GoodsID { get; set; }
private double goodsAmount;
private bool goodsExist;private void AccountNull_ExecuteCode(object sender, EventArgs e)
{
Console.Write(
" this is accountId : {0} is null ", AccountId.ToString());
}
private void CheckAccount_ExecuteCode(object sender, EventArgs e)
{
switch (AccountId)
{
case 1001:
accountAmount
= 100;
accountExist
= true;
break;
case 1002:
accountAmount
= 500;
accountExist
= false;
break;
case 1003:
accountAmount
= 1000;
accountExist
= true;
break;
default:
accountAmount
= 0;
accountExist
= false;
break;
}
}
private void CheckGoods_ExecuteCode(object sender, EventArgs e)
{
switch (GoodsID)
{
case 2001:
goodsAmount
= 20;
goodsExist
= true;
break;
case 2002:
goodsAmount
= 30;
goodsExist
= false;
break;
case 2003:
goodsAmount
= 40;
goodsExist
= true;
break;
default:
goodsAmount
= 0;
goodsExist
= false;
break;
}
}
private void GoodsNull_ExecuteCode(object sender, EventArgs e)
{
Console.Write(
" this is goodsId : {0} is null ", GoodsID.ToString());
}
private void AmountNotEnough_ExecuteCode(object sender, EventArgs e)
{
Console.Write(
" Sorry: your account's amount is {0}, this is goodsId's amount is {1} ", accountAmount.ToString(), goodsAmount.ToString());
}
private void CalOrder_ExecuteCode(object sender, EventArgs e)
{
this.accountAmount -= goodsAmount;
Console.Write(
" your order is success!! your account' amount is {0} ", this.accountAmount.ToString());
}

我们清楚这里涉及到账号和产品的验证过程,如何整个系统中不可能仅仅在订单处理过程中附带该过程
因此我们应尽可能的细化这些步骤。这就是自定义活动
第一验证账号信息:AccountActivity 活动名称应以Activity结尾
代码如下:

代码

public sealed partial class AccountActivity: Activity
{
public AccountActivity()
{
InitializeComponent();
}
public static DependencyProperty AccountIdProperty = DependencyProperty.Register("AccountId", typeof(int), typeof(AccountActivity));

[DescriptionAttribute(

"AccountId")]
[CategoryAttribute(
"AccountId Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int AccountId
{
get
{
return ((int)(base.GetValue(AccountActivity.AccountIdProperty)));
}
set
{
base.SetValue(AccountActivity.AccountIdProperty, value);
}
}
public static DependencyProperty AccountAmountProperty = DependencyProperty.Register("AccountAmount", typeof(double), typeof(AccountActivity));

[DescriptionAttribute(

"AccountAmount")]
[CategoryAttribute(
"AccountAmount Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public double AccountAmount
{
get
{
return ((double)(base.GetValue(AccountActivity.AccountAmountProperty)));
}
set
{
base.SetValue(AccountActivity.AccountAmountProperty, value);
}
}
public static DependencyProperty AccountExistProperty = DependencyProperty.Register("AccountExist", typeof(bool), typeof(AccountActivity));

[DescriptionAttribute(

"AccountExist")]
[CategoryAttribute(
"AccountExist Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public bool AccountExist
{
get
{
return ((bool)(base.GetValue(AccountActivity.AccountExistProperty)));
}
set
{
base.SetValue(AccountActivity.AccountExistProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
switch (AccountId)
{
case 1001:
AccountAmount
= 100;
AccountExist
= true;
break;
case 1002:
AccountAmount
= 505;
AccountExist
= false;
break;
default:
AccountAmount
= 0;
AccountExist
= false;
break;
}
Console.Write(
" this accmountId is {0} exist is {1} ", AccountId.ToString(), AccountExist.ToString());
return base.Execute(executionContext);
}
}

 第二产品信息验证 

代码

public partial class GoodsActivity: Activity
{
public GoodsActivity()
{
InitializeComponent();
}
public static DependencyProperty GoodsIdProperty = DependencyProperty.Register("GoodsId", typeof(int), typeof(GoodsActivity));

[DescriptionAttribute(

"GoodsId")]
[CategoryAttribute(
"GoodsId Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int GoodsId
{
get
{
return ((int)(base.GetValue(GoodsActivity.GoodsIdProperty)));
}
set
{
base.SetValue(GoodsActivity.GoodsIdProperty, value);
}
}
public static DependencyProperty GoodsAmountProperty = DependencyProperty.Register("GoodsAmount", typeof(double), typeof(GoodsActivity));

[DescriptionAttribute(

"GoodsAmount")]
[CategoryAttribute(
"GoodsAmount Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public double GoodsAmount
{
get
{
return ((double)(base.GetValue(GoodsActivity.GoodsAmountProperty)));
}
set
{
base.SetValue(GoodsActivity.GoodsAmountProperty, value);
}
}
public static DependencyProperty GoodsExistProperty = DependencyProperty.Register("GoodsExist", typeof(bool), typeof(GoodsActivity));

[DescriptionAttribute(

"GoodsExist")]
[CategoryAttribute(
"GoodsExist Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public bool GoodsExist
{
get
{
return ((bool)(base.GetValue(GoodsActivity.GoodsExistProperty)));
}
set
{
base.SetValue(GoodsActivity.GoodsExistProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
switch (GoodsId)
{
case 2001:
GoodsAmount
= 50;
GoodsExist
= true;
break;
case 2002:
GoodsAmount
= 100;
GoodsExist
= false;
break;
default:
GoodsAmount
= 0;
GoodsExist
= false;
break;
}
Console.Write(
"this GoodsId is {0} exist is {1} ", GoodsId.ToString(), GoodsExist.ToString());
return base.Execute(executionContext);
}
}

第三订单处理 

代码

public sealed partial class OrderActivity : Activity
{
public OrderActivity()
{
InitializeComponent();
}
public static DependencyProperty AccountIdProperty = DependencyProperty.Register("AccountId", typeof(int), typeof(OrderActivity));

[DescriptionAttribute(

"AccountId")]
[CategoryAttribute(
"AccountId Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int AccountId
{
get
{
return ((int)(base.GetValue(OrderActivity.AccountIdProperty)));
}
set
{
base.SetValue(OrderActivity.AccountIdProperty, value);
}
}
public static DependencyProperty GoodsIdProperty = DependencyProperty.Register("GoodsId", typeof(int), typeof(OrderActivity));

[DescriptionAttribute(

"GoodsId")]
[CategoryAttribute(
"GoodsId Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int GoodsId
{
get
{
return ((int)(base.GetValue(OrderActivity.GoodsIdProperty)));
}
set
{
base.SetValue(OrderActivity.GoodsIdProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
Console.Write(
"this AccountId is {0} ", AccountId.ToString());
Console.Write(
"this GoodsId is {0} ", GoodsId.ToString());
return base.Execute(executionContext);
}
}

 自定义活动到现在就都已经完成了。
来看看新工作流是什么样吧
新建顺序工作流
CustomerOrderActivity

两个工作流的任务是相同的。后者别前者更容易进行理解与维护,而产生的附加活动也能为其他工作流重用
需要指出的是 工作流的的各个活动的 属性可以互相绑定,而达到传递的目的
点击活动的属性。选择AccountID属性后点击后面的...弹出页面如图:

后台代码:

代码

public sealed partial class CustomerOrderActivity : SequentialWorkflowActivity
{
public CustomerOrderActivity()
{
InitializeComponent();
}
public static DependencyProperty AccountIdProperty = DependencyProperty.Register("AccountId", typeof(int), typeof(CustomerOrderActivity));

[DescriptionAttribute(

"AccountId")]
[CategoryAttribute(
"AccountId Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int AccountId
{
get
{
return ((int)(base.GetValue(CustomerOrderActivity.AccountIdProperty)));
}
set
{
base.SetValue(CustomerOrderActivity.AccountIdProperty, value);
}
}
public static DependencyProperty GoodsIdProperty = DependencyProperty.Register("GoodsId", typeof(int), typeof(CustomerOrderActivity));

[DescriptionAttribute(

"GoodsId")]
[CategoryAttribute(
"GoodsId Category")]
[BrowsableAttribute(
true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int GoodsId
{
get
{
return ((int)(base.GetValue(CustomerOrderActivity.GoodsIdProperty)));
}
set
{
base.SetValue(CustomerOrderActivity.GoodsIdProperty, value);
}
}

 可以看出 工作流里 的代码很少了。更清爽了。因为主要的工作都已经在自定义活动中完成了。。。 

posted on 2010-10-22 16:43  gotolovo  阅读(275)  评论()    收藏  举报