Example #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();
            }
        }
Example #2
0
        public void CanDelete_should_not_throw_exception()
        {
            var command = new DeleteAsset {
                AppId = appId
            };

            GuardAsset.CanDelete(command);
        }
Example #3
0
        private async Task DeleteCore(DeleteAsset delete)
        {
            await GuardAsset.CanDelete(delete, Snapshot, contentRepository);

            await NormalizeTagsAsync(Snapshot.AppId.Id, null);

            Delete(delete);
        }
Example #4
0
        public void Delete(DeleteAsset command)
        {
            VerifyNotDeleted();

            RaiseEvent(SimpleMapper.Map(command, new AssetDeleted {
                DeletedSize = Snapshot.TotalSize
            }));
        }
Example #5
0
        public async Task CanDelete_should_not_throw_exception()
        {
            var command = new DeleteAsset {
                AppId = appId
            };

            await GuardAsset.CanDelete(command, Asset(), contentRepository);
        }
Example #6
0
        protected Task On(DeleteAsset command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AssetDomainObject>(context, a =>
            {
                GuardAsset.CanDelete(command);

                a.Delete(command);
            }));
        }
Example #7
0
        /// <summary>
        /// Delete asset by AssetId
        /// </summary>
        /// <param name="AssetId"></param>
        public void DeleteAsset(int AssetId)
        {
            var proc = new DeleteAsset(this.database)
            {
                AssetId = AssetId
            };

            proc.Execute();
        }
Example #8
0
        public object Delete(DeleteAsset request)
        {
            var entity = request.ConvertTo <Asset>();

            return(InTransaction(db =>
            {
                Logic.Remove(entity);
                return new CommonResponse();
            }));
        }
Example #9
0
        public AssetDomainObject Delete(DeleteAsset command)
        {
            VerifyCreatedAndNotDeleted();

            RaiseEvent(SimpleMapper.Map(command, new AssetDeleted {
                DeletedSize = Snapshot.TotalSize
            }));

            return(this);
        }
Example #10
0
        public async Task Delete_should_not_throw_exception_if_referenced_by_other_item_but_forced()
        {
            var command = new DeleteAsset();

            await ExecuteCreateAsync();

            A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id))
            .Returns(true);

            await PublishAsync(command);
        }
        public AssetDomainObject Delete(DeleteAsset command)
        {
            Guard.NotNull(command, nameof(command));

            VerifyCreatedAndNotDeleted();

            RaiseEvent(SimpleMapper.Map(command, new AssetDeleted {
                DeletedSize = totalSize
            }));

            return(this);
        }
Example #12
0
        public async Task CanDelete_should_throw_exception_if_referenced()
        {
            var asset = Asset();

            var command = new DeleteAsset {
                AppId = appId, CheckReferrers = true
            };

            A.CallTo(() => contentRepository.HasReferrersAsync(appId.Id, asset.Id, SearchScope.All))
            .Returns(true);

            await Assert.ThrowsAsync <DomainException>(() => GuardAsset.CanDelete(command, asset, contentRepository));
        }
Example #13
0
        public async Task Delete_should_throw_exception_if_referenced_by_other_item()
        {
            var command = new DeleteAsset {
                CheckReferrers = true
            };

            await ExecuteCreateAsync();

            A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id))
            .Returns(true);

            await Assert.ThrowsAsync <DomainException>(() => PublishAsync(command));
        }
Example #14
0
        public static async Task CanDelete(DeleteAsset command, IAssetEntity asset, IContentRepository contentRepository)
        {
            Guard.NotNull(command, nameof(command));

            if (command.CheckReferrers)
            {
                var hasReferrer = await contentRepository.HasReferrersAsync(asset.AppId.Id, asset.Id, SearchScope.All);

                if (hasReferrer)
                {
                    throw new DomainException(T.Get("assets.referenced"));
                }
            }
        }
Example #15
0
        private async Task DeleteCore(DeleteAsset delete, AssetOperation operation)
        {
            if (delete.CheckReferrers)
            {
                await operation.CheckReferrersAsync();
            }

            if (!delete.DoNotScript)
            {
                await operation.ExecuteDeleteScriptAsync(delete);
            }

            await operation.UnsetTags();

            Delete(delete);
        }
Example #16
0
        public async Task Delete_should_create_events_with_total_file_size()
        {
            var command = new DeleteAsset();

            await ExecuteCreateAsync();
            await ExecuteUpdateAsync();

            var result = await sut.ExecuteAsync(CreateAssetCommand(command));

            result.ShouldBeEquivalent(new EntitySavedResult(2));

            Assert.True(sut.Snapshot.IsDeleted);

            LastEvents
            .ShouldHaveSameEvents(
                CreateAssetEvent(new AssetDeleted {
                DeletedSize = 2048
            })
                );
        }
Example #17
0
        public static Task ExecuteDeleteScriptAsync(this AssetOperation operation, DeleteAsset delete)
        {
            var script = operation.App.AssetScripts?.Delete;

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

            // Script vars are just wrappers over dictionaries for better performance.
            var vars = new AssetScriptVars
            {
                Command = new AssetCommandScriptVars
                {
                    Permanent = delete.Permanent
                },
                Operation = "Delete"
            };

            return(ExecuteScriptAsync(operation, script, vars));
        }
Example #18
0
        public static Task ExecuteDeleteScriptAsync(this AssetOperation operation, DeleteAsset delete)
        {
            var script = operation.App.AssetScripts?.Delete;

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

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

            return(ExecuteScriptAsync(operation, script, vars));
        }
 protected Task On(DeleteAsset command, CommandContext context)
 {
     return(handler.UpdateAsync <AssetDomainObject>(context, c => c.Delete(command)));
 }
Example #20
0
 public static void CanDelete(DeleteAsset command)
 {
     Guard.NotNull(command, nameof(command));
 }
Example #21
0
 private void Delete(DeleteAsset command)
 {
     Raise(command, new AssetDeleted {
         DeletedSize = Snapshot.TotalSize
     });
 }