示例#1
0
        public override ChangeGroup CreateForMigrationInstructionTable(ChangeGroup deltaTableChangeGroup)
        {
            ChangeGroup group = new SqlChangeGroup(this, (SqlChangeGroup)deltaTableChangeGroup);

            group.Status = ChangeStatus.PendingConflictDetection;
            return(group);
        }
示例#2
0
 /// <summary>
 /// This constructor should only used by internal assembly to realize the migration action from database.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="actionId"></param>
 /// <param name="action"></param>
 /// <param name="sourceItem"></param>
 /// <param name="version"></param>
 /// <param name="mergeVersionTo"></param>
 internal SqlMigrationAction(ChangeGroup parent, long actionId, Guid action, IMigrationItem sourceItem,
                             string fromPath, string path, string version, string mergeVersionTo, string itemTypeRefName, XmlDocument actionDetails,
                             ActionState actionState)
     : base(parent, actionId, action, sourceItem, fromPath, path, version, mergeVersionTo, itemTypeRefName, actionDetails)
 {
     State = actionState;
 }
        public static void AddLabelActionsToChangeGroup(ChangeGroup changeGroup, ILabel label)
        {
            if (changeGroup != null && changeGroup.Actions.Count > 0 && label != null && label.LabelItems.Count > 0)
            {
                LabelProperties labelProperties = new LabelProperties(label);

                changeGroup.CreateAction(
                    WellKnownChangeActionId.Add,
                    null,
                    null,
                    // HACK: This is the ToPath which we shouldn't need for a label, but it is not currently nullable, so we use the first action Path
                    changeGroup.Actions[0].Path,
                    null,
                    null,
                    WellKnownContentType.VersionControlLabel.ReferenceName,
                    labelProperties.ToXmlDocument());

                // Create a MigrationAction for each item in the label
                foreach (ILabelItem labelItem in label.LabelItems)
                {
                    IMigrationAction action = changeGroup.CreateAction(
                        WellKnownChangeActionId.Add,
                        null,
                        null,
                        labelItem.ItemCanonicalPath,
                        labelItem.ItemVersion,
                        null,
                        labelItem.Recurse ?
                        WellKnownContentType.VersionControlRecursiveLabelItem.ReferenceName :
                        WellKnownContentType.VersionControlLabelItem.ReferenceName,
                        null);
                }
            }
        }
示例#4
0
 internal void FirePostChangeGroupSaved(ChangeGroup changeGroup)
 {
     if (PostChangeGroupSaved != null)
     {
         ChangeGroupEventArgs eventArgs = new ChangeGroupEventArgs(m_changeGroupManager.SourceId, changeGroup);
         PostChangeGroupSaved(this, eventArgs);
     }
 }
        private bool NoActiveMigrationInstructionInChangeGroup(ChangeGroup changeGroup)
        {
            foreach (MigrationAction action in changeGroup.Actions)
            {
                if (action.State == ActionState.Pending)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
        public static MigrationConflict CreateConflict(ChangeGroup changeGroup, string conflictDetails, string actionPath)
        {
            if (changeGroup == null)
            {
                throw new ArgumentNullException("changeGroup");
            }
            if (string.IsNullOrEmpty(actionPath))
            {
                throw new ArgumentNullException("actionPath");
            }

            VCContentConflictType conflictInstance = new VCContentConflictType();

            return(new VCContentConflict(conflictInstance, changeGroup, conflictDetails, actionPath));
        }
示例#7
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);
        }
 private void InvokePostChangeGroupMigrationAddins(Guid migrationSourceId, ChangeGroup changeGroup)
 {
     foreach (MigrationAddin migrationAddin in m_addinManagementService.GetMigrationSourceMigrationAddins(migrationSourceId))
     {
         Debug.Assert(m_migrationContextsByMigrationSource.ContainsKey(migrationSourceId));
         Debug.Assert(m_migrationProviders.ContainsKey(migrationSourceId));
         MigrationContext migrationContext;
         if (m_migrationContextsByMigrationSource.TryGetValue(migrationSourceId, out migrationContext))
         {
             try
             {
                 migrationAddin.PostChangeGroupMigration(migrationContext, changeGroup);
             }
             catch (Exception e)
             {
                 ProcessAddinException(migrationAddin, migrationSourceId, e);
             }
         }
     }
 }
示例#9
0
        /// <summary>
        /// Add a migration action to delta table. The migration actions will be grouped together to create a change group.
        /// The following rules are used to group migration actions.
        /// 1. Action path and fromPath does not collide with any existing paths.
        /// 2. Action comment is the same.
        /// 3. Action owner is the same.
        /// 4. Action time is not more than 10 minutes away from the previous action.
        /// The return value is the delta table entry the migration action is added to.
        /// If a new changegroup is generated, oldChangeGroup contains the previous changegroup.
        /// </summary>
        /// <param name="defaultGroupName"></param>
        /// <param name="comment"></param>
        /// <param name="owner"></param>
        /// <param name="executionOrder"></param>
        /// <param name="action"></param>
        /// <param name="sourceItem"></param>
        /// <param name="fromPath"></param>
        /// <param name="path"></param>
        /// <param name="version"></param>
        /// <param name="mergeVersionTo"></param>
        /// <param name="itemTypeRefName"></param>
        /// <param name="actionDetails"></param>
        /// <param name="actionTime"></param>
        /// <param name="oldChangeGroup"></param>
        /// <returns></returns>
        public ChangeGroup AddMigrationActionToDeltaTable(string defaultGroupName, string comment, string owner, long executionOrder,
                                                          Guid action, IMigrationItem sourceItem, string fromPath, string path, string version, string mergeVersionTo, string itemTypeRefName,
                                                          XmlDocument actionDetails, DateTime actionTime, out ChangeGroup oldChangeGroup)
        {
            if (m_currentChangeGroup == null)
            {
                oldChangeGroup = null;
                m_existingActionPaths.Clear();
                m_currentChangeGroup                = CreateChangeGroupForDeltaTable(defaultGroupName);
                m_currentChangeGroup.Comment        = comment;
                m_currentChangeGroup.Owner          = owner;
                m_currentChangeGroup.ExecutionOrder = executionOrder;
            }
            else if (m_existingActionPaths.Contains(path) ||
                     (!string.IsNullOrEmpty(fromPath) && m_existingActionPaths.Contains(fromPath)) ||
                     !string.Equals(comment, m_currentChangeGroup.Comment, StringComparison.Ordinal) ||
                     !string.Equals(owner, m_currentChangeGroup.Owner, StringComparison.Ordinal) ||
                     (m_latestActionTime != DateTime.MinValue && actionTime != DateTime.MinValue && (actionTime - m_latestActionTime > MaxGroupTimeSpan)))
            {
                m_currentChangeGroup.Save();
                oldChangeGroup                      = m_currentChangeGroup;
                m_currentChangeGroup                = CreateChangeGroupForDeltaTable(defaultGroupName);
                m_currentChangeGroup.Comment        = comment;
                m_currentChangeGroup.Owner          = owner;
                m_currentChangeGroup.ExecutionOrder = executionOrder;
                m_existingActionPaths.Clear();
            }
            else
            {
                oldChangeGroup = m_currentChangeGroup;
            }
            m_currentChangeGroup.CreateAction(action, sourceItem, fromPath, path, version, mergeVersionTo, itemTypeRefName, actionDetails);
            m_existingActionPaths.Add(path);
            if (!string.IsNullOrEmpty(fromPath))
            {
                m_existingActionPaths.Add(fromPath);
            }
            m_latestActionTime = actionTime;

            return(m_currentChangeGroup);
        }
示例#10
0
        internal override void ReactivateMigrationInstruction(
            ChangeGroup migrationInstruction,
            ChangeGroup deltaEntryToObsolete)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                long migrInstrId = migrationInstruction.ChangeGroupId;
                var  migrInstr   = context.RTChangeGroupSet.Where(g => g.Id == migrInstrId);

                long deltaId = deltaEntryToObsolete.ChangeGroupId;
                var  delta   = context.RTChangeGroupSet.Where(g => g.Id == deltaId);

                Debug.Assert(migrInstr.Count() == 1, "migrInstr.Count() != 1");
                Debug.Assert(delta.Count() == 1, "delta.Count() != 1");

                migrInstr.First().Status = (int)ChangeStatus.Pending;
                delta.First().Status     = (int)ChangeStatus.DeltaComplete;

                context.TrySaveChanges();
            }
        }
        private void FinishChangeGroupMigration(ChangeGroup nextChangeGroup, ConversionResult result)
        {
            // TODO: update group conversion history and mark group complete should be in one transaction
            bool changeGroupIsNotSkipped = !result.ChangeId.Equals(Constants.MigrationResultSkipChangeGroup, StringComparison.InvariantCultureIgnoreCase);

            if (changeGroupIsNotSkipped)
            {
                // HACK: Currently separate ChangeGroups are created to hold label actions
                // These need to be marked Complete, so the value below is store in the ChangeId name
                // but we don't want these in the conversion history table
                if (result.ChangeId == WellKnownContentType.VersionControlLabel.ReferenceName)
                {
                    changeGroupIsNotSkipped = false;
                }
                else
                {
                    nextChangeGroup.UpdateConversionHistory(result);
                }
            }
            nextChangeGroup.Complete();

            if (changeGroupIsNotSkipped)
            {
                // cache the conversion history in TranslactionService
                foreach (ItemConversionHistory hist in result.ItemConversionHistory)
                {
                    if (string.IsNullOrEmpty(hist.SourceItemId) ||
                        string.IsNullOrEmpty(hist.TargetItemId))
                    {
                        throw new MigrationException(MigrationToolkitResources.InvalidConversionHistoryInfo);
                    }

                    string targetItemVersionStr = string.IsNullOrEmpty(hist.TargetItemVersion)
                                                   ? Constants.ChangeGroupGenericVersionNumber
                                                   : hist.TargetItemVersion;
                    TranslationService.CacheItemVersion(hist.TargetItemId, targetItemVersionStr, result.TargetSideSourceId);
                }
            }
        }
示例#12
0
        private void Initialize(ChangeGroup parent, long actionId, Guid action, IMigrationItem sourceItem,
                                string fromPath, string path, string version, string mergeVersionTo, string itemTypeRefName, XmlDocument actionDetails)
        {
            m_parent          = parent;
            m_actionId        = actionId;
            m_action          = action;
            m_sourceItem      = sourceItem;
            m_fromPath        = fromPath;
            m_path            = path;
            m_version         = version;
            m_mergeVersionTo  = mergeVersionTo;
            m_itemTypeRefName = itemTypeRefName;
            m_actionDetails   = actionDetails;

            if (null != m_actionDetails)
            {
                m_actionDetails.NodeChanged  += new XmlNodeChangedEventHandler(m_actionDetails_NodeChanged);
                m_actionDetails.NodeInserted += new XmlNodeChangedEventHandler(m_actionDetails_NodeInserted);
                m_actionDetails.NodeRemoved  += new XmlNodeChangedEventHandler(m_actionDetails_NodeRemoved);
            }

            IsDirty = false;
        }
示例#13
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);
        }
示例#14
0
        /// <summary>
        /// Generate migration instructions
        /// </summary>
        internal void GenerateMigrationInstructions(Guid targetSystemId)
        {
            try
            {
                // Given target system, find change group service for source and for ourselves...
                ConfigurationService configurationService = m_serviceContainers[targetSystemId].GetService(typeof(ConfigurationService)) as ConfigurationService;

                // ToDo, not sure, we can probably just pass in ource system id to let target change group service to load it. But source/target may be different, not sqlchangegroupmanager
                ChangeGroupService sourceChangeGroupService = m_serviceContainers[configurationService.MigrationPeer].GetService(typeof(ChangeGroupService)) as ChangeGroupService;
                ChangeGroupService targetChangeGroupService = m_serviceContainers[targetSystemId].GetService(typeof(ChangeGroupService)) as ChangeGroupService;

                // CopySourceDeltaTableToTarget
                //ChangeGroup deltaTableEntry;

                if (StopMigrationEngineOnBasicConflict)
                {
                    // if one of the delta table entry on source side is conflicted, we stop
                    long?firstConflictedChangeGroupId = sourceChangeGroupService.GetFirstConflictedChangeGroup(ChangeStatus.DeltaPending);
                    if (firstConflictedChangeGroupId.HasValue)
                    {
                        return;
                    }

                    // if one of the migration instruction for target side is conflict, we also stop
                    firstConflictedChangeGroupId = targetChangeGroupService.GetFirstConflictedChangeGroup(ChangeStatus.Pending);
                    if (firstConflictedChangeGroupId.HasValue)
                    {
                        return;
                    }
                }

                ChangeActionRegistrationService changeActionRegistrationService =
                    m_serviceContainers[targetSystemId].GetService(typeof(ChangeActionRegistrationService)) as ChangeActionRegistrationService;

                int pageNumber = 0;
                IEnumerable <ChangeGroup> changeGroups;
                do
                {
                    // NOTE: we do not increment pageNumber here, because the processed ChangeGroups are marked "DeltaComplete" and no longer
                    //       appear in the delta table
                    changeGroups = sourceChangeGroupService.NextDeltaTablePage(pageNumber, m_pageSize, false);
                    foreach (ChangeGroup deltaTableEntry in changeGroups)
                    {
                        TraceManager.TraceInformation(string.Format(
                                                          "Generating migration instruction for ChangeGroup {0}",
                                                          deltaTableEntry.ChangeGroupId));

                        ChangeGroup migrationInstructionChangeGroup = targetChangeGroupService.CreateChangeGroupForMigrationInstructionTable(deltaTableEntry);

                        // NOTE:
                        // migration instruction change group is created using the target change group manager/service
                        // however, the MigrationItems in it are created by the source-side adapter
                        // by setting the UseOtherSideMigrationItemSerializers flag, we tell this change group to use the source-side change group manager
                        // to find the registered IMigrationItem serializer to persist these MigrationItems
                        migrationInstructionChangeGroup.UseOtherSideMigrationItemSerializers = true;

                        migrationInstructionChangeGroup.ReflectedChangeGroupId = deltaTableEntry.ChangeGroupId;

                        foreach (MigrationAction action in deltaTableEntry.Actions)
                        {
                            try
                            {
                                BeforeCopyDeltaTableEntryToMigrationInstructionTable(action, configurationService.MigrationPeer);
                            }
                            catch (UnmappedWorkItemTypeException unmappedWITEx)
                            {
                                ConflictManager conflictManager =
                                    m_serviceContainers[configurationService.MigrationPeer].GetService(typeof(ConflictManager)) as ConflictManager;

                                var conflict = WITUnmappedWITConflictType.CreateConflict(unmappedWITEx.SourceWorkItemType, action);

                                List <MigrationAction> actions;
                                var result = conflictManager.TryResolveNewConflict(conflictManager.SourceId, conflict, out actions);

                                if (!result.Resolved)
                                {
                                    continue;
                                }
                                else
                                {
                                    if (result.ResolutionType == ConflictResolutionType.SkipConflictedChangeAction)
                                    {
                                        action.State = ActionState.Skipped;
                                        continue;
                                    }
                                    else
                                    {
                                        // NOTE:
                                        // So far this conflict can only be:
                                        // 1. manually resolved (skipped) AFTER
                                        //    the configuration is updated with the requirement WIT mapping;
                                        // 2. skipping the conflicted migration action (i.e. not migrating the source
                                        //    Work Item type.
                                        Debug.Assert(
                                            false,
                                            string.Format("WITUnmappedWITConflict is auto-resolved. Skipping this assertion will SKIP the original conflicted action '{0}'.",
                                                          action.ActionId.ToString()));
                                        action.State = ActionState.Skipped;
                                        continue;
                                    }
                                }
                            }

                            if (action.State == ActionState.Skipped || action.ChangeGroup.ContainsBackloggedAction)
                            {
                                continue;
                            }
                            ChangeActionHandler actionHandler;
                            if (changeActionRegistrationService.TryGetChangeActionHandler(action.Action, action.ItemTypeReferenceName, out actionHandler))
                            {
                                try
                                {
                                    actionHandler(action, migrationInstructionChangeGroup);
                                }
                                catch (MigrationUnresolvedConflictException)
                                {
                                    // We have already created an unresolved conflict, just return.
                                    return;
                                }
                                catch (Exception e)
                                {
                                    ConflictManager manager = m_serviceContainers[targetSystemId].GetService(typeof(ConflictManager)) as ConflictManager;
                                    ErrorManager.TryHandleException(e, manager);
                                }
                            }
                            else
                            {
                                string            analysisProviderName;
                                IAnalysisProvider analysisProvider;
                                if (m_analysisProviders.TryGetValue(targetSystemId, out analysisProvider))
                                {
                                    analysisProviderName = analysisProvider.GetType().ToString();
                                }
                                else
                                {
                                    Debug.Fail("Unable to find IAnalysisProvider with Id: " + targetSystemId);
                                    analysisProviderName = "Unknown";
                                }
                                throw new MigrationException(
                                          string.Format(MigrationToolkitResources.Culture, MigrationToolkitResources.UnknownChangeAction,
                                                        action.Action.ToString(), analysisProviderName));
                            }
                        }

                        if (!migrationInstructionChangeGroup.ContainsBackloggedAction &&
                            migrationInstructionChangeGroup.Actions.Count > 0)
                        {
                            ChangeStatus status = migrationInstructionChangeGroup.Status;
                            migrationInstructionChangeGroup.Status = ChangeStatus.ChangeCreationInProgress;
                            migrationInstructionChangeGroup.Owner  = deltaTableEntry.Owner; // owner may be translated too
                            // Save the partial Change group into DB.
                            migrationInstructionChangeGroup.Save();

                            // Commit the status change together.
                            migrationInstructionChangeGroup.Status = status;
                            deltaTableEntry.Status = ChangeStatus.DeltaComplete;
                            migrationInstructionChangeGroup.Manager.BatchUpdateStatus(
                                new ChangeGroup[] { migrationInstructionChangeGroup, deltaTableEntry });
                        }
                        else
                        {
                            // If all change actions in the delta table entry are skipped.
                            // Just mark the delta table entry as completed.
                            deltaTableEntry.UpdateStatus(ChangeStatus.DeltaComplete);
                        }

                        if (this.StopRequested)
                        {
                            return;
                        }
                    }
                }while (changeGroups.Count() == m_pageSize);

                DetectBasicConflicts(targetChangeGroupService, targetSystemId, configurationService.MigrationPeer);

                if (this.StopRequested)
                {
                    return;
                }

                ProviderDetectConflicts(targetSystemId, targetChangeGroupService);

                if (this.StopRequested)
                {
                    return;
                }

                // dispose the target side delta table entries after we've done all conflict analysis
                targetChangeGroupService.BatchMarkMigrationInstructionsAsPending();
            }
            catch (Exception e)
            {
                ConflictManager manager = m_serviceContainers[targetSystemId].GetService(typeof(ConflictManager)) as ConflictManager;
                ErrorManager.TryHandleException(e, manager);
            }
        }
示例#15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="migrationContext"></param>
 /// <param name="changeGroup"></param>
 public virtual void PostChangeGroupMigration(
     MigrationContext migrationContext, ChangeGroup changeGroup)
 {
 }
示例#16
0
 /// <summary>
 /// Creates and initializes a new change group with the specified name in migration instruction table.
 /// </summary>
 /// <param name="deltaTableChangeGroup">The name of the ChangeGroup to create</param>
 /// <returns>The new ChangeGroup</returns>
 public ChangeGroup CreateChangeGroupForMigrationInstructionTable(ChangeGroup deltaTableChangeGroup)
 {
     return(m_changeGroupManager.CreateForMigrationInstructionTable(deltaTableChangeGroup));
 }
示例#17
0
 internal ChangeGroupEventArgs(Guid sourceId, ChangeGroup changeGroup)
 {
     m_sourceId    = sourceId;
     m_changeGroup = changeGroup;
 }
示例#18
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 ChangeGroup ReactivateDeltaEntry(ChangeGroup migrationInstructionEntry)
 {
     return(m_changeGroupManager.DiscardMigrationInstructionAndReactivateDelta(migrationInstructionEntry));
 }
 protected virtual void ProcessMigrInstructionTableEntry(ChangeGroup changeGroup, Guid sourceId)
 {
 }
 /// <summary>
 /// Creates a new event args with the specified changeGroup.
 /// </summary>
 public VersionControlEventArgs(ChangeGroup changeGroup, SystemType sourceSystem)
     : this(changeGroup, MigrationToolkitResources.DefaultVCEventString, sourceSystem)
 {
 }
示例#21
0
 internal void ReactivateMigrationInstruction(ChangeGroup migrationInstruction, ChangeGroup deltaEntryToObsolete)
 {
     m_changeGroupManager.ReactivateMigrationInstruction(migrationInstruction, deltaEntryToObsolete);
 }
 /// <summary>
 /// Creates a new event args with the specified session and description.
 /// </summary>
 /// <param name="description">The description of the event</param>
 public VersionControlEventArgs(ChangeGroup changeGroup, string description, SystemType sourceSystem)
     : this(changeGroup, description, null, sourceSystem)
 {
 }
 /// <summary>
 /// Creates a new event args with the specified session and description.
 /// </summary>
 /// <param name="changeGroup"></param>
 /// <param name="description">The description of the event</param>
 public VersionControlEventArgs(ChangeGroup changeGroup, string description, Exception exception, SystemType sourceSystem)
     : base(description, exception)
 {
     m_changeGroup   = changeGroup;
     m_primarySystem = sourceSystem;
 }
示例#24
0
 /// <summary>
 /// Creates a new change group with the specified name in migration instruction table
 /// </summary>
 /// <param name="deltaTableGroup"></param>
 /// <returns></returns>
 public abstract ChangeGroup CreateForMigrationInstructionTable(ChangeGroup deltaTableGroup);
示例#25
0
 protected MigrationAction(ChangeGroup parent, long actionId, Guid action, IMigrationItem sourceItem,
                           string fromPath, string path, string version, string mergeVersionTo, string itemTypeRefName, XmlDocument actionDetails)
 {
     Initialize(parent, actionId, action, sourceItem, fromPath, path, version, mergeVersionTo, itemTypeRefName, actionDetails);
 }
示例#26
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 abstract ChangeGroup DiscardMigrationInstructionAndReactivateDelta(ChangeGroup migrationInstructionEntry);
示例#27
0
 /// <summary>
 /// Discard a delta table entry and reactivate the corresponding migration instruction change group
 /// </summary>
 /// <param name="migrationInstruction"></param>
 /// <param name="deltaEntryToObsolete"></param>
 internal abstract void ReactivateMigrationInstruction(ChangeGroup migrationInstruction, ChangeGroup deltaEntryToObsolete);
 private static Collection <IMigrationAction> realizeActionList(SqlDataReader reader, ChangeGroupManager manager, ChangeGroup parent)
 {
     throw new NotImplementedException();
 }
        private bool updateConversionHistory(MigrationConflict conflict, ConflictResolutionRule rule)
        {
            if (!rule.DataFieldDictionary.ContainsKey(VCContentConflictUserMergeChangeAction.MigrationInstructionChangeId) ||
                !rule.DataFieldDictionary.ContainsKey(VCContentConflictUserMergeChangeAction.DeltaTableChangeId))
            {
                return(false);
            }
            string migrationInstructionName = rule.DataFieldDictionary[VCContentConflictUserMergeChangeAction.MigrationInstructionChangeId];
            string deltaTableName           = rule.DataFieldDictionary[VCContentConflictUserMergeChangeAction.DeltaTableChangeId];

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                ChangeGroup conflictChangeGroup = conflict.ConflictedChangeAction.ChangeGroup;
                Guid        deltaSideSourceId;

                // Mark all delta table entry as DeltaComplete
                var deltaTableEntries =
                    from d in context.RTChangeGroupSet
                    where d.SessionUniqueId == conflictChangeGroup.SessionId &&
                    d.Status == (int)ChangeStatus.DeltaPending
                    select d;
                foreach (RTChangeGroup deltaTableEntry in deltaTableEntries)
                {
                    deltaTableEntry.Status = (int)ChangeStatus.DeltaComplete;
                    deltaTableEntry.ContainsBackloggedAction = false;
                }

                // Mark all migration instruction entry as Complete
                var migrationInstructionEntries =
                    from d in context.RTChangeGroupSet
                    where d.SessionUniqueId == conflictChangeGroup.SessionId &&
                    (d.Status == (int)ChangeStatus.Pending || d.Status == (int)ChangeStatus.InProgress || d.Status == (int)ChangeStatus.PendingConflictDetection)
                    select d;
                foreach (RTChangeGroup migrationInstructionEntry in migrationInstructionEntries)
                {
                    migrationInstructionEntry.Status = (int)ChangeStatus.Complete;
                    migrationInstructionEntry.ContainsBackloggedAction = false;
                }

                // Mark the source side highwatermark
                var sourceSideHighWaterMark =
                    (from hwm in context.RTHighWaterMarkSet
                     where hwm.SessionUniqueId == conflictChangeGroup.SessionId &&
                     hwm.SourceUniqueId != conflictChangeGroup.SourceId &&
                     hwm.Name == Constants.HwmDelta
                     select hwm).First();
                Debug.Assert(sourceSideHighWaterMark != null, "Can't find the source side HWM");

                sourceSideHighWaterMark.Value = deltaTableName;
                deltaSideSourceId             = sourceSideHighWaterMark.SourceUniqueId;

                // Mark the target side highwatermark
                var targetHighWaterMark =
                    (from hwm in context.RTHighWaterMarkSet
                     where hwm.SessionUniqueId == conflictChangeGroup.SessionId &&
                     hwm.SourceUniqueId == conflictChangeGroup.SourceId &&
                     hwm.Name == Constants.HwmDelta
                     select hwm).First();
                Debug.Assert(targetHighWaterMark != null, "Can't find the target side HWM");

                targetHighWaterMark.Value = migrationInstructionName;

                // Create the conversion history entry
                RTConversionHistory conversionHistory = RTConversionHistory.CreateRTConversionHistory(
                    DateTime.UtcNow,
                    -1,
                    true);
                conversionHistory.Comment = rule.RuleDescription;

                var session =
                    (from s in context.RTSessionConfigSet
                     where s.SessionUniqueId == conflictChangeGroup.SessionId
                     select s).First();

                Debug.Assert(session != null, "Cannot find session in DB");

                RTSessionRun sessionRun =
                    (from sr in context.RTSessionRunSet
                     where sr.Id == session.Id
                     select sr).First();
                Debug.Assert(sessionRun != null, "Cannot find session run in DB");

                conversionHistory.SessionRun = sessionRun;

                RTMigrationSource migrationSource =
                    (from ms in context.RTMigrationSourceSet
                     where ms.UniqueId.Equals(conflictChangeGroup.SourceId)
                     select ms).First();
                Debug.Assert(migrationSource != null, "Cannot find the migration source to persist conversion history");

                RTMigrationSource deltaSideMigrationSource =
                    (from ms in context.RTMigrationSourceSet
                     where ms.UniqueId.Equals(deltaSideSourceId)
                     select ms).First();
                Debug.Assert(deltaSideMigrationSource != null, "Cannot find the migration source to persist conversion history");

                conversionHistory.SourceMigrationSource = migrationSource;

                context.AddToRTConversionHistorySet(conversionHistory);

                RTMigrationItem sourceItem = RTMigrationItem.CreateRTMigrationItem(0, deltaTableName, Constants.ChangeGroupGenericVersionNumber);
                sourceItem.MigrationSource = migrationSource;
                RTMigrationItem targetItem = RTMigrationItem.CreateRTMigrationItem(0, migrationInstructionName, Constants.ChangeGroupGenericVersionNumber);
                targetItem.MigrationSource = deltaSideMigrationSource;


                RTItemRevisionPair pair = RTItemRevisionPair.CreateRTItemRevisionPair(
                    sourceItem.Id, targetItem.Id);
                pair.LeftMigrationItem  = sourceItem;
                pair.RightMigrationItem = targetItem;
                pair.ConversionHistory  = conversionHistory;



                // Create a new HistoryNotFoundConflict Resolution Rule
                context.TrySaveChanges();
            }
            return(true);
        }
示例#30
0
 protected MigrationAction(ChangeGroup parent, Guid action, IMigrationItem sourceItem,
                           string fromPath, string path, string version, string mergeVersionTo, string itemTypeRefName, XmlDocument actionDetails)
     : this(parent, DefaultActionId, action, sourceItem, fromPath, path, version, mergeVersionTo, itemTypeRefName, actionDetails)
 {
 }