示例#1
0
        internal List <IMigrationAction> LoadPagedActions(IEnumerable <RTChangeAction> rtChangeActions)
        {
            List <IMigrationAction> realizedMigrationActions = new List <IMigrationAction>();

            SqlChangeGroup parentChangeGroup = null;
            RTChangeGroup  parentRTGroup     = null;

            foreach (RTChangeAction rtChangeAction in rtChangeActions)
            {
                if (parentRTGroup == null)
                {
                    parentChangeGroup = new SqlChangeGroup(this);
                    rtChangeAction.ChangeGroupReference.Load();
                    parentRTGroup = rtChangeAction.ChangeGroup;
                }

                IMigrationAction migrationAction = parentChangeGroup.RealizeFromEDMWithSingleAction(parentRTGroup, rtChangeAction);

                if (null != migrationAction)
                {
                    realizedMigrationActions.Add(migrationAction);
                }
            }

            return(realizedMigrationActions);
        }
示例#2
0
        public override ChangeGroup CreateForMigrationInstructionTable(ChangeGroup deltaTableChangeGroup)
        {
            ChangeGroup group = new SqlChangeGroup(this, (SqlChangeGroup)deltaTableChangeGroup);

            group.Status = ChangeStatus.PendingConflictDetection;
            return(group);
        }
示例#3
0
        public override IMigrationAction LoadSingleAction(long actionInternalId)
        {
            IMigrationAction retAction = null;

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                Guid sessionUniqueId = new Guid(Session.SessionUniqueId);
                var  actions         =
                    (from ca in context.RTChangeActionSet
                     where ca.ChangeActionId == actionInternalId
                     select ca);

                if (actions.Count() > 0)
                {
                    RTChangeAction rtChangeAction = actions.First();
                    rtChangeAction.ChangeGroupReference.Load();
                    RTChangeGroup parentRTGroup = rtChangeAction.ChangeGroup;

                    SqlChangeGroup parentChangeGroup = new SqlChangeGroup(this);
                    retAction = parentChangeGroup.RealizeFromEDMWithSingleAction(parentRTGroup, rtChangeAction);
                }
            }

            return(retAction);
        }
        private static ChangeGroup realizeChangeGroup(SqlDataReader reader, ChangeGroupManager manager)
        {
            SqlChangeGroup group = null;

            if (reader != null && reader.HasRows)
            {
                if (reader.Read())
                {
                    loadOrdinalCache(reader);

                    group = new SqlChangeGroup(manager);
                    group.ChangeGroupId  = reader.GetInt32(s_ordinalChangeGroupId);
                    group.ChangeTimeUtc  = reader.GetDateTime(s_ordinalChangeTime);
                    group.Comment        = reader.GetString(s_ordinalComment);
                    group.ExecutionOrder = reader.GetInt64(s_ordinalExecutionOrder);
                    group.Owner          = reader.GetString(s_ordinalOwner);
                    group.Status         = (ChangeStatus)reader.GetInt32(s_ordinalStatus);
                    group.SessionId      = new Guid(reader.GetString(s_ordinalSessionId));
                    group.SourceId       = reader.GetGuid(s_ordinalSourceId);
                    // TODO DB changed neededgroup.Direction = (MigrationDirection)reader.GetInt32(s_ordinalDirection);
                    group.Name = reader.GetString(s_ordinalName);
                }

                if (reader.Read())
                {
                    throw new MigrationException(MigrationToolkitResources.TooManyChangeGroupsReturned);
                }
            }

            return(group);
        }
示例#5
0
        public override ReadOnlyCollection <KeyValuePair <MigrationAction, MigrationAction> > DetectContentConflict()
        {
            List <KeyValuePair <MigrationAction, MigrationAction> > conflictActions = new List <KeyValuePair <MigrationAction, MigrationAction> >();
            Dictionary <long, SqlChangeGroup> loadedChangeGroups = new Dictionary <long, SqlChangeGroup>();

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                foreach (VCContentConflictResult contentConflictResults in context.QueryContentConflict(SourceId, new Guid(Session.SessionUniqueId)))
                {
                    RTChangeAction migrationInstructionAction =
                        context.RTChangeActionSet.Where(a => a.ChangeActionId == contentConflictResults.MigrationInstructionChangeActionId).First();

                    RTChangeAction deltaAction =
                        context.RTChangeActionSet.Where(a => a.ChangeActionId == contentConflictResults.DeltaChangeActionId).First();

                    SqlMigrationAction conflictActionSource = SqlMigrationAction.RealizeFromDB(migrationInstructionAction);
                    if (loadedChangeGroups.ContainsKey(migrationInstructionAction.ChangeGroupId))
                    {
                        conflictActionSource.ChangeGroup = loadedChangeGroups[migrationInstructionAction.ChangeGroupId];
                    }
                    else
                    {
                        RTChangeGroup  migrationInstructionChangeGroup = context.RTChangeGroupSet.Where(c => c.Id == migrationInstructionAction.ChangeGroupId).First();
                        SqlChangeGroup conflictChangeGroupSource       = new SqlChangeGroup(this);
                        conflictChangeGroupSource.RealizeFromEDMWithSingleAction(migrationInstructionChangeGroup, migrationInstructionAction);
                        loadedChangeGroups.Add(migrationInstructionAction.ChangeGroupId, conflictChangeGroupSource);
                        conflictActionSource.ChangeGroup = conflictChangeGroupSource;
                    }

                    SqlMigrationAction conflictActionTarget = SqlMigrationAction.RealizeFromDB(deltaAction);

                    if (loadedChangeGroups.ContainsKey(deltaAction.ChangeGroupId))
                    {
                        conflictActionTarget.ChangeGroup = loadedChangeGroups[deltaAction.ChangeGroupId];
                    }
                    else
                    {
                        RTChangeGroup  deltaChangeGroup          = context.RTChangeGroupSet.Where(c => c.Id == deltaAction.ChangeGroupId).First();
                        SqlChangeGroup conflictChangeGroupTarget = new SqlChangeGroup(this);
                        conflictChangeGroupTarget.RealizeFromEDMWithSingleAction(deltaChangeGroup, deltaAction);
                        loadedChangeGroups.Add(deltaAction.ChangeGroupId, conflictChangeGroupTarget);
                        conflictActionTarget.ChangeGroup = conflictChangeGroupTarget;
                    }

                    conflictActions.Add(new KeyValuePair <MigrationAction, MigrationAction>(conflictActionSource, conflictActionTarget));
                }
            }
            return(conflictActions.AsReadOnly());
        }
        /// <summary>
        /// constructor. Saves partial change group to db.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="copyFromGroup"></param>
        public SqlChangeGroup(
            ChangeGroupManager manager,
            SqlChangeGroup copyFromGroup)
            : base(manager)
        {
            Name           = copyFromGroup.Name;
            ExecutionOrder = copyFromGroup.ExecutionOrder;
            Owner          = copyFromGroup.Owner;
            ChangeTimeUtc  = copyFromGroup.ChangeTimeUtc;
            Comment        = copyFromGroup.Comment;
            RevisionTime   = copyFromGroup.RevisionTime;
            ExecutionOrder = copyFromGroup.ExecutionOrder;
            Status         = copyFromGroup.Status;

            ListenToDefaultActionCollectionChange();
        }
示例#7
0
        private IEnumerable <ChangeGroup> GetChangeGroupTablePageByStatus(
            int pageNumber,
            int pageSize,
            Guid sessionUniqueId,
            ChangeStatus status,
            bool useOtherSideMigrationItemSerializers,
            bool includeGroupInBacklog)
        {
            List <ChangeGroup> deltaTableEntries = new List <ChangeGroup>();

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int statusVal = (int)status;

                IQueryable <RTChangeGroup> query;
                if (includeGroupInBacklog)
                {
                    query = (from cg in context.RTChangeGroupSet
                             where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                             cg.SourceUniqueId.Equals(SourceId) &&
                             cg.Status == statusVal
                             orderby cg.Id
                             select cg).Skip(pageNumber * pageSize).Take(pageSize);
                }
                else
                {
                    query = (from cg in context.RTChangeGroupSet
                             where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                             cg.SourceUniqueId.Equals(SourceId) &&
                             cg.Status == statusVal &&
                             !cg.ContainsBackloggedAction
                             orderby cg.Id
                             select cg).Skip(pageNumber * pageSize).Take(pageSize);
                }

                foreach (RTChangeGroup rtChangeGroup in query)
                {
                    SqlChangeGroup changeGroup = new SqlChangeGroup(this);
                    changeGroup.UseOtherSideMigrationItemSerializers = useOtherSideMigrationItemSerializers;
                    changeGroup.RealizeFromEDM(rtChangeGroup);
                    deltaTableEntries.Add(changeGroup);
                }
            }

            return(deltaTableEntries);
        }
示例#8
0
        internal void BatchSaveGroupedChangeActions(IList <IMigrationAction> page)
        {
            // note that we assume all IMigrationActions in page belongs to the same change group
            if (page.Count == 0)
            {
                return;
            }

            ChangeGroup changeGroup = page.First().ChangeGroup;

            Debug.Assert(null != changeGroup, "IMigrationAction does not have a parent ChangeGroup");

            SqlChangeGroup sqlChangeGroup = changeGroup as SqlChangeGroup;

            Debug.Assert(null != sqlChangeGroup, "Cannot convert IMigrationAction.ChangeGroup to SqlChangeGroup");

            sqlChangeGroup.BatchSaveChangeActions(page);
        }
示例#9
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);
        }
示例#10
0
        public override ChangeGroup CreateForDeltaTable(string groupName)
        {
            ChangeGroup group = new SqlChangeGroup(this, groupName, ChangeStatus.Delta);

            return(group);
        }
示例#11
0
        public override ChangeGroup Create(string groupName)
        {
            ChangeGroup group = new SqlChangeGroup(this, groupName, ChangeStatus.AnalysisMigrationInstruction);

            return(group);
        }
示例#12
0
 internal override int PromoteAnalysisToPending(IMigrationTransaction trx)
 {
     return(SqlChangeGroup.PromoteAnalysisToPending(trx, Session.SessionUniqueId, SourceId));
 }
示例#13
0
        public override IEnumerable <ChangeGroup> NextMigrationInstructionTablePage(
            int pageNumber,
            int pageSize,
            bool isInConflictDetectionState,
            bool includeGroupInBacklog)
        {
            Guid sessionUniqueId  = new Guid(Session.SessionUniqueId);
            int  pendingDetection = (int)ChangeStatus.PendingConflictDetection;
            int  pending          = (int)ChangeStatus.Pending;

            List <ChangeGroup> deltaTableEntries = new List <ChangeGroup>();

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                IQueryable <RTChangeGroup> query;
                if (includeGroupInBacklog)
                {
                    if (isInConflictDetectionState)
                    {
                        query = (from cg in context.RTChangeGroupSet
                                 where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                                 cg.SourceUniqueId.Equals(SourceId) &&
                                 (cg.Status == pendingDetection || cg.Status == pending)
                                 orderby cg.Id
                                 select cg).Skip(pageNumber * pageSize).Take(pageSize);
                    }
                    else
                    {
                        query = (from cg in context.RTChangeGroupSet
                                 where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                                 cg.SourceUniqueId.Equals(SourceId) &&
                                 cg.Status == pending
                                 orderby cg.Id
                                 select cg).Skip(pageNumber * pageSize).Take(pageSize);
                    }
                }
                else
                {
                    if (isInConflictDetectionState)
                    {
                        query = (from cg in context.RTChangeGroupSet
                                 where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                                 cg.SourceUniqueId.Equals(SourceId) &&
                                 (cg.Status == pendingDetection || cg.Status == pending) &&
                                 !cg.ContainsBackloggedAction
                                 orderby cg.Id
                                 select cg).Skip(pageNumber * pageSize).Take(pageSize);
                    }
                    else
                    {
                        query = (from cg in context.RTChangeGroupSet
                                 where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                                 cg.SourceUniqueId.Equals(SourceId) &&
                                 cg.Status == pending &&
                                 !cg.ContainsBackloggedAction
                                 orderby cg.Id
                                 select cg).Skip(pageNumber * pageSize).Take(pageSize);
                    }
                }

                foreach (RTChangeGroup rtChangeGroup in query)
                {
                    SqlChangeGroup changeGroup = new SqlChangeGroup(this);
                    changeGroup.UseOtherSideMigrationItemSerializers = true;
                    changeGroup.RealizeFromEDM(rtChangeGroup);
                    deltaTableEntries.Add(changeGroup);
                }
            }

            return(deltaTableEntries);
        }
示例#14
0
 public override int PromoteAnalysisToPending()
 {
     return(SqlChangeGroup.PromoteAnalysisToPending(Session.SessionUniqueId, SourceId));
 }
示例#15
0
 public override ChangeGroup Next()
 {
     return(SqlChangeGroup.Next(this));
 }