如果在Workflow中定义了一个属性,如何才能在工作流创建后对这个属性进行修改呢?
今天折腾了一天,也不见有什么效果,只搞懂了一半,先写出来,没有领悟到的等以后想通了再写。
在创建工作流的时候,可以用CreateWorkflow(typeof(wf),Dictionary<string,object>)这样的方式将参数值传入工作流。但是如果工作流已经创建,宿主程序又如何把值传入工作流呢?
需要用到
ExternalDataEventArgs这个东东,需要自己继承一个这样的类
[Serializable]
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
public class BillExternalDataEventArgs : ExternalDataEventArgs
{
private Decimal _mycash;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public Decimal Cash
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _mycash; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _mycash = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public BillExternalDataEventArgs(Guid instanceId,Decimal decCash) : base(instanceId)
{
_mycash = decCash;
}
}
然后在把对应的接口进行相应的调整
[ExternalDataExchange]
public interface IBillWorkFlow
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
Decimal GetCash(Decimal decCash);
event EventHandler<BillExternalDataEventArgs> BillSubmit;
event EventHandler<BillExternalDataEventArgs> BillOk;
}
[Serializable]
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
public class MyBillWorkFlow : IBillWorkFlow
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public MyBillWorkFlow()
{
System.Diagnostics.Debug.WriteLine("MyBillWorkFlow Init");
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Dictionary<string, EventHandler<BillExternalDataEventArgs>> _EventList = new Dictionary<string, EventHandler<BillExternalDataEventArgs>>();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public void RaisEvent(string strName,Guid guidInstanceId,Decimal decCash)
{
if (_EventList[strName] != null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
EventHandler<BillExternalDataEventArgs> evehandler = _EventList[strName];
BillExternalDataEventArgs ede = new BillExternalDataEventArgs(guidInstanceId,decCash);
evehandler(this, ede);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch
{
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public Decimal GetCash(Decimal decCash)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return decCash;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public event EventHandler<BillExternalDataEventArgs> BillSubmit
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
add
{
System.Diagnostics.Debug.WriteLine("add BillSubmit event");
_EventList.Add("BillSubmit", value);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
remove
{ _EventList.Remove("BillSubmit"); }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public event EventHandler<BillExternalDataEventArgs> BillOk
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
add
{ _EventList.Add("BillOk", value); }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
remove
{ _EventList.Remove("BillOk"); }
}
}
然后在工作流中定义
public Billdayone.BillExternalDataEventArgs _cash = default(Billdayone.BillExternalDataEventArgs);
这个_cash就是宿主与工作流之间传递的重要属性。
只需要调用
RaisEvent(string strName,Guid guidInstanceId,Decimal decCash)//Decimal decCash就是宿主向工作流传递的参数,将传递给_cash.Cash
这样就完成了宿主向工作流传递参数。
但是我还没有弄明白怎么能够得到工作流中的属性值。还在学习中。。。还不知道怎么办?。。。