public async Task Should_invoke_asset_store_to_delete_temporary_file()
        {
            await sut.DeleteAsync("Temp");

            A.CallTo(() => assetStore.DeleteAsync("Temp"))
            .MustHaveHappened();
        }
        public void Should_delete_with_id_and_version()
        {
            sut.DeleteAsync(id, 1, string.Empty);

            A.CallTo(() => sut.DeleteAsync($"{id}_1"))
            .MustHaveHappened();
        }
 private void SetupStore(long version, Guid commitId)
 {
     A.CallTo(() => assetStore.UploadAsync(commitId.ToString(), stream, CancellationToken.None))
     .Returns(TaskHelper.Done);
     A.CallTo(() => assetStore.CopyAsync(commitId.ToString(), assetId.ToString(), version, null, CancellationToken.None))
     .Returns(TaskHelper.Done);
     A.CallTo(() => assetStore.DeleteAsync(commitId.ToString()))
     .Returns(TaskHelper.Done);
 }
        public async Task DeleteAsync(DomainId appId, DomainId id, long fileVersion)
        {
            var fileNameOld = GetFileName(id, fileVersion);
            var fileNameNew = GetFileName(appId, id, fileVersion);

            await Task.WhenAll(
                assetStore.DeleteAsync(fileNameOld),
                assetStore.DeleteAsync(fileNameNew));
        }
Example #5
0
        public async override Task HandleAsync(CommandContext context, Func <Task> next)
        {
            switch (context.Command)
            {
            case CreateAsset createAsset:
            {
                createAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(createAsset.File.OpenRead());

                await assetStore.UploadAsync(context.ContextId.ToString(), createAsset.File.OpenRead());

                try
                {
                    var result = await ExecuteCommandAsync(createAsset) as AssetSavedResult;

                    context.Complete(EntityCreatedResult.Create(createAsset.AssetId, result.Version));

                    await assetStore.CopyAsync(context.ContextId.ToString(), createAsset.AssetId.ToString(), result.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(context.ContextId.ToString());
                }

                break;
            }

            case UpdateAsset updateAsset:
            {
                updateAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(updateAsset.File.OpenRead());

                await assetStore.UploadAsync(context.ContextId.ToString(), updateAsset.File.OpenRead());

                try
                {
                    var result = await ExecuteCommandAsync(updateAsset) as AssetSavedResult;

                    context.Complete(result);

                    await assetStore.CopyAsync(context.ContextId.ToString(), updateAsset.AssetId.ToString(), result.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(context.ContextId.ToString());
                }

                break;
            }

            default:
                await base.HandleAsync(context, next);

                break;
            }
        }
        public async Task Should_invoke_asset_store_to_delete_archive_using_suffix_for_compatibility()
        {
            await sut.DeleteAsync(backupId);

            A.CallTo(() => assetStore.DeleteAsync(fileName))
            .MustHaveHappened();
        }
Example #7
0
        public Task DeleteAsync(DomainId appId, DomainId id, long fileVersion, string?suffix)
        {
            var fileNameOld = GetFileName(id, fileVersion, suffix);
            var fileNameNew = GetFileName(appId, id, fileVersion, suffix);

            if (options.FolderPerApp)
            {
                return(assetStore.DeleteAsync(fileNameNew));
            }
            else
            {
                return(Task.WhenAll(
                           assetStore.DeleteAsync(fileNameOld),
                           assetStore.DeleteAsync(fileNameNew)));
            }
        }
Example #8
0
 private void AssertAssetHasBeenUploaded(long version, Guid commitId)
 {
     A.CallTo(() => assetStore.UploadAsync(commitId.ToString(), stream, CancellationToken.None))
     .MustHaveHappened();
     A.CallTo(() => assetStore.CopyAsync(commitId.ToString(), assetId.ToString(), version, null, CancellationToken.None))
     .MustHaveHappened();
     A.CallTo(() => assetStore.DeleteAsync(commitId.ToString()))
     .MustHaveHappened();
 }
Example #9
0
        private void AssertAssetHasBeenUploaded(long version, Guid commitId)
        {
            var fileName = AssetStoreExtensions.GetFileName(assetId.ToString(), version);

            A.CallTo(() => assetStore.UploadAsync(commitId.ToString(), A <HasherStream> .Ignored, false, CancellationToken.None))
            .MustHaveHappened();
            A.CallTo(() => assetStore.CopyAsync(commitId.ToString(), fileName, CancellationToken.None))
            .MustHaveHappened();
            A.CallTo(() => assetStore.DeleteAsync(commitId.ToString()))
            .MustHaveHappened();
        }
Example #10
0
 public static async Task DeleteAsync(IAssetStore assetStore, string id, ISemanticLog log)
 {
     try
     {
         await assetStore.DeleteAsync(id, 0, null);
     }
     catch (Exception ex)
     {
         log.LogError(ex, id, (logOperationId, w) => w
                      .WriteProperty("action", "deleteBackup")
                      .WriteProperty("status", "failed")
                      .WriteProperty("operationId", logOperationId));
     }
 }
Example #11
0
 private async Task CleanupBackupAsync(BackupStateJob job)
 {
     try
     {
         await assetStore.DeleteAsync(job.Id.ToString(), 0, null);
     }
     catch (Exception ex)
     {
         log.LogError(ex, w => w
                      .WriteProperty("action", "deleteBackup")
                      .WriteProperty("status", "failed")
                      .WriteProperty("backupId", job.Id.ToString()));
     }
 }
        public override async Task HandleAsync(CommandContext context, Func <Task> next)
        {
            switch (context.Command)
            {
            case CreateAsset createAsset:
            {
                if (createAsset.Tags == null)
                {
                    createAsset.Tags = new HashSet <string>();
                }

                createAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(createAsset.File.OpenRead());

                createAsset.FileHash = await UploadAsync(context, createAsset.File);

                try
                {
                    var existings = await assetQuery.QueryByHashAsync(createAsset.AppId.Id, createAsset.FileHash);

                    AssetCreatedResult result = null;

                    foreach (var existing in existings)
                    {
                        if (IsDuplicate(createAsset, existing))
                        {
                            result = new AssetCreatedResult(
                                existing.Id,
                                existing.Tags,
                                existing.Version,
                                existing.FileVersion,
                                existing.FileHash,
                                true);
                        }

                        break;
                    }

                    if (result == null)
                    {
                        foreach (var tagGenerator in tagGenerators)
                        {
                            tagGenerator.GenerateTags(createAsset, createAsset.Tags);
                        }

                        var commandResult = (AssetSavedResult) await ExecuteCommandAsync(createAsset);

                        result = new AssetCreatedResult(
                            createAsset.AssetId,
                            createAsset.Tags,
                            commandResult.Version,
                            commandResult.FileVersion,
                            commandResult.FileHash,
                            false);

                        await assetStore.CopyAsync(context.ContextId.ToString(), createAsset.AssetId.ToString(), result.FileVersion, null);
                    }

                    context.Complete(result);
                }
                finally
                {
                    await assetStore.DeleteAsync(context.ContextId.ToString());
                }

                break;
            }

            case UpdateAsset updateAsset:
            {
                updateAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(updateAsset.File.OpenRead());

                updateAsset.FileHash = await UploadAsync(context, updateAsset.File);

                try
                {
                    var result = (AssetSavedResult) await ExecuteCommandAsync(updateAsset);

                    context.Complete(result);

                    await assetStore.CopyAsync(context.ContextId.ToString(), updateAsset.AssetId.ToString(), result.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(context.ContextId.ToString());
                }

                break;
            }

            default:
                await base.HandleAsync(context, next);

                break;
            }
        }
        public Task DeleteAsync(Guid id, long fileVersion)
        {
            var fileName = GetFileName(id, fileVersion);

            return(assetStore.DeleteAsync(fileName));
        }
 public static Task DeleteAsync(this IAssetStore store, string id, long version, string suffix)
 {
     return(store.DeleteAsync(GetFileName(id, version, suffix)));
 }
Example #15
0
        public Task DeleteAsync(Guid backupId)
        {
            var fileName = GetFileName(backupId);

            return(assetStore.DeleteAsync(fileName));
        }
Example #16
0
        public override async Task HandleAsync(CommandContext context, Func <Task> next)
        {
            var tempFile = context.ContextId.ToString();

            switch (context.Command)
            {
            case CreateAsset createAsset:
            {
                await EnrichWithImageInfosAsync(createAsset);
                await EnrichWithHashAndUploadAsync(createAsset, tempFile);

                try
                {
                    var existings = await assetQuery.QueryByHashAsync(createAsset.AppId.Id, createAsset.FileHash);

                    foreach (var existing in existings)
                    {
                        if (IsDuplicate(existing, createAsset.File))
                        {
                            var result = new AssetCreatedResult(existing, true);

                            context.Complete(result);

                            await next();

                            return;
                        }
                    }

                    GenerateTags(createAsset);

                    await HandleCoreAsync(context, next);

                    var asset = context.Result <IEnrichedAssetEntity>();

                    context.Complete(new AssetCreatedResult(asset, false));

                    await assetStore.CopyAsync(tempFile, createAsset.AssetId.ToString(), asset.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(tempFile);
                }

                break;
            }

            case UpdateAsset updateAsset:
            {
                await EnrichWithImageInfosAsync(updateAsset);
                await EnrichWithHashAndUploadAsync(updateAsset, tempFile);

                try
                {
                    await HandleCoreAsync(context, next);

                    var asset = context.Result <IEnrichedAssetEntity>();

                    await assetStore.CopyAsync(tempFile, updateAsset.AssetId.ToString(), asset.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(tempFile);
                }

                break;
            }

            default:
                await HandleCoreAsync(context, next);

                break;
            }
        }
 public static Task DeleteAsync(this IAssetStore store, Guid id, long version, string suffix)
 {
     return(store.DeleteAsync(id.ToString(), version, suffix));
 }
Example #18
0
        public override async Task HandleAsync(CommandContext context, Func <Task> next)
        {
            switch (context.Command)
            {
            case CreateAsset createAsset:
            {
                if (createAsset.Tags == null)
                {
                    createAsset.Tags = new HashSet <string>();
                }

                createAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(createAsset.File.OpenRead());

                foreach (var tagGenerator in tagGenerators)
                {
                    tagGenerator.GenerateTags(createAsset, createAsset.Tags);
                }

                var originalTags = new HashSet <string>(createAsset.Tags);

                await assetStore.UploadAsync(context.ContextId.ToString(), createAsset.File.OpenRead());

                try
                {
                    var result = await ExecuteCommandAsync(createAsset) as AssetSavedResult;

                    context.Complete(new AssetCreatedResult(createAsset.AssetId, originalTags, result.Version));

                    await assetStore.CopyAsync(context.ContextId.ToString(), createAsset.AssetId.ToString(), result.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(context.ContextId.ToString());
                }

                break;
            }

            case UpdateAsset updateAsset:
            {
                updateAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(updateAsset.File.OpenRead());

                await assetStore.UploadAsync(context.ContextId.ToString(), updateAsset.File.OpenRead());

                try
                {
                    var result = await ExecuteCommandAsync(updateAsset) as AssetSavedResult;

                    context.Complete(result);

                    await assetStore.CopyAsync(context.ContextId.ToString(), updateAsset.AssetId.ToString(), result.FileVersion, null);
                }
                finally
                {
                    await assetStore.DeleteAsync(context.ContextId.ToString());
                }

                break;
            }

            default:
                await base.HandleAsync(context, next);

                break;
            }
        }
Example #19
0
 public Task DeleteAsync(string tempFile,
                         CancellationToken ct = default)
 {
     return(assetStore.DeleteAsync(tempFile, ct));
 }