public async Task <IEnumerable <JsonPatchOperation> > Process(IMigrationContext migrationContext, IBatchMigrationContext batchContext, WorkItem sourceWorkItem, WorkItem targetWorkItem)
        {
            IList <JsonPatchOperation> jsonPatchOperations = new List <JsonPatchOperation>();

            if (sourceWorkItem.Relations == null)
            {
                return(jsonPatchOperations);
            }

            IEnumerable <WorkItemRelation> sourceAttachmentWorkItemRelations = GetAttachmentWorkItemRelations(sourceWorkItem.Relations);

            if (sourceAttachmentWorkItemRelations.Any())
            {
                foreach (WorkItemRelation sourceAttachmentWorkItemRelation in sourceAttachmentWorkItemRelations)
                {
                    WorkItemRelation targetAttachmentRelation = GetAttachmentIfExistsOnTarget(targetWorkItem, sourceAttachmentWorkItemRelation);

                    if (targetAttachmentRelation != null) // is on target
                    {
                        JsonPatchOperation attachmentAddOperation = MigrationHelpers.GetRelationAddOperation(targetAttachmentRelation);
                        jsonPatchOperations.Add(attachmentAddOperation);
                    }
                    else // is not on target
                    {
                        AttachmentLink attachmentLink = await UploadAttachmentFromSourceRelation(migrationContext, batchContext, sourceWorkItem, sourceAttachmentWorkItemRelation, migrationContext.Config.MaxAttachmentSize);

                        if (attachmentLink != null)
                        {
                            WorkItemRelation newAttachmentWorkItemRelation = new WorkItemRelation();
                            newAttachmentWorkItemRelation.Rel        = sourceAttachmentWorkItemRelation.Rel;
                            newAttachmentWorkItemRelation.Url        = attachmentLink.AttachmentReference.Url;
                            newAttachmentWorkItemRelation.Attributes = new Dictionary <string, object>();
                            newAttachmentWorkItemRelation.Attributes[Constants.RelationAttributeName]         = attachmentLink.FileName;
                            newAttachmentWorkItemRelation.Attributes[Constants.RelationAttributeResourceSize] = attachmentLink.ResourceSize;
                            newAttachmentWorkItemRelation.Attributes[Constants.RelationAttributeComment]      = attachmentLink.Comment;

                            JsonPatchOperation attachmentAddOperation = MigrationHelpers.GetRelationAddOperation(newAttachmentWorkItemRelation);
                            jsonPatchOperations.Add(attachmentAddOperation);
                        }
                    }
                }
            }

            return(jsonPatchOperations);
        }
        public static JsonPatchOperation GetRevisionHistoryAttachmentAddOperation(AttachmentLink attachmentLink, int workItemId)
        {
            JsonPatchOperation jsonPatchOperation = new JsonPatchOperation();

            jsonPatchOperation.Operation = Operation.Add;
            jsonPatchOperation.Path      = $"/{Constants.Relations}/-";
            jsonPatchOperation.Value     = new WorkItemRelation
            {
                Rel        = Constants.AttachedFile,
                Url        = attachmentLink.AttachmentReference.Url,
                Attributes = new Dictionary <string, object>
                {
                    { Constants.RelationAttributeName, attachmentLink.FileName },
                    { Constants.RelationAttributeResourceSize, attachmentLink.ResourceSize },
                    { Constants.RelationAttributeComment, attachmentLink.Comment }
                }
            };

            return(jsonPatchOperation);
        }