Exemplo n.º 1
0
        private XmlDocument CreateWorkItemUpdateOperation(MigrationAction action)
        {
            XmlDocument desc     = action.RecordDetails.DetailsDocument;
            XmlElement  rootNode = desc.DocumentElement;

            Debug.Assert(null != rootNode,
                         "Wit IMigrationAction.MigrationActionDescription is invalid.");
            Debug.Assert(null != rootNode.Attributes["WorkItemType"],
                         "WorkItemType is missing in MigrationActionDescription.");
            Debug.Assert(null != rootNode.Attributes["Author"],
                         "Author is missing in MigrationActionDescription.");
            Debug.Assert(null != rootNode.Attributes["ChangeDate"],
                         "ChangeDate is missing in MigrationActionDescription.");
            string workItemType   = rootNode.Attributes["WorkItemType"].Value;
            string author         = rootNode.Attributes["Author"].Value;
            string changeDate     = rootNode.Attributes["ChangeDate"].Value;
            string targetRevision = rootNode.Attributes["TargetRevision"].Value;

            TfsUpdateDocument tfsUpdateDocument = InitializeUpdateDocument();

            tfsUpdateDocument.CreateWorkItemUpdateDoc(TargetWorkItem.Id.ToString(), targetRevision);
            tfsUpdateDocument.AddFields(action, workItemType, author, changeDate, false);

            tfsUpdateDocument.InsertConversionHistoryCommentToHistory(
                workItemType,
                GenerateMigrationHistoryComment(action));

            // insert source item Id to field TfsMigrationTool.ReflectedWorkItemId if it is in WITD
            tfsUpdateDocument.InsertConversionHistoryField(
                workItemType,
                action.SourceWorkItemId);

            return(tfsUpdateDocument.UpdateDocument);
        }
Exemplo n.º 2
0
        internal string GetSourceWorkItemRevision(
            MigrationAction action)
        {
            XmlAttribute workItemRevAttr = action.RecordDetails.DetailsDocument.DocumentElement.Attributes["Revision"];

            return(workItemRevAttr == null ? string.Empty : workItemRevAttr.Value);
        }
Exemplo n.º 3
0
        public override void BasicActionHandler(MigrationAction action, ChangeGroup group)
        {
            try
            {
                VersionControlPath.GetFullPath(action.Path, true);
                if (!string.IsNullOrEmpty(action.FromPath))
                {
                    VersionControlPath.GetFullPath(action.FromPath, true);
                }
            }
            catch (Exception e)
            {
                MigrationConflict pathTooLongConflict = VCInvalidPathConflictType.CreateConflict(action, e.Message, action.Path);

                List <MigrationAction>   returnActions;
                ConflictResolutionResult resolutionResult = ((TfsVCAnalysisProvider)AnalysisProvider).ConflictManager.TryResolveNewConflict(
                    group.SourceId, pathTooLongConflict, out returnActions);
                if (resolutionResult.Resolved)
                {
                    switch (resolutionResult.ResolutionType)
                    {
                    case ConflictResolutionType.SkipConflictedChangeAction:
                        return;

                    default:
                        Debug.Fail("Unknown resolution result");
                        return;
                    }
                }
                return;
            }
            base.BasicActionHandler(action, group);
        }
Exemplo n.º 4
0
 public VCInvalidLabelNameConflict(ConflictType conflictType, MigrationAction conflictAction, string message)
     : base(conflictType,
            Status.Unresolved,
            message,
            string.Empty)
 {
     ConflictedChangeAction = conflictAction;
 }
Exemplo n.º 5
0
 public VCContentConflict(ConflictType conflictType, MigrationAction conflictAction, MigrationAction otherSideConflictAction)
     : base(conflictType,
            Status.Unresolved,
            otherSideConflictAction.ActionId.ToString(),
            string.Format("{0};{1}", conflictAction.Path, conflictAction.ChangeGroup.Name))
 {
     ConflictedChangeAction = conflictAction;
 }
 public VCNameSpaceContentConflict(ConflictType conflictType, MigrationAction conflictAction)
     : base(conflictType,
            Status.Unresolved,
            string.Format("{0}", conflictAction.Path),
            string.Format("{0};{1}", conflictAction.Path, conflictAction.ChangeGroup.Name))
 {
     ConflictedChangeAction = conflictAction;
 }
 public VCLabelAlreadyExistsConflict(ConflictType conflictType, MigrationAction conflictAction, string message)
     : base(conflictType,
            Status.Unresolved,
            message,
            string.Empty)
 {
     ConflictedChangeAction = conflictAction;
 }
Exemplo n.º 8
0
 public VCInvalidPathConflict(ConflictType conflictType, MigrationAction conflictAction, string message, string path)
     : base(conflictType,
            Status.Unresolved,
            message,
            path)
 {
     ConflictedChangeAction = conflictAction;
 }
Exemplo n.º 9
0
        private string GenerateMigrationHistoryComment(MigrationAction action)
        {
            ICommentDecorationService commentDecorationService = ServiceContainer.GetService(typeof(ICommentDecorationService)) as ICommentDecorationService;

            Debug.Assert(null != commentDecorationService);
            Debug.Assert(!string.IsNullOrEmpty(action.SourceWorkItemId));
            return(commentDecorationService.GetChangeGroupCommentSuffix(action.SourceWorkItemId));
        }
 /// <summary>
 /// Basic action handler that copy all fields of given action
 /// </summary>
 /// <param name="action"></param>
 /// <param name="group"></param>
 public virtual void BasicActionHandler(MigrationAction action, ChangeGroup group)
 {
     group.CreateAction(action.Action,
                        action.SourceItem,
                        action.FromPath,
                        action.Path, action.Version,
                        action.MergeVersionTo,
                        action.ItemTypeReferenceName,
                        action.MigrationActionDescription);
 }
Exemplo n.º 11
0
        private void FindTargetWorkItemLatestRevision(
            MigrationAction action)
        {
            TargetWorkItem.Reset();
            TargetWorkItem.SyncToLatest();

            XmlDocument desc     = action.RecordDetails.DetailsDocument;
            XmlElement  rootNode = desc.DocumentElement;

            Debug.Assert(null != rootNode);
            rootNode.SetAttribute("TargetRevision", XmlConvert.ToString(TargetWorkItem.Rev));
        }
Exemplo n.º 12
0
 public override void BasicActionHandler(
     MigrationAction deltaTableAction,
     ChangeGroup migrationInstructionChangeGroup)
 {
     migrationInstructionChangeGroup.CreateAction(
         deltaTableAction.Action,
         deltaTableAction.SourceItem,
         deltaTableAction.FromPath,
         deltaTableAction.Path,
         deltaTableAction.Version,
         deltaTableAction.MergeVersionTo,
         deltaTableAction.ItemTypeReferenceName,
         deltaTableAction.MigrationActionDescription);
 }
Exemplo n.º 13
0
        private XmlDocument CreateUpdateOperationDoc(
            MigrationAction action)
        {
            XmlDocument updateDocument = null;

            if (action.ChangeActionId == TfsConstants.ChangeActionId.Add)
            {
                updateDocument = CreateNewWorkItemOperation(action);
            }
            else if (action.ChangeActionId == TfsConstants.ChangeActionId.Edit)
            {
                FindTargetWorkItemLatestRevision(action);
                updateDocument = CreateWorkItemUpdateOperation(action);
            }

            return(updateDocument);
        }
Exemplo n.º 14
0
        public void Should_migrate_using_static_types()
        {
            Action <Person, Person_v1> updater = (p, p1) =>
            {
                var nameSegments = p1.Name.Split(',');
                p.LastName  = nameSegments[0].Trim();
                p.FirstName = nameSegments[1].Trim();

                // shortcut: put the person object in the list
                _persons.Add(p);
            };

            var m = MigrationAction <Person, Person_v1> .AsMerge(updater);

            CommitMigration(m, _store);
            AssertMigrationsSuccessful();
        }
Exemplo n.º 15
0
        private void UpdateConversionHistory(
            MigrationAction action,
            Watermark targetItemWatermark,
            ConversionResult changeResult)
        {
            TargetWorkItemId = int.Parse(targetItemWatermark.Id);
            string sourceWorkItemRevision = GetSourceWorkItemRevision(action);

            // update work item mapping cache
            if (!m_mappedWorkItem.ContainsKey(action.SourceWorkItemId))
            {
                m_mappedWorkItem.Add(action.SourceWorkItemId, TargetWorkItemId);
            }

            // insert conversion history for pushing to db
            changeResult.ItemConversionHistory.Add(
                new ItemConversionHistory(action.SourceWorkItemId, sourceWorkItemRevision, targetItemWatermark.Id,
                                          targetItemWatermark.Revision.ToString()));
            changeResult.ChangeId = targetItemWatermark.Id + ":" + targetItemWatermark.Revision;
        }
        /// <summary>
        /// Basic action handler that copy all fields of given action
        /// </summary>
        /// <param name="action"></param>
        /// <param name="group"></param>
        public override void BasicActionHandler(MigrationAction action, ChangeGroup group)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            group.CreateAction(action.Action,
                               action.SourceItem,
                               action.FromPath,
                               action.Path,
                               action.Version,
                               action.MergeVersionTo,
                               action.ItemTypeReferenceName,
                               action.MigrationActionDescription);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Try to process the change group, assuming it contains context sync instructions.
        /// </summary>
        /// <param name="nextChangeGroup"></param>
        /// <returns>true if the change group is a context sync group and it has been processed (either successfully or not)</returns>
        /// <exception cref="MigrationUnresolvedConflictException"></exception>
        /// <remarks>
        /// If sync succeeds, the change group will be marked as 'Completed'; otherwise, a conflict
        /// will be raised and we do not expect it to be auto-resolved.
        /// </remarks>
        private bool TryProcessContextSyncChangeGroup(ChangeGroup changeGroup)
        {
            // context sync steps must be strictly ordered, although they may not come in expected order
            // the following logic sorts them
            bool foundSyncContextAction = true;

            MigrationAction[] contextSyncActions = new MigrationAction[6];
            foreach (MigrationAction action in changeGroup.Actions)
            {
                if (action.Action.Equals(WellKnownChangeActionId.SyncContext))
                {
                    Debug.Assert(!string.IsNullOrEmpty(action.FromPath));
                    if (action.ItemTypeReferenceName.Equals(WellKnownContentType.UserGroupList.ReferenceName))
                    {
                        contextSyncActions[0] = action;
                    }
                    else if (action.ItemTypeReferenceName.Equals(WellKnownContentType.ValueListCollection.ReferenceName))
                    {
                        contextSyncActions[1] = action;
                    }
                    else if (action.ItemTypeReferenceName.Equals(WellKnownContentType.Tfs2005WorkItemFieldMetadata.ReferenceName) ||
                             action.ItemTypeReferenceName.Equals(WellKnownContentType.Tfs2008WorkItemFieldMetadata.ReferenceName))
                    {
                        contextSyncActions[2] = action;
                    }
                    else if (action.ItemTypeReferenceName.Equals(TfsConstants.TfsAreaPathsContentTypeRefName))
                    {
                        contextSyncActions[3] = action;
                    }
                    else if (action.ItemTypeReferenceName.Equals(TfsConstants.TfsIterationPathsContentTypeRefName))
                    {
                        contextSyncActions[4] = action;
                    }
                    else if (action.ItemTypeReferenceName.Equals(TfsConstants.TfsCSSNodeChangesContentTypeRefName))
                    {
                        contextSyncActions[5] = action;
                    }
                }
                else
                {
                    foundSyncContextAction = false;
                    break;
                }
            }

            if (!foundSyncContextAction)
            {
                return(false);
            }

            IMigrationAction currSyncAction = null;

            try
            {
                if (contextSyncActions[0] != null)
                {
                    currSyncAction = contextSyncActions[0];
                    SyncUserAccount(currSyncAction.MigrationActionDescription, m_witMetadataSyncPolicy);
                }

                if (contextSyncActions[1] != null)
                {
                    currSyncAction = contextSyncActions[1];
                    SyncGlobalList(currSyncAction.MigrationActionDescription, m_witMetadataSyncPolicy);
                }

                if (contextSyncActions[2] != null)
                {
                    currSyncAction = contextSyncActions[2];
                    SyncWorkItemTypeDefinition(currSyncAction.MigrationActionDescription,
                                               m_witMetadataSyncPolicy);
                }

                if (contextSyncActions[3] != null && !m_migrationSource.WorkItemStore.Core.DisableAreaPathAutoCreation)
                {
                    // keep for backward compatibility only (replaced by SyncCSSNodeChanges)
                    currSyncAction = contextSyncActions[3];
                    SyncAreaPaths(currSyncAction.MigrationActionDescription, m_witMetadataSyncPolicy);
                }

                if (contextSyncActions[4] != null && !m_migrationSource.WorkItemStore.Core.DisableIterationPathAutoCreation)
                {
                    // keep for backward compatibility only (replaced by SyncCSSNodeChanges)
                    currSyncAction = contextSyncActions[4];
                    SyncIterationPaths(currSyncAction.MigrationActionDescription, m_witMetadataSyncPolicy);
                }

                if (contextSyncActions[5] != null)
                {
                    currSyncAction = contextSyncActions[5];
                    SyncCSSNodeChanges(
                        currSyncAction.MigrationActionDescription,
                        m_migrationSource.WorkItemStore.Core.DisableAreaPathAutoCreation,
                        m_migrationSource.WorkItemStore.Core.DisableIterationPathAutoCreation);
                }

                changeGroup.Status = ChangeStatus.Complete;
                changeGroup.Save();

                return(true);
            }
            catch (Exception ex)
            {
                if (!(ex is MigrationUnresolvedConflictException))
                {
                    TraceManager.TraceError(ex.ToString());

                    // backlog the conflict context sync action/group
                    MigrationConflict genericeConflict = InvalidSubmissionConflictType.CreateConflict(
                        currSyncAction, ex, currSyncAction.ChangeGroup.Name, currSyncAction.ChangeGroup.Name);
                    var conflictManager = m_conflictManagementService.GetService(typeof(ConflictManager)) as ConflictManager;
                    Debug.Assert(null != conflictManager);
                    List <MigrationAction>   resolutionActions;
                    ConflictResolutionResult resolveRslt =
                        conflictManager.TryResolveNewConflict(conflictManager.SourceId, genericeConflict, out resolutionActions);
                    Debug.Assert(!resolveRslt.Resolved);
                    return(true);
                }
                else
                {
                    throw;
                }
            }
        }
 /// <summary>
 /// Basic action handler that copy all fields of given action
 /// </summary>
 /// <param name="action"></param>
 /// <param name="group"></param>
 public override void BasicActionHandler(MigrationAction action, ChangeGroup group)
 {
     TraceManager.TraceInformation("\tWSSVC:ChangeActionHandler:Basic - {0} - {1}", action.State, group.Name);
     base.BasicActionHandler(action, group);
 }
Exemplo n.º 19
0
 private void cmbAction_SelectedIndexChanged(object sender, EventArgs e)
 {
     _lastAction = (MigrationAction)cmbAction.SelectedItem;
 }
Exemplo n.º 20
0
 private string GenerateMigrationHistoryComment(MigrationAction action)
 {
     return(string.Empty);
 }
Exemplo n.º 21
0
 private void cmbAction_SelectedIndexChanged(object sender, EventArgs e)
 {
     _lastAction = (MigrationAction)cmbAction.SelectedItem;
 }
Exemplo n.º 22
0
 public override void BasicActionHandler(MigrationAction action, ChangeGroup group)
 {
     base.BasicActionHandler(action, group);
 }