Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
        // 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);
                    }
                }
            }
        }