真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

服務(wù)端對(duì)WCF數(shù)據(jù)實(shí)例分析

本篇內(nèi)容介紹了“服務(wù)端對(duì)WCF數(shù)據(jù)實(shí)例分析”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

成都創(chuàng)新互聯(lián)公司專注于開魯企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站建設(shè)。開魯網(wǎng)站建設(shè)公司,為開魯?shù)鹊貐^(qū)提供建站服務(wù)。全流程按需求定制開發(fā),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

publicclassMySyncProvider:KnowledgeSyncProvider,IChangeDataRetriever,INotifyingChangeApplierTarget  

  1. {  

  2. //Thenameofthemetadatastorecustomcolumnthatisusedtosaveatimestampoflastchangeonan  

  3. //iteminthemetadatastoresowecandochangedetection.  

  4. conststringTIMESTAMP_COLUMNNAME="timestamp";  

  5. //Thisisoursampleinmemorydatastorewhichforsimplicty,storessetsofstringname-ProcessChangeBatchpairs  

  6. //referencedbyidentifiersofthetype'Guid'  

  7. MySimpleDataStore_store;  

  8. //UsetheSyncFramework'soptionalmetadatastoretotrackversioninformation  

  9. SqlMetadataStore_metadataStore=null;//表示通過使用輕型數(shù)據(jù)庫存儲(chǔ)元數(shù)據(jù)來實(shí)現(xiàn)的元數(shù)據(jù)存儲(chǔ)區(qū)。  

  10. ReplicaMetadata_metadata=null;//提供對(duì)元數(shù)據(jù)存儲(chǔ)區(qū)中的副本元數(shù)據(jù)和項(xiàng)元數(shù)據(jù)的訪問。ReplicaMetadata還對(duì)刪除檢測(cè)和用于實(shí)現(xiàn)同步提供程序方法的幫助器提供服務(wù)  

  11. privatestring_name=null;  

  12. privatestring_folderPath=null;  

  13. privatestring_replicaMetadataFile=null;  

  14. privatestring_replicaIdFile=null;  

  15. //Theprovider'suniqueidentifier  

  16. SyncId_replicaId=null;  

  17. SyncIdFormatGroup_idFormats=null;  

  18. SyncSessionContext_currentSessionContext=null;  

  19. //Constructadatastorebyprovidinganamefortheendpoint(replica)and  

  20. //afiletowhichwe'llpersistthesyncmetadata(file)  

  21. publicMySyncProvider(stringfolderPath,stringname)  

  22. {  

  23. namename=name;  

  24. folderPathfolderPath=folderPath;  

  25. replicaMetadataFile=_folderPath.ToString()+""+_name.ToString()+".Metadata";  

  26. replicaIdFile=_folderPath.ToString()+""+_name.ToString()+".Replicaid";  

  27. SetItemIdFormatandReplicaIdFormatforusingGuidids.  

  28. idFormats=newSyncIdFormatGroup();  

  29. idFormats.ItemIdFormat.IsVariableLength=false;  

  30. idFormats.ItemIdFormat.Length=16;  

  31. idFormats.ReplicaIdFormat.IsVariableLength=false;  

  32. idFormats.ReplicaIdFormat.Length=16;  

  33. }  

  34. publicSyncIdReplicaId  

  35. {  

  36. get  

  37. {  

  38. if(_replicaId==null)  

  39. {  

  40. replicaId=GetReplicaIdFromFile(_replicaIdFile);  

  41. }  

  42. return_replicaId;  

  43. }  

  44. }  

  45. #regionMetadataStoreRelatedMethods  

  46. privatevoidInitializeMetadataStore()  

  47. {  

  48. Valuesforaddingacustomfieldtothemetadatastore  

  49. Listfields=newList();  

  50. SyncIdid=ReplicaId;  

  51. Createoropenthemetadatastore,initializingitwiththeidformatswe'llusetoreferenceouritemsandendpoints  

  52. if(!File.Exists(_replicaMetadataFile))  

  53. {  

  54. fields.Add(newFieldSchema(TIMESTAMP_COLUMNNAME,typeof(System.UInt64)));  

  55. //創(chuàng)建一個(gè)具有指定名稱和位置的元數(shù)據(jù)存儲(chǔ)區(qū)文件,然后返回表示該文件的元數(shù)據(jù)存儲(chǔ)區(qū)對(duì)象。  

  56. _metadataStore=SqlMetadataStore.CreateStore(_replicaMetadataFile);  

  57. //在元數(shù)據(jù)存儲(chǔ)區(qū)創(chuàng)建和初始化副本的元數(shù)據(jù),并返回一個(gè)用于訪問該副本元數(shù)據(jù)的副本元數(shù)據(jù)對(duì)象。  

  58. _metadata=_metadataStore.InitializeReplicaMetadata(_idFormats,//提供程序的ID格式架構(gòu)  

  59. replicaId,//與此元數(shù)據(jù)相關(guān)聯(lián)的副本ID  

  60. fields,//每個(gè)元數(shù)據(jù)項(xiàng)的自定義元數(shù)據(jù)字段的架構(gòu)信息集合。如果不存在自定義元數(shù)據(jù)字段,則可為null引用  

  61. null/*Noindexestocreate*/);//可用于更有效地查找元數(shù)據(jù)存儲(chǔ)區(qū)中的項(xiàng)的索引架構(gòu)列表。如果不存在自定義索引,則可以是null引用  

  62. }  

  63. else  

  64. {  

  65. _metadataStore=SqlMetadataStore.OpenStore(_replicaMetadataFile);//打開現(xiàn)有的元數(shù)據(jù)存儲(chǔ)區(qū)文件,并返回表示該文件的元數(shù)據(jù)存儲(chǔ)區(qū)對(duì)象  

  66. _metadata=_metadataStore.GetReplicaMetadata(_idFormats,_replicaId);//獲取用于訪問元數(shù)據(jù)存儲(chǔ)區(qū)中的副本元數(shù)據(jù)的副本元數(shù)據(jù)對(duì)象。  

  67. }  

  68. }  

  69. privatevoidCloseMetadataStore()  

  70. {  

  71. metadataStore.Dispose();  

  72. metadataStore=null;  

  73. }  

  74. //Updatethemetadatastorewithchangesthathaveoccuredonthedatastoresincethelasttimeitwasupdated.  

  75. publicvoidUpdateMetadataStoreWithLocalChanges()  

  76. {  

  77. SyncVersionnewVersion=newSyncVersion(0,_metadata.GetNextTickCount());  

  78. metadata.DeleteDetector.MarkAllItemsUnreported();  

  79. foreach(Guididin_store.Ids)  

  80. {  

  81. ItemDatadata=_store.Get(id);  

  82. ItemMetadataitem=null;  

  83. //Lookupanitem'smetadatabyitsID  

  84. item=_metadata.FindItemMetadataById(newSyncId(id));  

  85. if(null==item)  

  86. {  

  87. Newitem,musthavebeencreatedsincethatlasttimethemetadatawasupdated.  

  88. Createtheitemmetadatarequiredforsync(givingitaSyncIDandaversion,definedtobeaDWORDandaULONGLONG  

  89. Forcreates,simplyprovidetherelativereplicaID(0)andthetickcountfortheprovider(everincreasing)  

  90. item=_metadata.CreateItemMetadata(newSyncId(id),newVersion);  

  91. item.ChangeVersion=newVersion;  

  92. SaveItemMetadata(item,data.TimeStamp);  

  93. }  

  94. else  

  95. {  

  96. if(data.TimeStamp>item.GetUInt64Field(TIMESTAMP_COLUMNNAME))//theitemhaschangedsincethelastsyncoperation.  

  97. {  

  98. //ChangedItem,thisitemhaschangedsincethelasttimethemetadatawasupdated.  

  99. //Assignanewversionbysimplystating"who"modifiedthisitem(0=local/me)and"when"(tickcountforthestore)  

  100. item.ChangeVersion=newVersion;  

  101. SaveItemMetadata(item,data.TimeStamp);  

  102. }  

  103. else  

  104. {  

  105. //Unchangeditem,nothinghaschangessojustmarkitaslivesothatthemetadataknowsithasnotbeendeleted.  

  106. _metadata.DeleteDetector.ReportLiveItemById(newSyncId(id));  

  107. }  

  108. }  

  109. }  

  110. Nowgobackthroughtheitemsthatarenolongerinthestoreandmarkthemasdeletedinthemetadata.   

  111. Thissetstheitemasatombstone.  

  112. foreach(ItemMetadataitemin_metadata.DeleteDetector.FindUnreportedItems())  

  113. {  

  114. item.MarkAsDeleted(newVersion);  

  115. SaveItemMetadata(item,0);//settimestampto0fortombstones  

  116. }  

  117. }  

  118. privatevoidSaveItemMetadata(ItemMetadataitem,ulongtimeStamp)  

  119. {  

  120. item.SetCustomField(TIMESTAMP_COLUMNNAME,timeStamp);  

  121. SaveItemMetadata(item);  

  122. }  

  123. privatevoidSaveItemMetadata(ItemMetadataitem)  

  124. {  

  125. metadata.SaveItemMetadata(item);  

  126. }  

  127. //MethodforcleaninguptombstonesolderthanacertainTimeSpan  

  128. publicvoidCleanupTombstones(TimeSpantimespan)  

  129. {  

  130. InitializeMetadataStore();  

  131. metadataStore.BeginTransaction();//對(duì)元數(shù)據(jù)存儲(chǔ)區(qū)啟動(dòng)顯式事務(wù)  

  132. metadata.CleanupDeletedItems(timespan);  

  133. metadataStore.CommitTransaction();//提交已對(duì)元數(shù)據(jù)存儲(chǔ)區(qū)啟動(dòng)的顯式事務(wù)  

  134. CloseMetadataStore();  

  135. }  

  136. #endregionMetadataStoreRelatedMethods  

  137. #regionKnowledgeSyncProviderOverrides  

  138. //BeginSessioniscalledatthebeginningofeachsyncoperation. Doinitializationhere. Forexampleupdate  

  139. //metadataifitwasnotupdatedastheactualdatawaschanged.  

  140. publicoverridevoidBeginSession(SyncProviderPositionposition,SyncSessionContextsyncSessionContext)  

  141. {  

  142. BeginSession();  

  143. currentSessionContext=syncSessionContext;  

  144. }  

  145. //EndSessioniscalledafterthesyncoperationiscompleted. Cleanuphappenshere.  

  146. publicoverridevoidEndSession(SyncSessionContextsyncSessionContext)  

  147. {  

  148. EndSession();  

  149. }  

  150. //Simplyaskthemetadatastoretocomputemychangebatchforme,providingthebatchsizeandtheknowledgeoftheotherendpoint!  

  151. //Theengineisaskingforthelistofchangesthatthedestinationproviderdoesnotknowabout.  

  152. //SyncKnowledge:表示副本所具有的有關(guān)自己項(xiàng)存儲(chǔ)區(qū)的知識(shí)。  

  153. //此類型的所有公共靜態(tài)(在VisualBasic中共享)成員都是線程安全的。不保證任何實(shí)例成員的線程安全。  

  154. publicoverrideChangeBatchGetChangeBatch(uintbatchSize,SyncKnowledgedestinationKnowledge,outobjectchangeDataRetriever)  

  155. {  

  156. ChangeBatchbatch=_metadata.GetChangeBatch(batchSize,destinationKnowledge);  

  157. changeDataRetriever=this;//thisiswherethetransfermechanism/protocolwouldgo.Foraninmemoryprovider,thisissufficient  

  158. returnbatch;  

  159. }  

  160. //ThisisonlycalledwhentheenginehasdetectedthatthedestinationisoutofdateduetoTombstonecleanup.  

  161. publicoverrideFullEnumerationChangeBatchGetFullEnumerationChangeBatch(uintbatchSize,SyncIdlowerEnumerationBound,SyncKnowledgeknowledgeForDataRetrieval,outobjectchangeDataRetriever)  

  162. {  

  163. FullEnumerationChangeBatchbatch=_metadata.GetFullEnumerationChangeBatch(batchSize,lowerEnumerationBound,knowledgeForDataRetrieval);  

  164. changeDataRetriever=this;//thisiswherethetransfermechanism/protocolwouldgo.Foraninmemoryprovider,thisissufficient  

  165. returnbatch;  

  166. }  

  167. //指定batchSize為10,以及相應(yīng)的知識(shí)  

  168. publicoverridevoidGetSyncBatchParameters(outuintbatchSize,outSyncKnowledgeknowledge)  

  169. {  

  170. batchSize=10;  

  171. knowledge=_metadata.GetKnowledge();  

  172. }  

  173. //應(yīng)用修改  

  174. publicoverridevoidProcessChangeBatch(ConflictResolutionPolicyresolutionPolicy,ChangeBatchsourceChanges,  

  175. objectchangeDataRetriever,SyncCallbackssyncCallback,SyncSessionStatisticssessionStatistics)  

  176. {  

  177. metadataStore.BeginTransaction();  

  178. 從原數(shù)據(jù)存儲(chǔ)中獲得取得本地所有修改  

  179. IEnumerablelocalChanges=_metadata.GetLocalVersions(sourceChanges);  

  180. Createachangeapplierobjecttomakechangeapplicationeasier(maketheenginecallme  

  181. whenitneedsdataandwhenIshouldsavedata)  

  182. NotifyingChangeApplierchangeApplier=newNotifyingChangeApplier(_idFormats);  

  183. changeApplier.ApplyChanges(resolutionPolicy,sourceChanges,changeDataRetrieverasIChangeDataRetriever,localChanges,_metadata.GetKnowledge(),  

  184. _metadata.GetForgottenKnowledge(),this,_currentSessionContext,syncCallback);  

  185. metadataStore.CommitTransaction();  

  186. }  

  187. //Iffullenumerationisneededbecause thisproviderisoutofdateduetotombstonecleanup,thenthismethodwillbecalledbytheengine.  

  188. publicoverridevoidProcessFullEnumerationChangeBatch(ConflictResolutionPolicyresolutionPolicy,FullEnumerationChangeBatchsourceChanges,objectchangeDataRetriever,SyncCallbackssyncCallback,SyncSessionStatisticssessionStatistics)  

  189. {  

  190. metadataStore.BeginTransaction();  

  191. Getallmylocalchangeversionsfromthemetadatastore  

  192. IEnumerablelocalChanges=_metadata.GetFullEnumerationLocalVersions(sourceChanges);  

  193. Createachangeapplierobjecttomakechangeapplicationeasier(maketheenginecallme  

  194. whenitneedsdataandwhenIshouldsavedata)  

  195. NotifyingChangeApplierchangeApplier=newNotifyingChangeApplier(_idFormats);  

  196. changeApplier.ApplyFullEnumerationChanges(resolutionPolicy,sourceChanges,changeDataRetrieverasIChangeDataRetriever,localChanges,_metadata.GetKnowledge(),  

  197. _metadata.GetForgottenKnowledge(),this,_currentSessionContext,syncCallback);  

  198. metadataStore.CommitTransaction();  

“服務(wù)端對(duì)WCF數(shù)據(jù)實(shí)例分析”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!


新聞標(biāo)題:服務(wù)端對(duì)WCF數(shù)據(jù)實(shí)例分析
分享URL:http://weahome.cn/article/pojsph.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部