Beispiel #1
0
        private async Task <AttachmentReference> UploadAttachmentsToTarget(IMigrationContext migrationContext, WorkItem sourceWorkItem)
        {
            RevisionHistoryAttachments revisionHistoryAttachmentsItem = await GetWorkItemUpdates(migrationContext, sourceWorkItem);

            string attachment = JsonConvert.SerializeObject(revisionHistoryAttachmentsItem.Updates);
            AttachmentReference aRef;

            using (MemoryStream stream = new MemoryStream())
            {
                var stringBytes = System.Text.Encoding.UTF8.GetBytes(attachment);
                await stream.WriteAsync(stringBytes, 0, stringBytes.Length);

                stream.Position = 0;
                //upload the attachment to the target for each workitem
                aRef = await WorkItemTrackingHelpers.CreateAttachmentAsync(migrationContext.TargetClient.WorkItemTrackingHttpClient, stream);
            }

            return(aRef);
        }
Beispiel #2
0
        private async Task <IList <AttachmentLink> > UploadAttachmentsToTarget(IMigrationContext migrationContext, WorkItem sourceWorkItem)
        {
            var attachmentLinks = new List <AttachmentLink>();
            int updateLimit     = migrationContext.Config.MoveHistoryLimit;
            int updateCount     = 0;

            while (updateCount < updateLimit)
            {
                var updates = await GetWorkItemUpdates(migrationContext, sourceWorkItem, skip : updateCount);

                string attachmentContent = JsonConvert.SerializeObject(updates);
                AttachmentReference attachmentReference;
                using (MemoryStream stream = new MemoryStream())
                {
                    var stringBytes = System.Text.Encoding.UTF8.GetBytes(attachmentContent);
                    await stream.WriteAsync(stringBytes, 0, stringBytes.Length);

                    stream.Position = 0;
                    //upload the attachment to the target for each batch of workitem updates
                    attachmentReference = await WorkItemTrackingHelpers.CreateAttachmentAsync(migrationContext.TargetClient.WorkItemTrackingHttpClient, stream);

                    attachmentLinks.Add(
                        new AttachmentLink(
                            $"{Constants.WorkItemHistory}-{sourceWorkItem.Id}-{updateCount}.json",
                            attachmentReference,
                            stringBytes.Length,
                            comment: $"Update range from {updateCount} to {updateCount + updates.Count}"));
                }

                updateCount += updates.Count;

                // if we got less than a page size, that means we're on the last
                // page and shouldn't try and read another page.
                if (updates.Count < Constants.PageSize)
                {
                    break;
                }
            }

            return(attachmentLinks);
        }