public TfsWITDSyncer( XmlDocument witd, TfsMigrationWorkItemStore migrationWITStore) { if (null == witd) { throw new ArgumentNullException("witd"); } if (null == migrationWITStore) { throw new ArgumentNullException("migrationWITStore"); } WITD = witd; MigrationWITStore = migrationWITStore; }
public void DetectConflicts(ChangeGroup group) { TfsMigrationWorkItemStore store = m_migrationSource.WorkItemStore; Debug.Assert(null != store, "store is NULL"); if (!store.ByPassrules) { foreach (IMigrationAction action in group.Actions) { if (action.State == ActionState.Skipped) { continue; } // Try apply changes if (action.MigrationActionDescription == null || action.MigrationActionDescription.DocumentElement == null) { throw new MigrationException(TfsWITAdapterResources.ErrorInvalidActionDescription, action.ActionId); } if (action.Action == WellKnownChangeActionId.Add) { var workItem = store.CreateNewWorkItem(action, m_conflictManagerService); store.TryApplyWitDataChanges(action, workItem, true, m_configurationService.MigrationPeer, m_conflictManagerService); } else if (action.Action == WellKnownChangeActionId.Edit) { // check if work item is in backlog only; if it is, this revision will be backlogged automatically store.IsSourceWorkItemInBacklog(m_conflictManagerService, action); } else { // skip detecting attachment-related conflicts continue; } } } }
public TfsUpdateDocument(TfsMigrationWorkItemStore tfsMigrationWorkItemStore) { MigrationWorkItemStore = tfsMigrationWorkItemStore; ByPassrules = MigrationWorkItemStore.ByPassrules; ServerDataIntegrityChecker = new TfsServerDataIntegrityChecker(); }
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); } }