版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
完成相关数据服务(correlQteddataservice)
1.在TruckService项目中,你会找到一个名称为
WorkflowTruckTrackingDataService.cs的源文件。你需要打开它准备进行编辑。
2.第一件事是添加该服务执行它的任务时所需要的私有字段。在
WorkflowTruckTrackingDataService类的左大括号的后面添加下面这些代码:
privatestaticWorkflowRuntime_workflowRuntime=null;
privatestaticExternalDataExchangeService_dataExchangeservice=null;
privatestaticTruckServiceDataConnector_dataConnector=null;
privatestaticobject_syncRoot=newobject();
3.在这些私有字段的下面是该服务将触发的事件。这些事件被触发的结果就是工作流实例
将调用一个CollExternolMethod渊](你可在TruckServiceDotoConnector类中看到它):
publiceventEventHandler<TruckActivityEventArgs>TruckLeaving;
publiceventEventHandler<TruckActivityEventArgs>Routellpdated;
publiceventEventHandler<TruckActivityEventArgs>TruckArrived;
4.接下来添加两个字段以及对应的属性,你需要它们去对相关的服务实例进行识别:
privateGuidJnstancelD=Guid.Empty;
publicGuidInstancelD
{
get{returnJnstancelD;}
set{JnstancelD=value;}
}
privateInt32_truckID=-1;
publicInt32TruckID
{
get{return_truckID;}
set<_truckID=value;}
}
5.现在我们需要添加两个静态方法:一个是在工作流运行时中注册该服务并对它进行配置,
另一个是去对已经注册的服务实例进行检索:
CreateDataService静态方法和GetRegisteredWorkflowDotoService静态方法
publicstaticWorkflowTruckTrackingDataService
CreateDataService(GuidinstancelD,
WorkflowRuntimeworkflowRuntime,
Int32truckID)
{
lock(_syncRoot)
//Ifwe'rejuststarting,saveacopyoftheworkflow.
//runtimereference
if(_workflowRuntime==null)
_workflowRuntime=workflowRuntime;
}
〃Ifwe'rejuststarting,pluginExternalDataExchangeservice.
if(_dataExchangeservice==null)
<
_dataExchangeService=newExternalDataExchangeService();
_workflowRuntime.AddService(_dataExchangeService);
}
//Checktoseeifwehavealreadyaddedthisdata
//exchangeservice.
TruckServiceDataConnectordataConnector=
(TruckServiceDataConnector)workflowRuntime.GetService(
typeof(TruckServiceDataConnector));
if(dataConnector==null)
_dataConnector=newTruckServiceDataConnector();
_dataExchangeService.AddService(_dataConnector);
}
else
{
_dataConnector=dataConnector;
//Pulltheserviceinstanceweregisteredwiththeconnection
〃object.
returnWorkflowTruckTrackingDataService.
GetRegisteredWorkflowDataService(instanceIDztruckID);
}
}
publicstaticWorkflowTruckTrackingDataService
GetRegisteredWorkflowDataService(GuidinstancelD,
Int32truckID)
{
lock(_syncRoot)
WorkflowTruckTrackingDataServiceworkflowDataService=
TruckServiceDataConnector.GetRegisteredWorkflowDataService(
instancelD,truckID);
if(workflowDataService==null)
workflowDataService=
newWorkflowTruckTrackingDataService(instanceIDztruckID);
TruckServiceDataConnector.RegisterDataService(
workflowDataService);
returnworkflowDataService;
)
}
6.现在添加构造器和析构器:
类的构造器和析构器代码
privateWorkflowTruckTrackingDataService(GuidinstancelD,Int32truckID)
{
this.JnstancelD=instancelD;
this._truckID=truckID;
)
^WorkflowTruckTrackingDataService()
//Cleanup
_workflowRuntime=null;
_dataExchangeService=null;
_dataConnector=null;
}
备注:你可以回忆一下第8章,构造器的作用是防止在服务和连接器类之间出现循环
链接引用。而对于析构器的作用来说,只是实现Disposable并不能完成相应的任务,因为
当从工作流运行时中移除该服务的时候并不调用Dispose方法。
7.在类的构造器的下面,添加下面的读取关联数据的方法:
publicstringRead()
return_dataConnector.RetrieveTruckInfo(InstanceID,TruckID);
}
8.最后添加事件实现的代码:
事件实现的代码
publicvoidRaiseTruckLeavingEvent(Int32truckID,
Int32startingX,
Int32startingY)
if(_workflowRuntime==null)
_workflowRuntime=newWorkflowRuntime();
//Loadspersistedworkflowinstances.
_workflowRuntime.GetWorkflow(JnstanceID);
if(TruckLeaving!=null)
{
TruckLeaving(thisznewTruckActivityEventArgs(_instanceID,
truckID,
startingX,
startingY));
}//if
publicvoidRaiseRouteUpdatedEvent(Int32truckID,
Int32Xz
Int32Y)
if(_workflowRuntime==null)
_workflowRuntime=newWorkflowRuntime();
//Loadspersistedworkflowinstances.
_workflowRuntime.GetWorkflow(_instanceID);
if(RouteUpdated!=null)
Routellpdated(thisznewTruckActivityEventArgs(_instanceID,
truckID,
X,Y));
}//if
}
publicvoidRaiseTruckArrivedEvent(Int32truckID)
if(_workflowRuntime==null)
_workflowRuntime=newWorkflowRuntime();
//Loadspersistedworkflowinstances.
_workflowRuntime.GetWorkflow(_instanceID);
if(TruckArrived!=null)
{
TruckArrived(this,newTruckActivityEventArgs(_instanceID,
truckID));
}//if
)
9.保存该文件并编译该Truckservice项目。如果存在编译错误,请纠正任何出现的编
译错误。
服务类的代码就全部完成了,列表17-3展示了该类的完整代码。TruckSercie本地通
信服务可以准备使用了。我们还没有一个工作流来使用该服务。我们也需要使用可信赖的
wca.exe工具来为我们创建自定义的CQllExternolMethod和HondleExtemolEvent活动。
列表17-3WorkflowTruckTrackingDataService.cs的完整代码
WorkflowTruckTrackingDataService类的完整代码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Workflow.Activities;
usingSystem.Workflow.Runtime;
namespaceTruckservice
{
publicclassWorkflowTruckTrackingDataService
privatestaticWorkflowRuntime_workflowRuntime=null;
privatestaticExternalDataExchangeService_dataExchangeservice=null;
privatestaticTruckServiceDataConnector_dataConnector=null;
privatestaticobject_syncRoot=newobject();
publiceventEventHandler<TruckActivityEventArgs>TruckLeaving;
publiceventEventHandler<TruckActivityEventArgs>Routellpdated;
publiceventEventHandler<TruckActivityEventArgs>TruckArrived;
privateGuidJnstancelD=Guid.Empty;
publicGuidInstancelD
{
get{returnJnstancelD;}
set{JnstancelD=value;}
?
privateInt32_truckID=-1;
publicInt32TruckID
get{return_truckID;}
set{_truckID=value;}
}
publicstaticWorkflowTruckTrackingDataServiceCreateDataService(Guid
instancelD,WorkflowRuntimeworkflowRuntime,Int32truckID)
lock(_syncRoot)
〃Ifwe'rejuststarting,saveacopyoftheworkflowruntimereference
if(_workflowRuntime==null)
{
_workflowRuntime=workflowRuntime;
}//if
//Ifwe'rejuststarting,pluginExternalDataExchangeservice
if(_dataExchangeService==null)
_dataExchangeService=newExternalDataExchangeService();
_workflowRuntime.AddService(_dataExchangeService);
}//if
//Checktoseeifwehavealreadyaddedthisdataexchangeservice
TruckServiceDataConnectordataConnector=
(TruckServiceDataConnector)workflowRuntime.GetService(typeof(TruckServiceDataCo
nnector));
if(dataConnector==null)
{
_dataConnector=newTruckServiceDataConnector。;
_dataExchangeService.AddService(_dataConnector);
}//if
else
{
_dataConnector=dataConnector;
}//else
//Pulltheserviceinstanceweregisteredwiththeconnectionobject
return
WorkflowTruckTrackingDataService.GetRegisteredWorkflowDataService(instanceIDz
truckID);
}//lock
}
publicstaticWorkflowTruckTrackingDataService
GetRegisteredWorkflowDataService(GuidinstancelD,Int32truckID)
{
lock(_syncRoot)
WorkflowTruckTrackingDataServiceworkflowDataService=
TruckServiceDataConnector.GetRegisteredWorkflowDataService(instanceIDztruckID);
if(workflowDataService==null)
{
workflowDataService=new
WorkflowTruckTrackingDataService(instanceIDztruckID);
TruckServiceDataConnector.RegisterDataService(workflowDataService);
}//if
returnworkflowDataService;
}//lock
}
privateWorkflowTruckTrackingDataService(GuidinstancelD,Int32truckID)
this.JnstancelD=instancelD;
this._truckID=truckID;
}
~WorkflowTruckTrackingDataService()
<
//Cleanup
_workflowRuntime=null;
_dataExchangeService=null;
_dataConnector=null;
}
publicstringRead()
return_dataConnector.RetrieveTruckInfo(InstanceID,TruckID);
}
publicvoidRaiseTruckLeavingEvent(Int32truckID,Int32startingX,Int32
startingY)
if(_workflowRuntime==null)
_workflowRuntime=newWorkflowRuntime();
_workflowRuntime.GetWorkflow(_instanceID);//loads
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 液化气体生产工岗前离岗考核试卷含答案
- 井下作业机司机岗前记录考核试卷含答案
- 水工混凝土维修工安全宣贯模拟考核试卷含答案
- 支教数学5年级题目及答案
- 国际铁路运费题目计算题及答案
- 《工业节水管理技术》课件-3.循环用水
- 2021年小升初冲刺城南旧日事阅读测试题及标准参考答案
- 2020安宁疗护专科护理操作配套理论试题及答案
- 阿斯利康2026全员合规培训配套测试题及参考答案
- 2024年仪表工技师职业资格考试试题集 带完整答案
- 2026年江苏单招职业适应性测试时政经典题集含答案
- 2026年浙江交通职业技术学院单招综合素质考试题库带答案
- 2025年下半年广西日报公开招聘33人笔试参考题库附答案
- 火灾风险隐患排查治理“自知、自查、自改”消防安全管理告知及承诺书
- 2026年中考语文一轮复习:病句的辨析与修改 课件
- 2025年广州市海珠区中小学教师招聘笔试参考试题及答案解析
- 盾构构造与操作维护课件 1 盾构构造与操作维护-盾构机整机构造介绍
- 《邮轮餐饮服务管理 》-邮轮餐饮服务管理第2章
- LNG加气站建设进度与质量控制方案
- 2025四川成都交易集团有限公司招聘10人笔试历年参考题库附带答案详解
- 车辆定点维修服务投标方案纯方案-
评论
0/150
提交评论