Exemple #1
0
        private async Task ProcessInlineImagesForHtmlField(IBatchMigrationContext batchContext, int sourceWorkItemId, KeyValuePair <string, object> field)
        {
            // we are assuming that this will always be a string, so log if it is not
            if (!(field.Value is string))
            {
                Logger.LogWarning(LogDestination.File, $"Unexpected value for html field {field.Key} for source work item {sourceWorkItemId}");
            }

            string           fieldHtmlContent = field.Value as string;
            HashSet <string> inlineImageUrls  = MigrationHelpers.GetInlineImageUrlsFromField(fieldHtmlContent, this.context.SourceClient.Connection.Uri.AbsoluteUri);

            foreach (string inlineImageUrl in inlineImageUrls)
            {
                // There are scenarios where someone copy/pastes image from one work item to another and the
                // it ends up using the same inline attachment link.
                if (!batchContext.SourceInlineImageUrlToTargetInlineImageGuid.ContainsKey(inlineImageUrl))
                {
                    string targetGuid = await UploadInlineImageAttachmentFromSourceWorkItemToTarget(batchContext, inlineImageUrl, sourceWorkItemId, context.Config.MaxAttachmentSize);

                    if (!String.IsNullOrEmpty(targetGuid))
                    {
                        batchContext.SourceInlineImageUrlToTargetInlineImageGuid.Add(inlineImageUrl, targetGuid);
                    }
                }
            }
        }
        private async Task ProcessInlineImagesForHtmlField(IBatchMigrationContext batchContext, int sourceWorkItemId, KeyValuePair <string, object> field)
        {
            string           fieldHtmlContent = (string)field.Value; // we are assuming that this will always be convertable to string
            HashSet <string> inlineImageUrls  = MigrationHelpers.GetInlineImageUrlsFromField(fieldHtmlContent, this.context.SourceClient.Connection.Uri.AbsoluteUri);

            foreach (string inlineImageUrl in inlineImageUrls)
            {
                // There are scenarios where someone copy/pastes image from one work item to another and the
                // it ends up using the same inline attachment link.
                if (!batchContext.SourceInlineImageUrlToTargetInlineImageGuid.ContainsKey(inlineImageUrl))
                {
                    string targetGuid = await UploadInlineImageAttachmentFromSourceWorkItemToTarget(batchContext, inlineImageUrl, sourceWorkItemId, context.Config.MaxAttachmentSize);

                    if (!String.IsNullOrEmpty(targetGuid))
                    {
                        batchContext.SourceInlineImageUrlToTargetInlineImageGuid.Add(inlineImageUrl, targetGuid);
                    }
                }
            }
        }