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