protected KeyValuePair CreateTargetField()

in Common/Migration/Phase1/WitBatchRequestGenerators/BaseWitBatchRequestGenerator.cs [246:291]


        protected KeyValuePair<string, object> CreateTargetField(WorkItem sourceWorkItem, KeyValuePair<string, object> sourceField)
        {
            KeyValuePair<string, object> targetField;
            string targetProject = this.migrationContext.Config.TargetConnection.Project;
            string sourceProject = this.migrationContext.Config.SourceConnection.Project;

            string defaultAreaPath = string.IsNullOrEmpty(this.migrationContext.Config.DefaultAreaPath) ? targetProject : this.migrationContext.Config.DefaultAreaPath;
            string defaultIterationPath = string.IsNullOrEmpty(this.migrationContext.Config.DefaultIterationPath) ? targetProject : this.migrationContext.Config.DefaultIterationPath;

            // Make sure the new area path and iteration path exist on target before assigning them.
            // Otherwise assign targetProject
            if (sourceField.Key.Equals(FieldNames.AreaPath, StringComparison.OrdinalIgnoreCase))
            {
                string targetPathName = GetTargetPathName(sourceField.Value as string, sourceProject, targetProject);

                if (ExistsInTargetAreaPathList(targetPathName))
                {
                    targetField = new KeyValuePair<string, object>(sourceField.Key, targetPathName);
                }
                else
                {
                    targetField = new KeyValuePair<string, object>(sourceField.Key, defaultAreaPath);
                    Logger.LogWarning(LogDestination.File, $"Could not find corresponding AreaPath: {targetPathName} on target. Assigning the AreaPath: {defaultAreaPath} on source work item with Id: {sourceWorkItem.Id}.");
                }
            }
            else if (sourceField.Key.Equals(FieldNames.IterationPath, StringComparison.OrdinalIgnoreCase))
            {
                string targetPathName = GetTargetPathName(sourceField.Value as string, sourceProject, targetProject);

                if (ExistsInTargetIterationPathList(targetPathName))
                {
                    targetField = new KeyValuePair<string, object>(sourceField.Key, targetPathName);
                }
                else
                {
                    targetField = new KeyValuePair<string, object>(sourceField.Key, defaultIterationPath);
                    Logger.LogWarning(LogDestination.File, $"Could not find corresponding IterationPath: {targetPathName} on target. Assigning the IterationPath: {defaultIterationPath} on source work item with Id: {sourceWorkItem.Id}.");
                }
            }
            else if (sourceField.Key.Equals(FieldNames.TeamProject, StringComparison.OrdinalIgnoreCase))
            {
                targetField = new KeyValuePair<string, object>(sourceField.Key, targetProject);
            }

            return targetField;
        }