Beispiel #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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
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();
            }
        }
Beispiel #4
0
        protected async Task On(UpdateAsset command, CommandContext context)
        {
            command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead());

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

                    a.Update(command);

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

                    context.Complete(new AssetSavedResult(a.Version, a.Snapshot.FileVersion));
                });

                await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), command.AssetId.ToString(), asset.Snapshot.FileVersion, null);
            }
            finally
            {
                await assetStore.DeleteTemporaryAsync(context.ContextId.ToString());
            }
        }
        private void UpdateCore(UpdateAsset update)
        {
            GuardAsset.CanUpdate(update);

            Update(update);
        }
        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();
            }
        }
Beispiel #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();
            }
        }
Beispiel #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();
            }
        }