




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、完成相關(guān)數(shù)據(jù)服務(wù)(correlot6d data service).在TruckService工程中,你會(huì)找到一個(gè)名稱為WorkflowTruckTrackingDatoService.cs的源文件。你需要翻開(kāi)它準(zhǔn)備進(jìn)行編輯。.第一件事是添加該服務(wù)執(zhí)行它的任務(wù)時(shí)所需要的私有字段。在WorkflowTruckTrackingDataService類的左大括號(hào)的后面添加下面這些代碼:private static WorkflowRuntime _workflowRuntime = null;private static ExternalDataExchangeService _dataExchan
2、geService = null;private static TruckServiceDataConnector _dataConnector = null;private static object _syncRoot = new object();.在這些私有字段的下面是該服務(wù)將觸發(fā)的事件。這些事件被觸發(fā)的結(jié)果就是工作流實(shí)例將調(diào)用一個(gè)CHExternolMethod 7制(你可在TruckServiceDotaConnector類中看至匕):public event EventHandler TruckLeaving;public event EventHandler RouteUpda
3、ted;public event EventHandler TruckArrived;.接下來(lái)添加兩個(gè)字段以及對(duì)應(yīng)的屬性,你需要它們?nèi)?duì)相關(guān)的服務(wù)實(shí)例進(jìn)行識(shí)別:private Guid _instanceID = Guid.Empty;public Guid InstancelDget return JnstancelD; set _instanceID = value; lock (.syncRoot)/ If were just starting, save a copy of the workflow runtime reference if (_workflowRuntime = nu
4、ll)(workflowRuntime = workflowRuntime;/ if/ If were just starting, plug in ExternalDataExchange serviceif (_dataExchangeService = null) _dataExchangeService = new ExternalDataExchangeService();_workflowRuntime.AddService(_dataExchangeService);/ if/ Check to see if we have already added this data exc
5、hange serviceTruckServiceDataConnector dataConnector =(TruckServiceDataConnector) workflowRuntime.GetService(typeof(TruckServiceDataCo nnector);if (dataConnector = null) _dataConnector = new TruckServiceDataConnector();_dataExchangeService.AddService(_dataConnector);)/ if elsedataConnector = dataCon
6、nector; / else / Pull the service instance we registered with the connection object returnWorkflowTruckTrackingDataService.GetRegisteredWorkflowDataService(instanceID,truckID); / lockpublic static WorkflowTruckTrackingDataServiceGetRegisteredWorkflowDataService(Guid instancelD, Int32 truckID)lock (_
7、syncRoot)WorkflowTruckTrackingDataService workflowDataService =TruckServiceDataConnector.GetRegisteredWorkflowDataService(instanceID, truckID);if (workflowDataService = null) workflowDataService = newWorkflowTruckTrackingDataService(instanceID, truckID);TruckServiceDataConnector.RegisterDataService(
8、workflowDataService);/ ifreturn workflowDataService; / lockprivate WorkflowTruckTrackingDataService(Guid instancelD, Int32truckID)this. instancelD = instancelD;this. truckID = truckID;WorkflowTruckTrackingDataService()/ Clean upworkflowRuntime = null;_dataExchangeService = null;dataConnector = null;
9、)public string Read()return _dataConnector.RetrieveTruckInfo(InstanceID,TruckID);public void RaiseTruckLeavingEvent(Int32 truckID, Int32 starting/, Int32 startingY)if (_workflowRuntime = null)_workflowRuntime = new WorkflowRuntime();_workflowRuntime.GetWorkflow(_instanceID); / loads persisted workfl
10、ow instancesif (TruckLeaving != null)TruckLeaving(this, new TruckActivityEventArgs(_instanceID, truckID, starting/, startingY);/ ifpublic void RaiseRouteUpdatedEvent(Int32 truckID, Int32 X, Int32 Y)if (_workflowRuntime = null)_workflowRuntime = new WorkflowRuntime();_workflowRuntime.GetWorkflow(_ins
11、tanceID); / loads persisted workflow instancesif (Routellpdated != null)Routellpdated(this, new TruckActivityEventArgs(_instanceID, truckID, X,/ ifpublic void RaiseTruckArrivedEvent(Int32 truckID)if (_workflowRuntime = null)_workflowRuntime = new WorkflowRuntime();_workflowRuntime.GetWorkflow(_insta
12、nceID); / loads persisted workflowinstancesif (TruckArrived != null)TruckArrived(this, new TruckActivityEventArgs(_instanceIDz truckID);/ ifprivate Int32 _truckID = -1;public Int32 TruckIDget return _truckID; 5現(xiàn)在我們需要添加兩個(gè)靜態(tài)方法:一個(gè)是在工作流運(yùn)行時(shí)中注冊(cè)該服務(wù)并對(duì)它進(jìn)行配置,另一個(gè)是去對(duì)已經(jīng)注冊(cè)的服務(wù)實(shí)例進(jìn)行檢索:CreoteDataService 靜態(tài)方法和GMRegist
13、erdWorkflowDotoSrvic靜態(tài)方法public static WorkflowTruckTrackingDataServiceCreateDataService(Guid instancelD,WorkflowRuntime workflowRuntime,Int32 truckID)/ If were just starting, save a copy of the workflow./ runtime reference if (_workflowRuntime = null) workflowRuntime = workflowRuntime;/ If were just
14、 starting, plug in ExternalDataExchange service.if (_dataExchangeService = null) _dataExchangeService = new ExternalDataExchangeService();_workflowRuntime.AddService(_dataExchangeService);)/ Check to see if we have already added this data/ exchange service.TruckServiceDataConnector dataConnector =(T
15、ruckServiceDataConnector)workflowRuntime.GetService(typeof(T ruckServiceDataConnector);if (dataConnector = null) _dataConnector = new TruckServiceDataConnector();_dataExchangeService.AddService(_dataConnector); else dataConnector = dataConnector;)/ Pull the service instance we registered with the co
16、nnection / object.return WorkflowTruckTrackingDataService.GetRegisteredWorkflowDataService(instanceID, truckID);public static WorkflowTruckTrackingDataServiceGetRegisteredWorkflowDataService(Guid instancelD,Int32 truckID)TruckServiceDataConnector.GetRegisteredWorkflowDataService(instancelD, truckID)
17、;if (workflowDataService = null)workflowDataService =new WorkflowTruckTrackingDataService(instanceID, truckID);TruckServiceDataConnector.RegisterDataService(workflowDataService);)return workflowDataService;.現(xiàn)在添加構(gòu)造器和析構(gòu)器:類的構(gòu)造器和析構(gòu)器代碼private WorkflowTruckTrackingDataService(Guid instancelD, Int32truckID
18、)this. instancelD = instancelD;this. truckID = truckID;WorkflowTruckTrackingDataService()/ Clean upworkflowRuntime = null;_dataExchangeService = null;dataConnector = null;備注:你可以回憶一下第8章,構(gòu)造器的作用是防止在服務(wù)和連接器類之間出現(xiàn)循環(huán) 鏈接引用。而對(duì)于析構(gòu)器的作用來(lái)說(shuō),只是實(shí)現(xiàn)IDisposoble并不能完成相應(yīng)的任務(wù),因?yàn)?當(dāng)從工作流運(yùn)行時(shí)中移除該服務(wù)的時(shí)候并不調(diào)用Dispose方法。.在類的構(gòu)造器的下面,添加下
19、面的讀取關(guān)聯(lián)數(shù)據(jù)的方法:public string Read() m .return _dataConnector.RetrieveTruckInfo(InstanceIDz TruckID);.最后添加事件實(shí)現(xiàn)的代碼:事件實(shí)現(xiàn)的代碼public void RaiseTruckLeavingEvent(Int32 truckID,Int32 starting/,Int32 startingY)if (_workflowRuntime = null)_workflowRuntime = new WorkflowRuntime();/ Loads persisted workflow instan
20、ces._workflowRuntime.GetWorkflow(_instanceID);if (TruckLeaving != null)耳TruckLeaving(this, new TruckActivityEventArgs(_instanceID, truckID, starting/, startingY);/ ifpublic void RaiseRoutellpdatedEvent(Int32 truckID,_workflowRuntime = new WorkflowRuntime();/ Loads persisted workflow instances._workf
21、lowRuntime.GetWorkflow(_instanceID);if (Routellpdated != null)truckID,X, Y);public void RaiseTruckArrivedEvent(Int32 truckID)if (_workflowRuntime = null)_workflowRuntime = new WorkflowRuntime(); Loads persisted workflow instances._workflowRuntime.GetWorkflow(_instanceID);if (TruckArrived != null)Tru
22、ckArrived(this, new TruckActivityEventArgs(_instanceID,truckID);/ if .保存該文件并編譯該TruckService工程。如果存在編譯錯(cuò)誤,請(qǐng)糾正任何出現(xiàn)的編 譯錯(cuò)誤。服務(wù)類的代碼就全部完成了,列表17-3展示了該類的完整代碼。TruckSercie本地通 信服務(wù)可以準(zhǔn)備使用了。我們還沒(méi)有一個(gè)工作流來(lái)使用該服務(wù)。我們也需要使用可信賴的 wca.exe工具來(lái)為我們創(chuàng)立自定義的CQllExtemolMethod和HandleExternalEvent活動(dòng)。列表 17-3 WorkflowTruckTrockingDcitciServicacs 的完整代碼WorkflowTruckTrackingDataService 類的完整代碼using System;using System.Collections.Generic;using System.Text;using System.Workflow.Activities;using System.Workflow.Runt
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 IEC 62680-1-3:2024 EN-FR Universal serial bus interfaces for data and power - Part 1-3: Common components - USB Type-C?cable and connector specification
- 2025-2030年中國(guó)鋁包木門(mén)窗行業(yè)運(yùn)行現(xiàn)狀及發(fā)展前景分析報(bào)告
- 2025-2030年中國(guó)金融資產(chǎn)交易所行業(yè)發(fā)展趨勢(shì)規(guī)劃研究報(bào)告
- 2025-2030年中國(guó)葡萄及深加工行業(yè)發(fā)展?fàn)顩r及營(yíng)銷戰(zhàn)略研究報(bào)告
- 2025-2030年中國(guó)色紡紗市場(chǎng)運(yùn)行動(dòng)態(tài)及發(fā)展趨勢(shì)預(yù)測(cè)報(bào)告
- 2025-2030年中國(guó)羊絨產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資戰(zhàn)略研究報(bào)告
- 2025-2030年中國(guó)程控交換機(jī)行業(yè)發(fā)展現(xiàn)狀及前景趨勢(shì)分析報(bào)告
- 2025-2030年中國(guó)離心泵制造行業(yè)市場(chǎng)運(yùn)營(yíng)狀況與發(fā)展?jié)摿Ψ治鰣?bào)告
- 2025遼寧省安全員C證考試(專職安全員)題庫(kù)附答案
- 2025廣東省安全員《C證》考試題庫(kù)及答案
- 2025年人教版英語(yǔ)五年級(jí)下冊(cè)教學(xué)進(jìn)度安排表
- 同等學(xué)力英語(yǔ)申碩考試詞匯(第六版大綱)電子版
- 部編四下語(yǔ)文《口語(yǔ)交際:轉(zhuǎn)述》公開(kāi)課教案教學(xué)設(shè)計(jì)【一等獎(jiǎng)】
- BowTieXP風(fēng)險(xiǎn)與管理軟件介紹
- 污水管網(wǎng)計(jì)算說(shuō)明書(shū)
- 原子雜化軌道理論
- 充填開(kāi)采之 矸石充填術(shù)
- 文化產(chǎn)業(yè)園項(xiàng)目建議書(shū)范文
- 互聯(lián)網(wǎng)銷售卷煙(煙草)案件的分析
- 公務(wù)員考察政審表樣本
- 白菜花生長(zhǎng)過(guò)程記錄
評(píng)論
0/150
提交評(píng)論