快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

澳门新葡亰黑平台:WF 状态机 事件传参详细步骤



在WF状态机的State活动中,都是从事故活动开始,经由过程callExternalMethod活动调用措施来履行必要履行的营业.

在事情流创建时刻,我们可以经由过程参数的要领将事情流必要的共稀有据通报给事情流,这样事情流可以任何时刻造访这些数据(经由过程事情流属性实现了数据的get和set)。

事情流的CreateWorkflow措施:

public WorkflowInstance CreateWorkflow (Type workflowType,Dictionary namedArgumentValues)

参数namedArgumentValues便是我们必要的参数,可以这样组装namedArgumentValues参数:

Dictionary namedArgumentValues= new Dictionary();=

namedArgumentValues.Add("UserId", userId);

namedArgumentValues.Add("Xml", xml);

namedArgumentValues.Add("OrderId", orderId);

经由过程传参的要领只能在事情流创建的时刻将数据写入,在事情流从新被load后,没有法子给事情流实例(WorkflowInstance)添加参数或者写入数据。然则在实际营业中每个营业操作都可能必要传入一些数据,比如订单审批人,审批金额等,这样就呈现了我在开拓中碰到的问题,若何给事情流实例通报值?

大年夜概的办理思路在关于wf中传参的问题:若何在workflow实例钝化后从新load时传参! 做了阐明。

第一步:创建自定义事故类,比如OrderDataEventArgs,创建自定义事故类的时刻必要留意两点:首先要承袭ExternalDataEventArgs,别的便是要添加序列化声明

[Serializable]

publicclassOrderDataEventArgs:ExternalDataEventArgs

{

privatestringcorpIdValue;

privatestringuserIdValue;

privateintstampDateValue;

privatestringorderIdValue;

privatestringxmlValue;

publicOrderDataEventArgs(GuidinstanceId,strin澳门新葡亰黑平台gcorpId,stringuserId,intstampDate)

:base(instanceId)

{

orderIdValue=instanceId.ToString();

corpIdValue=corpId;

userIdValue=userId;

stampDateValue=stampDate;

//xmlValue=xml;

WaitForIdle=true;

}

publicOrderDataEventArgs(GuidinstanceId,stringcorpId,stringuserId,stringxml)

:base(instanceId)

{

orderIdValue=instanceId.ToString();

corpIdValue=corpId;

userIdValue=userId;

xmlValue=xml;

WaitForIdle=true;

}

publicstringOrderId

{

get{returnorderIdValue;}

set{orderIdValue=value;}

}

publicstringCorpId

{

get{returncorpIdValue;}

set{corpIdValue=value;}

}

publicstringUserId

{

get{returnuserIdValue;}

set{userIdValue=value;}

}

publicintStampDate

{

get{returnstampDateValue;}

set{stampDateValue=value;}

}

publicstringXml

{

get{returnxmlValue;}

set{xmlValue=value;}

}

}

第二步:在状态机中添加OrderDataEventArgs类型的属性:

publicstaticDependencyPropertyOrderEventArgsProperty=DependencyProperty.Register("OrderEventArgs",typeof(OrderDataEventArgs),typeof(Workflow1))澳门新葡亰黑平台;

[DescriptionAttribute("OrderEventArgs")]

[CategoryAttribute("OrderEventArgsCategory")]

[BrowsableAttribute(true)]

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

publicOrderDataEventArgsOrderEventArgs

{

get

{

return((OrderDataEventArgs)(base.GetValue(Workflow1.OrderEventArgsProperty)));

}

set

{

base.SetValue(Workflow1.OrderEventArgsProperty,value);

}

}

然后将HandleExternalEventActivity活动事故e参数绑定到上面定义的OrderDataEventArgs属性,这样就能经由过程事故将必要的数据通报给事情流

设置历程图片:

e参数绑定到OrderDataEventArgs属性的代码如下,这是经由过程属性设置天生的代码:

//

//handleExternalEventActivity1

//

this.handleExternalEventActivity1.EventName="Create";

this.handleExternalEventActivity1.InterfaceType=typeof(WorkflowInterface.IOrder);

this.handleExternalEventActivity1.Name="handleExternalEventActivity1";

activitybind1.Name="Workflow1";

activitybind1.Path="OrderEventArgs澳门新葡亰黑平台";

workflowparameterbinding1.ParameterName="e";

workflowparameterbinding1.SetBinding(System.Workflow.ComponentModel.WorkflowParameterBinding.ValueProperty,((System.Workflow.ComponentModel.ActivityBind)(activitybind1)));

this.handleExternalEventActivity1.ParameterBindings.Add(workflowparameterbinding1);

this.handleExterna澳门新葡亰黑平台lEventActivity1.Invoked+=newSystem.EventHandler(this.handleExternalEventActivity1_Invoked);

OrderEventArgsProperty 属性数据通报的序言,客户端组装OrderDataEventArgs,经由过程事故发澳门新葡亰黑平台送给事情流,事情流履行CallExternalMethodActivity的措施。

下面是关于事情流接口和实现的代码:

[ExternalDataExchange]

publicinterfaceIOrder

{

///

///创建订单

///

eventEventHandlerCreate;

///

///确认订单

///

eventEventHandlerConfirm;

///

///完成

///

eventEventHandlerComplete;

voidSaveOrder(stringorderId,stringuserId);

}

[Serializable]

publicclassOrder:IOrder

{

publicvoidRaiseCreateEvent(OrderDataEventArgsargs)

{

if(Create!=null)

{

Create(null,args);

}

}

publicvoidRaisConfirmEvent(OrderDataEventArgsargs)

{

if(Confirm!=null)

{

Confirm(null,args);

}

}

publicvoidRaisCompleteEvent(OrderDataEventArgsargs)

{

if(Complete!=null)

{

Complete(null,args);

}

}

#regionIOrderMembers

publiceventEventHandlerCreate;

publiceventEventHandlerConfirm;

publiceventEventHandlerComplete;

publicvoidSaveOrder(stringorderId,stringuserId)

{

//获得经由过程OrderDataEventArgs通报的数据

Console.WriteLine("OrderIdvalue{0},UserIdvalue{1}",orderId,userId);

}

#endregion

}

您可能还会对下面的文章感兴趣: