private void GetCSSNodeId( IMigrationAction action, string workItemType, ref string fieldName, ref string fieldReferenceName, ref string stringVal, ref bool hasIteration, ref bool hasArea) { string fieldNameBeforeConversion = fieldName; string fieldRefNameBeforeConversion = fieldReferenceName; try { if (fieldRefNameBeforeConversion.Equals(CoreFieldReferenceNames.AreaPath)) { // Substitute AreaPath with AreaId fieldName = string.Empty; fieldReferenceName = CoreFieldReferenceNames.AreaId; stringVal = MigrationWorkItemStore.Core.TranslatePath(Node.TreeType.Area, stringVal).ToString(); hasArea = true; } else if (fieldRefNameBeforeConversion.Equals(CoreFieldReferenceNames.IterationPath)) { // Substitute IterationPath with IterationId fieldName = string.Empty; fieldReferenceName = CoreFieldReferenceNames.IterationId; stringVal = MigrationWorkItemStore.Core.TranslatePath(Node.TreeType.Iteration, stringVal).ToString(); hasIteration = true; } } catch (MissingPathException) { WorkItemType wit = MigrationWorkItemStore.GetWorkItemType(workItemType); FieldDefinition fd = wit.FieldDefinitions[fieldNameBeforeConversion]; MigrationConflict conflict = new InvalidFieldValueConflictType().CreateConflict( InvalidFieldValueConflictType.CreateConflictDetails(action.FromPath, action.Version, fd.ReferenceName, fd.Name, string.Empty, stringVal, wit.Project.Name, wit.Name, wit.Store.TeamFoundationServer.Uri.AbsoluteUri), InvalidFieldValueConflictType.CreateScopeHint(wit.Project.Name, wit.Name, fd.ReferenceName), action); var conflictMgrService = MigrationWorkItemStore.ServiceContainer.GetService(typeof(ConflictManager)) as ConflictManager; Debug.Assert(null != conflictMgrService, "cannot get conflict management service."); List <MigrationAction> rsltActions; ConflictResolutionResult result = conflictMgrService.TryResolveNewConflict( conflictMgrService.SourceId, conflict, out rsltActions); if (result.Resolved && result.ResolutionType == ConflictResolutionType.UpdatedConflictedChangeAction) { // extract the mapped value in the action description doc // and apply to the field Debug.Assert(null != conflict.ConflictedChangeAction, "Invalid field value conflict does not contain a conflicted change action."); XmlDocument mappedChangeData = conflict.ConflictedChangeAction.MigrationActionDescription; XmlNode fieldCol = mappedChangeData.SelectSingleNode( string.Format("/WorkItemChanges/Columns/Column[@ReferenceName='{0}']", fd.ReferenceName)); stringVal = fieldCol.FirstChild.InnerText; GetCSSNodeId(action, workItemType, ref fieldNameBeforeConversion, ref fieldNameBeforeConversion, ref stringVal, ref hasIteration, ref hasArea); } else { // we reach here because: // 1. the conflict is not resolved // 2. the conflict resolution action is unknown throw new MigrationUnresolvedConflictException(); } } }
public virtual void AddFields( IMigrationAction action, string workItemType, string author, string changedTime, bool insertWorkItem) { ServerDataIntegrityChecker.InitializeForUpdateAnalysis(workItemType, author); bool hasArea = false; bool hasIteration = false; XmlDocument desc = action.MigrationActionDescription; XmlElement cs = UpdateDocument.CreateElement("Columns"); UpdateDocument.FirstChild.AppendChild(cs); XmlNodeList columns = desc.SelectNodes("/WorkItemChanges/Columns/Column"); if (null == columns) { throw new MigrationException(TfsWITAdapterResources.ErrorInvalidActionDescription, action.ActionId); } foreach (XmlNode columnData in columns) { string fieldName = columnData.Attributes["DisplayName"].Value; string fieldReferenceName = columnData.Attributes["ReferenceName"].Value; string stringVal = columnData.FirstChild.InnerText; string fieldType = columnData.Attributes["Type"].Value; if (fieldReferenceName.Equals(CoreFieldReferenceNames.AreaPath) || fieldReferenceName.Equals(CoreFieldReferenceNames.IterationPath)) { GetCSSNodeId(action, workItemType, ref fieldName, ref fieldReferenceName, ref stringVal, ref hasIteration, ref hasArea);; } while (true) { try { AddColumn(cs, workItemType, fieldName, fieldReferenceName, stringVal); break; } catch (FieldNotExistException) { string sourceItemId = TfsMigrationWorkItemStore.GetSourceWorkItemId(action); string sourceItemRevision = TfsMigrationWorkItemStore.GetSourceWorkItemRevision(action); WorkItemType wit = MigrationWorkItemStore.GetWorkItemType(workItemType); MigrationConflict conflict = new InvalidFieldConflictType().CreateConflict( InvalidFieldConflictType.CreateConflictDetails(sourceItemId, sourceItemRevision, fieldReferenceName, wit), InvalidFieldConflictType.CreateScopeHint(wit.Project.Name, wit.Name), action); var conflictMgrService = MigrationWorkItemStore.ServiceContainer.GetService(typeof(ConflictManager)) as ConflictManager; Debug.Assert(null != conflictMgrService, "cannot get conflict management service."); List <MigrationAction> actions; ConflictResolutionResult resolutionRslt = conflictMgrService.TryResolveNewConflict(conflictMgrService.SourceId, conflict, out actions); if (!resolutionRslt.Resolved) { throw new MigrationUnresolvedConflictException(); } if (resolutionRslt.ResolutionType == ConflictResolutionType.UpdatedConflictedChangeAction) { XmlDocument migrationDesc = conflict.ConflictedChangeAction.MigrationActionDescription; XmlNode column = migrationDesc.SelectSingleNode(string.Format( @"/WorkItemChanges/Columns/Column[@ReferenceName=""{0}""]", fieldReferenceName)); if (null == column) { // field has been dropped by the resolution rule break; } fieldReferenceName = column.Attributes["ReferenceName"].Value; fieldName = string.Empty; } else { // unrecognized resolution action was taken throw new MigrationUnresolvedConflictException(); } } } } if (insertWorkItem) { //if (!hasArea && !ByPassrules) if (!hasArea) { AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.AreaId, MigrationWorkItemStore.Core.DefaultAreaId.ToString()); } //if (!hasIteration && !ByPassrules) if (!hasIteration) { AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.IterationId, MigrationWorkItemStore.Core.DefaultIterationId.ToString()); } AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.WorkItemType, workItemType); AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.CreatedDate, string.Empty); AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.CreatedBy, author); AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.ChangedBy, author); foreach (string missingField in ServerDataIntegrityChecker.MissingFields) { AddColumn(cs, workItemType, string.Empty, missingField, ServerDataIntegrityChecker[missingField]); } } else { AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.ChangedBy, author); } }