示例#1
0
        private AssetCommand CreateCommandCore(BulkTask task)
        {
            var job = task.CommandJob;

            switch (job.Type)
            {
            case BulkUpdateAssetType.Annotate:
            {
                var command = new AnnotateAsset();

                EnrichAndCheckPermission(task, command, Permissions.AppAssetsUpdate);
                return(command);
            }

            case BulkUpdateAssetType.Move:
            {
                var command = new MoveAsset();

                EnrichAndCheckPermission(task, command, Permissions.AppAssetsUpdate);
                return(command);
            }

            case BulkUpdateAssetType.Delete:
            {
                var command = new DeleteAsset();

                EnrichAndCheckPermission(task, command, Permissions.AppAssetsDelete);
                return(command);
            }

            default:
                throw new NotSupportedException();
            }
        }
示例#2
0
        public async Task CanMove_should_not_throw_exception_when_folder_has_not_changed()
        {
            var command = new MoveAsset {
                AppId = appId, ParentId = DomainId.NewGuid()
            };

            await GuardAsset.CanMove(command, assetQuery, command.ParentId);
        }
示例#3
0
        public async Task CanMove_should_not_throw_exception_when_added_to_root()
        {
            var command = new MoveAsset {
                AppId = appId
            };

            await GuardAsset.CanMove(command, assetQuery, DomainId.NewGuid());
        }
示例#4
0
        public async Task CanMove_should_not_throw_exception_if_added_to_root()
        {
            var command = new MoveAsset {
                AppId = appId
            };

            await GuardAsset.CanMove(command, Asset(), assetQuery);
        }
示例#5
0
        public async Task CanMove_should_throw_exception_when_folder_has_not_changed()
        {
            var command = new MoveAsset {
                ParentId = Guid.NewGuid()
            };

            await ValidationAssert.ThrowsAsync(() => GuardAsset.CanMove(command, assetQuery, command.ParentId),
                                               new ValidationError("Asset is already part of this folder.", "ParentId"));
        }
示例#6
0
        public async Task CanMove_should_not_throw_exception_if_folder_has_not_changed()
        {
            var parentId = DomainId.NewGuid();

            var command = new MoveAsset {
                AppId = appId, ParentId = parentId
            };

            await GuardAsset.CanMove(command, Asset(parentId : parentId), assetQuery);
        }
示例#7
0
        public async Task CanMove_should_throw_exception_when_folder_not_found()
        {
            var command = new MoveAsset {
                AppId = appId, ParentId = DomainId.NewGuid()
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId))
            .Returns(new List <IAssetFolderEntity>());

            await ValidationAssert.ThrowsAsync(() => GuardAsset.CanMove(command, assetQuery, DomainId.NewGuid()),
                                               new ValidationError("Asset folder does not exist.", "ParentId"));
        }
示例#8
0
        public static Task CanMove(MoveAsset command, IAssetQueryService assetQuery, Guid oldParentId)
        {
            Guard.NotNull(command);

            return(Validate.It(() => "Cannot move asset.", async e =>
            {
                if (command.ParentId != oldParentId)
                {
                    await CheckPathAsync(command.ParentId, assetQuery, e);
                }
            }));
        }
示例#9
0
        public static Task CanMove(MoveAsset command, IAssetEntity asset, IAssetQueryService assetQuery)
        {
            Guard.NotNull(command, nameof(command));

            return(Validate.It(async e =>
            {
                if (command.ParentId != asset.ParentId)
                {
                    await CheckPathAsync(command.AppId.Id, command.ParentId, assetQuery, e);
                }
            }));
        }
示例#10
0
        public async Task CanMove_should_not_throw_exception_when_folder_found()
        {
            var command = new MoveAsset {
                AppId = appId, ParentId = DomainId.NewGuid()
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId))
            .Returns(new List <IAssetFolderEntity> {
                CreateFolder()
            });

            await GuardAsset.CanMove(command, assetQuery, DomainId.NewGuid());
        }
示例#11
0
        public async Task CanMove_should_not_throw_exception_if_folder_not_found_but_optimized()
        {
            var parentId = DomainId.NewGuid();

            var command = new MoveAsset {
                AppId = appId, ParentId = parentId, OptimizeValidation = true
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId))
            .Returns(new List <IAssetFolderEntity>());

            await GuardAsset.CanMove(command, Asset(), assetQuery);
        }
示例#12
0
        private async Task MoveCore(MoveAsset move, AssetOperation operation)
        {
            if (!move.OptimizeValidation)
            {
                await operation.MustMoveToValidFolder(move.ParentId);
            }

            if (!move.DoNotScript)
            {
                await operation.ExecuteMoveScriptAsync(move);
            }

            Move(move);
        }
示例#13
0
        public async Task CanMove_should_not_throw_exception_if_folder_found()
        {
            var parentId = DomainId.NewGuid();

            var command = new MoveAsset {
                AppId = appId, ParentId = parentId
            };

            A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, default))
            .Returns(new List <IAssetFolderEntity> {
                AssetFolder()
            });

            await GuardAsset.CanMove(command, Asset(), assetQuery);
        }
示例#14
0
        public static Task CanMove(MoveAsset command, IAssetQueryService assetQuery, Guid oldParentId)
        {
            Guard.NotNull(command);

            return(Validate.It(() => "Cannot move asset.", async e =>
            {
                if (command.ParentId == oldParentId)
                {
                    e("Asset is already part of this folder.", nameof(command.ParentId));
                }
                else
                {
                    await CheckPathAsync(command.ParentId, assetQuery, e);
                }
            }));
        }
示例#15
0
        public static Task CanMove(MoveAsset command, IAssetEntity asset, IAssetQueryService assetQuery)
        {
            Guard.NotNull(command, nameof(command));

            return(Validate.It(async e =>
            {
                var parentId = command.ParentId;

                if (parentId != asset.ParentId && parentId != DomainId.Empty && !command.OptimizeValidation)
                {
                    var path = await assetQuery.FindAssetFolderAsync(command.AppId.Id, parentId);

                    if (path.Count == 0)
                    {
                        e(T.Get("assets.folderNotFound"), nameof(MoveAsset.ParentId));
                    }
                }
            }));
        }
示例#16
0
        public async Task Move_should_create_events_and_update_state()
        {
            var command = new MoveAsset {
                ParentId = parentId
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent2(sut.Snapshot);

            Assert.Equal(parentId, sut.Snapshot.ParentId);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetMoved {
                ParentId = parentId
            })
                );
        }
示例#17
0
        public static async Task ExecuteMoveScriptAsync(this AssetOperation operation, MoveAsset move)
        {
            var script = operation.App.AssetScripts?.Move;

            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }

            var parentPath = await GetPathAsync(operation, move.ParentId);

            var vars = new ScriptVars
            {
                // Use a dictionary for better performance, because no reflection is involved.
                [ScriptKeys.Command] = new Dictionary <string, object?>
                {
                    [ScriptKeys.ParentId]   = move.ParentId,
                    [ScriptKeys.ParentPath] = parentPath
                },
                [ScriptKeys.Operation] = "Move"
            };

            await ExecuteScriptAsync(operation, script, vars);
        }
示例#18
0
        public static async Task ExecuteMoveScriptAsync(this AssetOperation operation, MoveAsset move)
        {
            var script = operation.App.AssetScripts?.Move;

            if (string.IsNullOrWhiteSpace(script))
            {
                return;
            }

            var parentPath = await GetPathAsync(operation, move.ParentId);

            // Script vars are just wrappers over dictionaries for better performance.
            var vars = new AssetScriptVars
            {
                Command = new AssetCommandScriptVars
                {
                    ParentId   = move.ParentId,
                    ParentPath = parentPath
                },
                Operation = "Move"
            };

            await ExecuteScriptAsync(operation, script, vars);
        }
示例#19
0
 private void Move(MoveAsset command)
 {
     Raise(command, new AssetMoved());
 }
示例#20
0
        private async Task MoveCore(MoveAsset move)
        {
            await GuardAsset.CanMove(move, Snapshot, assetQuery);

            Move(move);
        }
示例#21
0
 public void Move(MoveAsset command)
 {
     RaiseEvent(SimpleMapper.Map(command, new AssetMoved()));
 }
示例#22
0
 public void Move(MoveAsset command)
 {
     Raise(command, new AssetMoved());
 }