コード例 #1
0
        public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession session)
        {
            var models =
                GetFiles(sync.FileSystem)
                .Select(x => (x, sync.Read <AssetsModel>(x, log)));

            var batchIndex = 0;

            foreach (var(_, model) in models)
            {
                if (model?.Assets?.Count > 0)
                {
                    var uploader = new UploadPipeline(session, log, sync.FileSystem)
                    {
                        FilePathProvider = asset => asset.Id.GetBlobPath()
                    };

                    try
                    {
                        foreach (var asset in model.Assets)
                        {
                            await uploader.UploadAsync(asset);
                        }
                    }
                    finally
                    {
                        await uploader.CompleteAsync();
                    }

                    var request = new BulkUpdateAssetsDto();

                    foreach (var asset in model.Assets)
                    {
                        var parentId = await sync.Folders.GetIdAsync(asset.FolderPath);

                        request.Jobs.Add(asset.ToMove(parentId));
                        request.Jobs.Add(asset.ToAnnotate());
                    }

                    var assetIndex = 0;

                    var results = await session.Assets.BulkUpdateAssetsAsync(session.App, request);

                    foreach (var asset in model.Assets)
                    {
                        // We create wo commands per asset.
                        var result1 = results.FirstOrDefault(x => x.JobIndex == (assetIndex * 2));
                        var result2 = results.FirstOrDefault(x => x.JobIndex == (assetIndex * 2) + 1);

                        log.StepStart($"Upserting #{batchIndex}/{assetIndex}");

                        if (result1?.Error != null)
                        {
                            log.StepFailed(result1.Error.ToString());
                        }
                        else if (result2?.Error != null)
                        {
                            log.StepFailed(result2.Error.ToString());
                        }
                        else if (result1?.Id != null && result2?.Id != null)
                        {
                            log.StepSuccess();
                        }
                        else
                        {
                            log.StepSkipped("Unknown Reason");
                        }

                        assetIndex++;
                    }
                }

                batchIndex++;
            }
        }
コード例 #2
0
        public async Task ImportAsync(DirectoryInfo directoryInfo, JsonHelper jsonHelper, SyncOptions options, ISession session)
        {
            var models =
                GetFiles(directoryInfo)
                .Select(x => (x, jsonHelper.Read <AssetsModel>(x, log)));

            var tree = new FolderTree(session);

            foreach (var(_, model) in models)
            {
                if (model?.Assets?.Count > 0)
                {
                    var uploader = new UploadPipeline(session, log, directoryInfo);

                    await uploader.UploadAsync(model.Assets);

                    await uploader.CompleteAsync();

                    var request = new BulkUpdateAssetsDto();

                    foreach (var asset in model.Assets)
                    {
                        var parentId = await tree.GetIdAsync(asset.FolderPath);

                        request.Jobs.Add(asset.ToMoveJob(parentId));
                        request.Jobs.Add(asset.ToAnnotateJob());
                    }

                    var assetIndex = 0;

                    var results = await session.Assets.BulkUpdateAssetsAsync(session.App, request);

                    foreach (var asset in model.Assets)
                    {
                        // We create wo commands per asset.
                        var result1 = results.FirstOrDefault(x => x.JobIndex == (assetIndex * 2));
                        var result2 = results.FirstOrDefault(x => x.JobIndex == (assetIndex * 2) + 1);

                        log.StepStart($"Upserting #{assetIndex}");

                        if (result1?.Error != null)
                        {
                            log.StepFailed(result1.Error.ToString());
                        }
                        else if (result2?.Error != null)
                        {
                            log.StepFailed(result2.Error.ToString());
                        }
                        else if (result1?.Id != null && result2.Id != null)
                        {
                            log.StepSuccess();
                        }
                        else
                        {
                            log.StepSkipped("Unknown Reason");
                        }

                        assetIndex++;
                    }
                }
            }
        }