本文整理汇总了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)
{
//.........这里部分代码省略.........