Ejemplo n.º 1
0
        public void To()
        {
            var items = Directory.CreateDirectory("test").CreateSubdirectory(Guid.NewGuid().ToString());
            var save  = new SaveWorkItems(items);

            save.To(JToken.FromObject(new
            {
                id         = 1,
                workItemId = 12
            }));

            File
            .Exists(Path.Join(items.FullName, "12", "1.json"))
            .Should()
            .BeTrue();
        }
Ejemplo n.º 2
0
        public static async Task Run(string organization,
                                     string token, IEnumerable <string> areas, string output, IProgress <Progress> progress)
        {
            var dir    = Directory.CreateDirectory(output);
            var client = new Client(token);

            await using var context = new MigrationContext(dir.FullName);
            await context.Database.EnsureCreatedAsync();

            var download        = new Download(client);
            var saveWorkItems   = new SaveWorkItems(dir.CreateSubdirectory("items"));
            var saveAttachments = new SaveAttachments(client, dir.CreateSubdirectory("attachments"));

            var totalItems       = 0;
            var totalAttachments = 0;

            await foreach (var update in download.To(organization, areas.ToArray()))
            {
                saveWorkItems.To(update);
                await Save(context, update);

                await foreach (var attachment in saveAttachments.To(update))
                {
                    context.Attachments.Add(new AttachmentMapping {
                        Id = attachment.Id
                    });
                    totalAttachments++;
                }

                totalItems++;

                if (totalItems % 1000 == 0)
                {
                    await context.SaveChangesAsync();
                }

                progress.Report(new Progress {
                    Updates = totalItems, Attachments = totalAttachments
                });
            }

            await context.SaveChangesAsync();
        }