当前位置: 首页>>代码示例>>C#>>正文


C# SessionBase.OpenPage方法代码示例

本文整理汇总了C#中SessionBase.OpenPage方法的典型用法代码示例。如果您正苦于以下问题:C# SessionBase.OpenPage方法的具体用法?C# SessionBase.OpenPage怎么用?C# SessionBase.OpenPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SessionBase的用法示例。


在下文中一共展示了SessionBase.OpenPage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SyncWith

 static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func<SessionBase, UInt64, Change, bool> doUpdate)
 {
   UInt64 currentVersion;
   UInt64 pageToReadVersion;
   bool conflictFound = false;
   using (var reader = sessionToRead.BeginRead())
   {
     Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false);
     if (changes != null)
     {
       using (var updater = sessionToUpdate.BeginUpdate())
       {
         var dbs = sessionToUpdate.OpenAllDatabases();
         ReplicaSync matchingReplicaSync = null;
         foreach (ReplicaSync sync in sessionToUpdate.AllObjects<ReplicaSync>())
         {
           if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory)
           {
             matchingReplicaSync = sync;
             break;
           }
         }
         if (changes.ChangeList.Count > 0)
         {
           foreach (TransactionChanges transactionChanges in changes.ChangeList)
           {
             if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber)
             {
               foreach (Change change in transactionChanges.ChangeList)
               {
                 Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false);
                 Database dbToRead = sessionToRead.OpenDatabase(change.DatabaseId, false, false);
                 string dbName = dbToRead != null ? dbToRead.Name : null;
                 if (change.Deleted)
                 {
                   if (dbToUpdate == null) // does not exist
                     continue;
                   if (change.PageId == 0) // Database delete
                   {
                     currentVersion = dbToUpdate.Page.PageInfo.VersionNumber;
                     if (currentVersion < change.Version)
                       sessionToUpdate.DeleteDatabase(dbToUpdate);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.DeleteDatabase(dbToUpdate);
                     }
                   }
                   else
                   {
                     Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                     if (page == null) // page does not exist
                       continue;
                     currentVersion = page.PageInfo.VersionNumber;
                     if (currentVersion < change.Version)
                       sessionToUpdate.DeletePage(dbToUpdate, page);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.DeleteDatabase(dbToUpdate);
                     }
                   }
                 }
                 else
                 {
                   if (dbToUpdate == null) // does not exist
                     dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName);
                   if (change.PageId > 0)
                   {
                     Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                     Page pageToRead = sessionToRead.OpenPage(dbToRead, change.PageId);
                     if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page
                       continue;
                     currentVersion = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber;
                     pageToReadVersion = pageToRead.PageInfo.VersionNumber;
                     if (currentVersion < pageToReadVersion || dbToUpdate.IsNew)
                       sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                     else
                     {
                       conflictFound = true;
                       if (doUpdate(sessionToUpdate, currentVersion, change))
                         sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                     }
                   }
                 }
               }
             }
           }
           UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber;
           if (matchingReplicaSync != null)
             matchingReplicaSync.TransactionNumber = lastTransactionNumber;
           if (conflictFound)
           {
             sessionToUpdate.Verify();
           }
           sessionToUpdate.Commit();
           if (matchingReplicaSync == null)
           {
//.........这里部分代码省略.........
开发者ID:VelocityDB,项目名称:VelocityDB,代码行数:101,代码来源:Sync.cs


注:本文中的SessionBase.OpenPage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。