コード例 #1
0
        private void SavePartialChangeGroup()
        {
            if (null != m_runTimeChangeGroup)
            {
                return;
            }

            SqlChangeGroupManager manager = this.Manager as SqlChangeGroupManager;

            Debug.Assert(null != manager, "Manager is not a SqlChangeGroupManager for SqlChangeGroup");

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                try
                {
                    context.Attach(manager.RunTimeMigrationSource);
                    context.Attach(manager.RuntimeSessionRun);

                    // save group attributes
                    m_runTimeChangeGroup         = RTChangeGroup.CreateRTChangeGroup(-1, ExecutionOrder, SessionId, SourceId, (int)ChangeStatus.ChangeCreationInProgress, false);
                    m_runTimeChangeGroup.Owner   = Owner;
                    m_runTimeChangeGroup.Comment = Comment;
                    // Store the ChangeTimeUtc value in the RevsionTime column unless the ChangeTimeUtc is not set (MinValue)
                    // If it's not set, store DateTime.MaxValue to indicate that because DateTime.MinValue is outside the range allowed by SQL
                    m_runTimeChangeGroup.RevisionTime           = ChangeTimeUtc.Equals(DateTime.MinValue) ? DateTime.MaxValue : ChangeTimeUtc;
                    m_runTimeChangeGroup.StartTime              = DateTime.UtcNow;
                    m_runTimeChangeGroup.Name                   = Name;
                    m_runTimeChangeGroup.ReflectedChangeGroupId = ReflectedChangeGroupId;
                    m_runTimeChangeGroup.UsePagedActions        = m_usePagedActions;
                    m_runTimeChangeGroup.IsForcedSync           = IsForcedSync;

                    // establish SessionRun association
                    m_runTimeChangeGroup.SessionRun = manager.RuntimeSessionRun;

                    // estabilish MigrationSource association
                    m_runTimeChangeGroup.SourceSideMigrationSource = manager.RunTimeMigrationSource;


                    // save the group
                    context.AddToRTChangeGroupSet(m_runTimeChangeGroup);
                    context.TrySaveChanges();

                    // record internal Id
                    this.ChangeGroupId = m_runTimeChangeGroup.Id;
                }
                finally
                {
                    context.Detach(m_runTimeChangeGroup);
                    context.Detach(manager.RunTimeMigrationSource);
                    context.Detach(manager.RuntimeSessionRun);
                }
            }
        }
コード例 #2
0
        private void SavePartialChangeGroup()
        {
            if (null != m_runTimeChangeGroup)
            {
                return;
            }

            SqlChangeGroupManager manager = this.Manager as SqlChangeGroupManager;

            Debug.Assert(null != manager, "Manager is not a SqlChangeGroupManager for SqlChangeGroup");

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                try
                {
                    context.Attach(manager.RunTimeMigrationSource);
                    context.Attach(manager.RuntimeSessionRun);

                    // save group attributes
                    m_runTimeChangeGroup                        = RTChangeGroup.CreateRTChangeGroup(-1, ExecutionOrder, SessionId, SourceId, (int)ChangeStatus.ChangeCreationInProgress, false);
                    m_runTimeChangeGroup.Owner                  = Owner;
                    m_runTimeChangeGroup.Comment                = Comment;
                    m_runTimeChangeGroup.RevisionTime           = RevisionTime;
                    m_runTimeChangeGroup.StartTime              = DateTime.UtcNow;
                    m_runTimeChangeGroup.Name                   = Name;
                    m_runTimeChangeGroup.ReflectedChangeGroupId = ReflectedChangeGroupId;
                    m_runTimeChangeGroup.UsePagedActions        = m_usePagedActions;

                    // establish SessionRun association
                    m_runTimeChangeGroup.SessionRun = manager.RuntimeSessionRun;

                    // estabilish MigrationSource association
                    m_runTimeChangeGroup.SourceSideMigrationSource = manager.RunTimeMigrationSource;


                    // save the group
                    context.AddToRTChangeGroupSet(m_runTimeChangeGroup);
                    context.TrySaveChanges();

                    // record internal Id
                    this.ChangeGroupId = m_runTimeChangeGroup.Id;
                }
                finally
                {
                    context.Detach(m_runTimeChangeGroup);
                    context.Detach(manager.RunTimeMigrationSource);
                    context.Detach(manager.RuntimeSessionRun);
                }
            }
        }
コード例 #3
0
        internal override void Initialize(int sessionRunStorageId)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                RuntimeSessionRun =
                    (from sr in context.RTSessionRunSet
                     where sr.Id == sessionRunStorageId
                     select sr).First();
                Debug.Assert(RuntimeSessionRun != null, "Cannot find session run in DB");
                context.Detach(RuntimeSessionRun);

                RunTimeMigrationSource = context.LoadMigrationSources(SourceId).First();
                Debug.Assert(RuntimeSessionRun != null, "Cannot find migration source in DB");
                context.Detach(RunTimeMigrationSource);
            }
        }
コード例 #4
0
        internal RTLinkChangeGroup AddLinkChangeGroup(LinkChangeGroup group)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var rtLinkChangeGroup = RTLinkChangeGroup.CreateRTLinkChangeGroup(
                    0, (int)group.Status, false, SessionGroupId, SessionId, SourceId);
                rtLinkChangeGroup.GroupName = group.GroupName;
                context.AddToRTLinkChangeGroupSet(rtLinkChangeGroup);

                int newActiveActionCount = 0;
                foreach (LinkChangeAction a in group.Actions)
                {
                    RTLinkChangeAction rtLinkChangeAction = AddChangeAction(a, context);
                    if (rtLinkChangeAction == null)
                    {
                        continue;
                    }

                    rtLinkChangeAction.LinkChangeGroup = rtLinkChangeGroup;
                    ++newActiveActionCount;
                }

                if (newActiveActionCount <= 0)
                {
                    return(null);
                }

                context.TrySaveChanges();
                group.InternalId = rtLinkChangeGroup.Id;
                context.Detach(rtLinkChangeGroup);
                return(rtLinkChangeGroup);
            }
        }
コード例 #5
0
        /// <summary>
        /// Discard a migration instruction change group and reactivate the corresponding delta table entry
        /// </summary>
        /// <param name="migrationInstructionEntry"></param>
        /// <returns>The corresponding delta table entry</returns>
        internal override ChangeGroup DiscardMigrationInstructionAndReactivateDelta(ChangeGroup migrationInstructionEntry)
        {
            Debug.Assert(migrationInstructionEntry.ReflectedChangeGroupId.HasValue, "migrationInstructionEntry.ReflectedChangeGroupId does not have value");

            RTChangeGroup rtChangeGroup = null;

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                long migrInstrId = migrationInstructionEntry.ChangeGroupId;
                var  migrInstr   = context.RTChangeGroupSet.Where(g => g.Id == migrInstrId);

                long deltaId = migrationInstructionEntry.ReflectedChangeGroupId.Value;
                var  delta   = context.RTChangeGroupSet.Where(g => g.Id == deltaId);

                if (migrInstr.Count() != 1 || delta.Count() != 1)
                {
                    return(null);
                }

                migrInstr.First().Status = (int)ChangeStatus.Obsolete;

                rtChangeGroup        = delta.First();
                rtChangeGroup.Status = (int)ChangeStatus.DeltaPending;

                context.TrySaveChanges();

                context.Detach(rtChangeGroup);
            }

            SqlChangeGroup changeGroup = new SqlChangeGroup(this);

            changeGroup.UseOtherSideMigrationItemSerializers = true;
            changeGroup.RealizeFromEDM(rtChangeGroup);

            return(changeGroup);
        }
コード例 #6
0
        protected override void Create()
        {
            // ToDo
            ChangeStatus targetStatus = Status;

            SqlChangeGroupManager manager = this.Manager as SqlChangeGroupManager;

            Debug.Assert(null != manager, "Manager is not a SqlChangeGroupManager for SqlChangeGroup");

            // save the group (without child actions)
            SavePartialChangeGroup();

            // bulk save sliced child change actions
            const int bulkChangeActionInsertionSize = 1000;
            int       changeActionCount             = 0;

            while (Actions.Count > 0)
            {
                using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
                {
                    try
                    {
                        context.Attach(m_runTimeChangeGroup);

                        while (Actions.Count > 0 && changeActionCount < bulkChangeActionInsertionSize)
                        {
                            SqlMigrationAction action = Actions[0] as SqlMigrationAction;
                            Debug.Assert(null != action);
                            action.ChangeGroup = this;

                            IMigrationItemSerializer serializer = ManagerWithMigrationItemSerializers[action.Action];
                            action.CreateNew(serializer);
                            action.RTChangeAction.ChangeGroup = m_runTimeChangeGroup;

                            // Remove processed child change actions.
                            // When this ObjectModel context is disposed,
                            // the RTChangeAction will be disposed as well.
                            Actions.RemoveAt(0);

                            ++changeActionCount;
                        }
                        context.TrySaveChanges();
                    }
                    finally
                    {
                        context.Detach(m_runTimeChangeGroup);
                    }
                }

                changeActionCount = 0;
            }

            // update group status in DB
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                try
                {
                    context.Attach(m_runTimeChangeGroup);
                    m_runTimeChangeGroup.Status          = (int)targetStatus;
                    m_runTimeChangeGroup.UsePagedActions = m_usePagedActions;
                    context.TrySaveChanges();
                }
                finally
                {
                    context.Detach(m_runTimeChangeGroup);
                }
            }
        }