Exemplo n.º 1
0
        protected override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case CreateAsset createRule:
                return(CreateReturnAsync(createRule, async c =>
                {
                    GuardAsset.CanCreate(c);

                    c.Tags = await tagService.NormalizeTagsAsync(c.AppId.Id, TagGroups.Assets, c.Tags, Snapshot.Tags);

                    Create(c);

                    return new AssetSavedResult(Version, Snapshot.FileVersion);
                }));

            case UpdateAsset updateRule:
                return(UpdateAsync(updateRule, c =>
                {
                    GuardAsset.CanUpdate(c);

                    Update(c);

                    return new AssetSavedResult(Version, Snapshot.FileVersion);
                }));

            case TagAsset tagAsset:
                return(UpdateAsync(tagAsset, async c =>
                {
                    GuardAsset.CanTag(c);

                    c.Tags = await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, c.Tags, Snapshot.Tags);

                    Tag(c);
                }));

            case DeleteAsset deleteAsset:
                return(UpdateAsync(deleteAsset, async c =>
                {
                    GuardAsset.CanDelete(c);

                    await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags);

                    Delete(c);
                }));

            case RenameAsset renameAsset:
                return(UpdateAsync(renameAsset, c =>
                {
                    GuardAsset.CanRename(c, Snapshot.FileName);

                    Rename(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 2
0
        protected override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case CreateAsset createRule:
                return(CreateReturnAsync(createRule, async c =>
                {
                    GuardAsset.CanCreate(c);

                    var tagIds = await NormalizeTagsAsync(c.AppId.Id, c.Tags);

                    Create(c, tagIds);

                    return Snapshot;
                }));

            case UpdateAsset updateRule:
                return(UpdateReturn(updateRule, c =>
                {
                    GuardAsset.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case AnnotateAsset annotateAsset:
                return(UpdateReturnAsync(annotateAsset, async c =>
                {
                    GuardAsset.CanAnnotate(c, Snapshot.FileName, Snapshot.Slug);

                    var tagIds = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags);

                    Annotate(c, tagIds);

                    return Snapshot;
                }));

            case DeleteAsset deleteAsset:
                return(UpdateAsync(deleteAsset, async c =>
                {
                    GuardAsset.CanDelete(c);

                    await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 3
0
        private async Task CreateCore(CreateAsset create)
        {
            GuardAsset.CanCreate(create);

            if (create.Tags != null)
            {
                create.Tags = await NormalizeTagsAsync(create.AppId.Id, create.Tags);
            }

            Create(create);
        }
Exemplo n.º 4
0
        public override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case CreateAsset createRule:
                return(CreateReturnAsync(createRule, c =>
                {
                    GuardAsset.CanCreate(c);

                    Create(c);

                    return new AssetSavedResult(NewVersion, Snapshot.FileVersion);
                }));

            case UpdateAsset updateRule:
                return(UpdateReturnAsync(updateRule, c =>
                {
                    GuardAsset.CanUpdate(c);

                    Update(c);

                    return new AssetSavedResult(NewVersion, Snapshot.FileVersion);
                }));

            case RenameAsset renameAsset:
                return(UpdateAsync(renameAsset, c =>
                {
                    GuardAsset.CanRename(c, Snapshot.FileName);

                    Rename(c);
                }));

            case DeleteAsset deleteAsset:
                return(UpdateAsync(deleteAsset, c =>
                {
                    GuardAsset.CanDelete(c);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 5
0
        protected async Task On(CreateAsset command, CommandContext context)
        {
            command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead());

            try
            {
                var asset = await handler.CreateSyncedAsync <AssetDomainObject>(context, async a =>
                {
                    GuardAsset.CanCreate(command);

                    a.Create(command);

                    await assetStore.UploadTemporaryAsync(context.ContextId.ToString(), command.File.OpenRead());

                    context.Complete(EntityCreatedResult.Create(command.AssetId, a.Version));
                });

                await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), command.AssetId.ToString(), asset.Snapshot.FileVersion, null);
            }
            finally
            {
                await assetStore.DeleteTemporaryAsync(context.ContextId.ToString());
            }
        }
Exemplo n.º 6
0
        public override Task <object?> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotDeleted();

            switch (command)
            {
            case CreateAsset createAsset:
                return(CreateReturnAsync(createAsset, async c =>
                {
                    await GuardAsset.CanCreate(c, assetQuery);

                    var tagIds = await NormalizeTagsAsync(c.AppId.Id, c.Tags);

                    Create(c, tagIds);

                    return Snapshot;
                }));

            case UpdateAsset updateAsset:
                return(UpdateReturn(updateAsset, c =>
                {
                    GuardAsset.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case AnnotateAsset annotateAsset:
                return(UpdateReturnAsync(annotateAsset, async c =>
                {
                    GuardAsset.CanAnnotate(c);

                    var tagIds = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags);

                    Annotate(c, tagIds);

                    return Snapshot;
                }));

            case MoveAsset moveAsset:
                return(UpdateReturnAsync(moveAsset, async c =>
                {
                    await GuardAsset.CanMove(c, assetQuery, Snapshot.ParentId);

                    Move(c);

                    return Snapshot;
                }));

            case DeleteAsset deleteAsset:
                return(UpdateAsync(deleteAsset, async c =>
                {
                    GuardAsset.CanDelete(c);

                    await tagService.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 7
0
        public override Task <object?> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case CreateAsset createAsset:
                return(CreateReturnAsync(createAsset, async c =>
                {
                    await GuardAsset.CanCreate(c, assetQuery);

                    var tagIds = await NormalizeTagsAsync(c.AppId.Id, c.Tags);

                    Create(c, tagIds);

                    return Snapshot;
                }));

            case UpdateAsset updateAsset:
                return(UpdateReturn(updateAsset, c =>
                {
                    GuardAsset.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case AnnotateAsset annotateAsset:
                return(UpdateReturnAsync(annotateAsset, async c =>
                {
                    GuardAsset.CanAnnotate(c);

                    var tagIds = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags);

                    Annotate(c, tagIds);

                    return Snapshot;
                }));

            case MoveAsset moveAsset:
                return(UpdateReturnAsync(moveAsset, async c =>
                {
                    await GuardAsset.CanMove(c, assetQuery, Snapshot.ParentId);

                    Move(c);

                    return Snapshot;
                }));

            case DeleteAsset deleteAsset:
                return(UpdateAsync(deleteAsset, async c =>
                {
                    GuardAsset.CanDelete(c);

                    if (c.CheckReferrers)
                    {
                        var hasReferrer = await contentRepository.HasReferrersAsync(Snapshot.AppId.Id, c.AssetId);

                        if (hasReferrer)
                        {
                            throw new DomainException(T.Get("assets.referenced"));
                        }
                    }

                    await assetTags.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 8
0
        public override Task <object?> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case CreateAsset createAsset:
                return(CreateReturnAsync(createAsset, async c =>
                {
                    await GuardAsset.CanCreate(c, assetQuery);

                    if (c.Tags != null)
                    {
                        c.Tags = await NormalizeTagsAsync(c.AppId.Id, c.Tags);
                    }

                    Create(c);

                    return Snapshot;
                }));

            case AnnotateAsset annotateAsset:
                return(UpdateReturnAsync(annotateAsset, async c =>
                {
                    GuardAsset.CanAnnotate(c);

                    if (c.Tags != null)
                    {
                        c.Tags = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags);
                    }

                    Annotate(c);

                    return Snapshot;
                }));

            case UpdateAsset updateAsset:
                return(UpdateReturn(updateAsset, c =>
                {
                    GuardAsset.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case MoveAsset moveAsset:
                return(UpdateReturnAsync(moveAsset, async c =>
                {
                    await GuardAsset.CanMove(c, Snapshot, assetQuery);

                    Move(c);

                    return Snapshot;
                }));

            case DeleteAsset deleteAsset:
                return(UpdateAsync(deleteAsset, async c =>
                {
                    await GuardAsset.CanDelete(c, Snapshot, contentRepository);

                    await assetTags.NormalizeTagsAsync(Snapshot.AppId.Id, TagGroups.Assets, null, Snapshot.Tags);

                    Delete(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }