private void GetCSSNodeId( Hist.MigrationAction action, string workItemType, ref string fieldName, ref string fieldReferenceName, ref string stringVal, ref bool hasIteration, ref bool hasArea) { string fieldNameBeforeConversion = fieldName; string fieldRefNameBeforeConversion = fieldReferenceName; 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; } }
internal void AddFields( Hist.MigrationAction action, string workItemType, string author, string changedTime, bool insertWorkItem) { bool hasArea = false; bool hasIteration = false; XmlDocument desc = action.RecordDetails.DetailsDocument; XmlElement cs = UpdateDocument.CreateElement("Columns"); UpdateDocument.FirstChild.AppendChild(cs); XmlNodeList columns = desc.SelectNodes("/WorkItemChanges/Columns/Column"); 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)) { try { GetCSSNodeId(action, workItemType, ref fieldName, ref fieldReferenceName, ref stringVal, ref hasIteration, ref hasArea);; } catch (Exception ex) { TraceManager.TraceError(ex.ToString()); continue; } } AddColumn(cs, workItemType, fieldName, fieldReferenceName, stringVal); } if (insertWorkItem) { if (!hasArea) //if (!hasArea && !ByPassrules) { AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.AreaId, MigrationWorkItemStore.Core.DefaultAreaId.ToString()); } if (!hasIteration) //if (!hasIteration && !ByPassrules) { 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); } else { AddColumn(cs, workItemType, string.Empty, CoreFieldReferenceNames.ChangedBy, author); } }
private ConflictResolutionResult ResolveBySubmitMissingChanges( IServiceContainer serviceContainer, MigrationConflict conflict, ConflictResolutionRule rule, out List <MigrationAction> actions) { actions = null; var retVal = new ConflictResolutionResult(false, ConflictResolutionType.Other); WITTranslationService translationService = serviceContainer.GetService(typeof(ITranslationService)) as WITTranslationService; Debug.Assert(null != translationService, "translationService is not initialized or not a wit translation service"); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTSessionGroup rtSessionGroup = FindSessionGroupForConflictedAction(conflict, context); if (null == rtSessionGroup) { return(retVal); } BM.BusinessModelManager bmm = new BM.BusinessModelManager(); BM.Configuration sessionGroupConfig = bmm.LoadConfiguration(rtSessionGroup.GroupUniqueId); // find target-side migration source config var parentChangeGroup = FindChangeGroupForConflictedAction(conflict, context); Guid targetMigrationSourceId = parentChangeGroup.SourceUniqueId; BM.MigrationSource targetMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[targetMigrationSourceId]; if (null == targetMigrationSourceConfig) { return(retVal); } // find source-side migration source config RTSession rtSession = FindSessionForConflictedAction(conflict, context); BM.Session parentSession = null; foreach (BM.Session s in sessionGroupConfig.SessionGroup.Sessions.Session) { if (new Guid(s.SessionUniqueId).Equals(rtSession.SessionUniqueId)) { parentSession = s; break; } } if (parentSession == null) { return(retVal); } Guid sourceMigrationSourceId = ((new Guid(parentSession.LeftMigrationSourceUniqueId)).Equals(targetMigrationSourceId)) ? new Guid(parentSession.RightMigrationSourceUniqueId) : new Guid(parentSession.LeftMigrationSourceUniqueId); BM.MigrationSource sourceMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[sourceMigrationSourceId]; if (null == sourceMigrationSourceConfig) { return(retVal); } string sourceServerUrl = sourceMigrationSourceConfig.ServerUrl; string sourceTeamProject = sourceMigrationSourceConfig.SourceIdentifier; string targetServerUrl = targetMigrationSourceConfig.ServerUrl; string targetTeamProject = targetMigrationSourceConfig.SourceIdentifier; string srcWorkItemIdStr = TfsMigrationWorkItemStore.GetSourceWorkItemId(conflict.ConflictedChangeAction); Debug.Assert(!string.IsNullOrEmpty(srcWorkItemIdStr), "srcWorkItemId is null or empty"); int srcWorkItemId; if (!int.TryParse(srcWorkItemIdStr, out srcWorkItemId)) { return(retVal); } string srcRevRanges = rule.DataFieldDictionary[HistoryNotFoundSubmitMissingChangesAction.DATAKEY_REVISION_RANGE]; int[] sourceRevToSync = new int[0]; if (string.IsNullOrEmpty(srcRevRanges)) { sourceRevToSync = ExtractMissingRevs(conflict.ConflictedChangeAction); } else { if (!IntegerRange.TryParseRangeString(srcRevRanges, out sourceRevToSync)) { return(retVal); } } if (sourceRevToSync.Length == 0) { return(retVal); } try { // compute delta from source side TfsWITAnalysisProvider analysisProvider = new TfsWITAnalysisProvider(sourceServerUrl, sourceTeamProject); WorkItem sourceWorkItem = analysisProvider.GetWorkItem(srcWorkItemId); Hist.MigrationAction[] sourceRevDetails = new Hist.MigrationAction[sourceRevToSync.Length]; for (int revIndex = 0; revIndex < sourceRevToSync.Length; ++revIndex) { var details = new TfsWITRecordDetails(sourceWorkItem, sourceRevToSync[revIndex]); SanitizeDetails(details); translationService.MapWorkItemTypeFieldValues( sourceWorkItem.Id.ToString(), details.DetailsDocument, sourceMigrationSourceId); TfsConstants.ChangeActionId actionId = (sourceRevToSync[revIndex] == 1 ? TfsConstants.ChangeActionId.Add : TfsConstants.ChangeActionId.Edit); sourceRevDetails[revIndex] = new Hist.MigrationAction(sourceWorkItem.Id.ToString(), details, actionId); } // migrate to target side TfsWITMigrationProvider migrationProvider = new TfsWITMigrationProvider(targetServerUrl, targetTeamProject, string.Empty); Hist.ConversionResult conversionResult = migrationProvider.ProcessChangeGroup(sourceRevDetails); // update conversion history ConversionResult convRslt = new ConversionResult(sourceMigrationSourceId, targetMigrationSourceId); convRslt.ChangeId = HistoryNotFoundResolutionChangeId; convRslt.ContinueProcessing = true; foreach (var itemConvHist in conversionResult.ItemConversionHistory) { convRslt.ItemConversionHistory.Add(new ItemConversionHistory( itemConvHist.SourceItemId, itemConvHist.SourceItemVersion, itemConvHist.TargetItemId, itemConvHist.TargetItemVersion)); } parentChangeGroup.SessionRunReference.Load(); int sessionRunId = parentChangeGroup.SessionRun.Id; convRslt.Save(sessionRunId, sourceMigrationSourceId); } catch (Exception ex) { TraceManager.TraceException(ex); retVal.Comment = ex.ToString(); return(retVal); } } retVal.Resolved = true; return(retVal); }