protected JsonPatchDocument CreateJsonPatchDocumentFromWorkItemFields()

in Common/Migration/Phase1/WitBatchRequestGenerators/BaseWitBatchRequestGenerator.cs [86:129]


        protected JsonPatchDocument CreateJsonPatchDocumentFromWorkItemFields(WorkItem sourceWorkItem)
        {
            string sourceWorkItemType = GetWorkItemTypeFromWorkItem(sourceWorkItem);
            JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();

            IList<string> fieldNamesAlreadyPopulated = new List<string>();

            foreach (var sourceField in sourceWorkItem.Fields)
            {
                if (fieldNamesAlreadyPopulated.Contains(sourceField.Key)) // we have already processed the content for this target field so skip
                {
                    continue;
                }

                if (FieldIsWithinType(sourceField.Key, sourceWorkItemType) && !IsFieldUnsupported(sourceField.Key))
                {
                    KeyValuePair<string, object> fieldProcessedForConfigFields = GetTargetField(sourceField, fieldNamesAlreadyPopulated);
                    KeyValuePair<string, object> preparedField = UpdateProjectNameIfNeededForField(sourceWorkItem, fieldProcessedForConfigFields);
                    
                    // TEMPORARY HACK for handling emoticons in identity fields:
                    if (this.migrationContext.Config.ClearIdentityDisplayNames)
                    {
                        preparedField = RemoveEmojis(sourceField, preparedField);
                    }

                    // add inline image urls
                    JsonPatchOperation jsonPatchOperation;
                    if (this.migrationContext.HtmlFieldReferenceNames.Contains(preparedField.Key) 
                        && preparedField.Value is string)
                    {
                        string updatedHtmlFieldValue = GetUpdatedHtmlField((string)preparedField.Value);
                        KeyValuePair<string, object> updatedField = new KeyValuePair<string, object>(preparedField.Key, updatedHtmlFieldValue);
                        jsonPatchOperation = MigrationHelpers.GetJsonPatchOperationAddForField(updatedField);
                    }
                    else
                    {
                        jsonPatchOperation = MigrationHelpers.GetJsonPatchOperationAddForField(preparedField);
                    }
                    jsonPatchDocument.Add(jsonPatchOperation);
                }
            }

            return jsonPatchDocument;
        }