/// <summary> /// Returns a SyncPoint object containg data about the last migrated items for the /// last time one direction of a sync or migration operation completed /// </summary> /// <param name="session">A Session object</param> /// <returns>A SyncPoint object or null if there have been no sync points completed for the specified session</returns> public static SyncPoint GetLatestSyncPointForSession(Session session) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { Guid sessionGuid = new Guid(session.SessionUniqueId); var syncPointQuery = (from sp in context.RTSyncPointSet where (sp.SessionUniqueId == sessionGuid) orderby sp.Id descending select sp).Take(1); if (syncPointQuery.Count() == 0) { return(null); } RTSyncPoint rtSyncPoint = syncPointQuery.First(); SyncPoint syncPoint = new SyncPoint(); syncPoint.SourceHighWaterMarkName = rtSyncPoint.SourceHighWaterMarkName; syncPoint.SourceHighWaterMarkValue = rtSyncPoint.SourceHighWaterMarkValue; syncPoint.LastMigratedTargetItemId = rtSyncPoint.LastMigratedTargetItemId; syncPoint.LastMigratedTargetItemVersion = rtSyncPoint.LastMigratedTargetItemVersion; return(syncPoint); } }
/// <summary> /// Returns a SyncPoint object containg data about the last migrated items for the /// last time one direction of a sync or migration operation completed /// </summary> /// <param name="session">A Session object</param> /// <returns>A SyncPoint object or null if there have been no sync points completed for the specified session</returns> public static List <SyncPoint> GetSyncPointsForDiff(Session session, Guid leftMigrationSourceId, Guid rightMigrationSourceId) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { List <SyncPoint> syncPointList = new List <SyncPoint>(); foreach (Guid migrationSourceGuid in new Guid[] { leftMigrationSourceId, rightMigrationSourceId }) { Guid sessionGuid = new Guid(session.SessionUniqueId); var syncPointQuery = (from sp in context.RTSyncPointSet where (sp.SessionUniqueId == sessionGuid && sp.SourceUniqueId == migrationSourceGuid) orderby sp.Id descending select sp).Take(1); if (syncPointQuery.Count() > 0) { RTSyncPoint rtSyncPoint = syncPointQuery.First(); SyncPoint syncPoint = new SyncPoint(); syncPoint.SourceMigrationSourceId = rtSyncPoint.SourceUniqueId; syncPoint.SourceHighWaterMarkName = rtSyncPoint.SourceHighWaterMarkName; syncPoint.SourceHighWaterMarkValue = rtSyncPoint.SourceHighWaterMarkValue; syncPoint.LastMigratedTargetItemId = rtSyncPoint.LastMigratedTargetItemId; syncPoint.LastMigratedTargetItemVersion = rtSyncPoint.LastMigratedTargetItemVersion; syncPointList.Add(syncPoint); } } return(syncPointList); } }
private void RecordSyncPoint( bool isLeftToRight, Guid sourceMigrationSourceId, Guid targetMigrationSourceId) { // Insert a row into the SYNC_POINT table // Get the current source high water mark var highWaterMarkQuery = (from h in m_context.RTHighWaterMarkSet where (h.SessionUniqueId == SessionId && h.SourceUniqueId == sourceMigrationSourceId) select h).Take(1); if (highWaterMarkQuery.Count() > 0) { RTHighWaterMark sourceHighWaterMark = highWaterMarkQuery.First(); // Get the corresponding target item MigrationItemId lastMigratedTargetItem = MigrationEngine.TranslationService.GetLastMigratedItemId(targetMigrationSourceId); // find last ChangeGroupId as of the sync point var lastChangeGroupQuery = (from g in m_context.RTChangeGroupSet where g.SessionUniqueId.Equals(this.SessionId) && (g.SourceUniqueId.Equals(sourceMigrationSourceId) || g.SourceUniqueId.Equals(targetMigrationSourceId)) orderby g.Id descending select g.Id).Take(1); long lastChangeGroupId = (lastChangeGroupQuery.Count() > 0 ? lastChangeGroupQuery.First() : 0); // Don't write the sync point if there is no value for lastMigratedTargetItem.ItemId if (!string.IsNullOrEmpty(lastMigratedTargetItem.ItemId)) { // Populate and save the SyncPoint info RTSyncPoint syncPoint = RTSyncPoint.CreateRTSyncPoint( 0, // Id SessionId, sourceMigrationSourceId, sourceHighWaterMark.Name, lastMigratedTargetItem.ItemId, lastMigratedTargetItem.ItemVersion ); syncPoint.SourceHighWaterMarkValue = sourceHighWaterMark.Value; syncPoint.LastChangeGroupId = lastChangeGroupId; m_context.AddToRTSyncPointSet(syncPoint); m_context.TrySaveChanges(); } } }
private void updateVCSyncPoint(ConversionResult result) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { // Populate and save the SyncPoint info RTSyncPoint syncPoint = RTSyncPoint.CreateRTSyncPoint( 0, // Id SessionId, result.SourceSideSourceId, "HWMDelta", result.ChangeId, Constants.ChangeGroupGenericVersionNumber ); syncPoint.SourceHighWaterMarkValue = result.ItemConversionHistory.First().SourceItemId; syncPoint.LastChangeGroupId = m_runTimeChangeGroup.Id; context.AddToRTSyncPointSet(syncPoint); context.TrySaveChanges(); } }
// Insert a row into the SYNC_POINT table private void RecordSyncPoint( bool isLeftToRight, Guid sourceMigrationSourceId, Guid targetMigrationSourceId) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { // Get the current source high water mark var highWaterMarkQuery = (from h in context.RTHighWaterMarkSet where (h.SessionUniqueId == SessionId && h.SourceUniqueId == sourceMigrationSourceId) select h).Take(1); if (highWaterMarkQuery.Count() > 0) { RTHighWaterMark sourceHighWaterMark = highWaterMarkQuery.First(); // Get the corresponding target item MigrationItemId lastMigratedTargetItem = MigrationEngine.TranslationService.GetLastMigratedItemId(targetMigrationSourceId); // find last ChangeGroupId as of the sync point var lastChangeGroupQuery = (from g in context.RTChangeGroupSet where g.SessionUniqueId.Equals(this.SessionId) && (g.SourceUniqueId.Equals(sourceMigrationSourceId) || g.SourceUniqueId.Equals(targetMigrationSourceId)) orderby g.Id descending select g.Id).Take(1); long lastChangeGroupId = (lastChangeGroupQuery.Count() > 0 ? lastChangeGroupQuery.First() : 0); // Use the previous sync point's values lastMigratedTargetItem the sync point if there is no value for lastMigratedTargetItem.ItemId if (string.IsNullOrEmpty(lastMigratedTargetItem.ItemId)) { IQueryable<RTSyncPoint> lastChangeSyncPointQuery = (from syncPt in context.RTSyncPointSet where syncPt.SessionUniqueId.Equals(this.SessionId) && syncPt.SourceUniqueId.Equals(sourceMigrationSourceId) && syncPt.SourceHighWaterMarkName.Equals(sourceHighWaterMark.Name) orderby syncPt.Id descending select syncPt).Take(1); if (lastChangeSyncPointQuery.Count() > 0) { RTSyncPoint previousSyncPoint = lastChangeSyncPointQuery.First(); lastMigratedTargetItem.ItemId = previousSyncPoint.LastMigratedTargetItemId; lastMigratedTargetItem.ItemVersion = previousSyncPoint.LastMigratedTargetItemVersion; } } // Don't write the sync point if there is still no value for lastMigratedTargetItem.ItemId if (!string.IsNullOrEmpty(lastMigratedTargetItem.ItemId)) { // Populate and save the SyncPoint info RTSyncPoint syncPoint = RTSyncPoint.CreateRTSyncPoint( 0, // Id SessionId, sourceMigrationSourceId, sourceHighWaterMark.Name, lastMigratedTargetItem.ItemId, lastMigratedTargetItem.ItemVersion ); syncPoint.SourceHighWaterMarkValue = sourceHighWaterMark.Value; syncPoint.LastChangeGroupId = lastChangeGroupId; context.AddToRTSyncPointSet(syncPoint); context.TrySaveChanges(); TraceManager.TraceInformation("Recorded sync point for migration source {0} of session {1} with Source High Water Mark '{2}' value of '{3}'", sourceMigrationSourceId, SessionId, syncPoint.SourceHighWaterMarkName, syncPoint.SourceHighWaterMarkValue); } } } }