public virtual void Reload() { if ((m_sessionUniqueId == Guid.Empty) || (m_sourceUniqueId == Guid.Empty)) { throw new MigrationException( string.Format(MigrationToolkitResources.Culture, MigrationToolkitResources.UninitializedHighWaterMark, m_name)); } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { var highwaterMarksQuery = from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId.Equals(m_sessionUniqueId) && hwm.SourceUniqueId.Equals(m_sourceUniqueId) && hwm.Name.Equals(m_name) select hwm; RTHighWaterMark rtHighWaterMark = null; if (highwaterMarksQuery.Count() > 0) { rtHighWaterMark = highwaterMarksQuery.First(); if (rtHighWaterMark.Value != null) { m_current = CreateValueFromString(rtHighWaterMark.Value); } else { m_current = default(T); } } else { rtHighWaterMark = RTHighWaterMark.CreateRTHighWaterMark(0, m_sessionUniqueId, m_sourceUniqueId, m_name); context.AddToRTHighWaterMarkSet(rtHighWaterMark); context.TrySaveChanges(); m_current = default(T); } } /* * using (TfsMigrationConsolidatedDBEntities context = TfsMigrationConsolidatedDBEntities.CreateInstance()) * { * HighWaterMarkEntity highWaterMarkEntity = context.CreateHighWaterMark * (m_sessionUniqueId, * m_sourceUniqueId, * m_name).First<HighWaterMarkEntity>(); * * * // ToDo error handling * if (highWaterMarkEntity.Value == null) * { * m_current = default(T); * } * else * { * m_current = CreateValueFromString(highWaterMarkEntity.Value); * } * }*/ }
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(); } } }
public HighWaterMark(Guid SessionUniqueId, Guid SourceUniqueId, string name, T defaultValue) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } m_sessionUniqueId = SessionUniqueId; m_sourceUniqueId = SourceUniqueId; m_name = name; using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { var highwaterMarksQuery = from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId.Equals(m_sessionUniqueId) && hwm.SourceUniqueId.Equals(m_sourceUniqueId) && hwm.Name.Equals(m_name) select hwm; RTHighWaterMark rtHighWaterMark = null; if (highwaterMarksQuery.Count() > 0) { rtHighWaterMark = highwaterMarksQuery.First(); if (rtHighWaterMark.Value != null) { m_current = CreateValueFromString(rtHighWaterMark.Value); } } else { rtHighWaterMark = RTHighWaterMark.CreateRTHighWaterMark(0, m_sessionUniqueId, m_sourceUniqueId, m_name); context.TrySaveChanges(); } } //using (TfsMigrationConsolidatedDBEntities context = TfsMigrationConsolidatedDBEntities.CreateInstance()) //{ // HighWaterMarkEntity highWaterMarkEntity = context.CreateHighWaterMark(m_sessionUniqueId, m_sourceUniqueId, m_name).First<HighWaterMarkEntity>(); // if (highWaterMarkEntity.Value != null) // { // m_current = CreateValueFromString(highWaterMarkEntity.Value); // } //} }
public virtual void Update(T newValue) { if (newValue == null) { throw new ArgumentNullException("newValue"); } if ((m_sessionUniqueId == Guid.Empty) || (m_sourceUniqueId == Guid.Empty)) { throw new MigrationException( string.Format(MigrationToolkitResources.Culture, MigrationToolkitResources.UninitializedHighWaterMark, m_name)); } string newValueString = GetValueAsString(newValue); // Todo We probably could use EDM eventing , OnBeforeUpdate(newValue); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { var highwaterMarksQuery = from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId.Equals(m_sessionUniqueId) && hwm.SourceUniqueId.Equals(m_sourceUniqueId) && hwm.Name.Equals(m_name) select hwm; if (highwaterMarksQuery.Count() > 0) { RTHighWaterMark rtHighWaterMark = highwaterMarksQuery.First(); rtHighWaterMark.Value = newValueString; context.TrySaveChanges(); } else { RTHighWaterMark rtHighWaterMark = new RTHighWaterMark(); rtHighWaterMark.SessionUniqueId = m_sessionUniqueId; rtHighWaterMark.SourceUniqueId = m_sourceUniqueId; rtHighWaterMark.Name = m_name; rtHighWaterMark.Value = newValueString; context.AddToRTHighWaterMarkSet(rtHighWaterMark); context.TrySaveChanges(); } } m_current = newValue; }
// 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); } } } }