private void SetupStore(long version, Guid commitId)
 {
     A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream))
     .Returns(TaskHelper.Done);
     A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null))
     .Returns(TaskHelper.Done);
     A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString()))
     .Returns(TaskHelper.Done);
 }
Exemplo n.º 2
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.UploadTemporaryAsync(context.ContextId.ToString(), createAsset.File.OpenRead());

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

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

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

                break;
            }

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

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

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

                    context.Complete(result);

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

                break;
            }

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

                break;
            }
        }
Exemplo n.º 3
0
        protected async Task On(CreateAsset command, CommandContext context)
        {
            command.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(command.File.OpenRead());

            try
            {
                var asset = await handler.CreateAsync <AssetDomainObject>(context, async a =>
                {
                    a.Create(command);

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

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

                await assetStore.CopyTemporaryAsync(context.ContextId.ToString(), asset.Id.ToString(), asset.FileVersion, null);
            }
            finally
            {
                await assetStore.DeleteTemporaryAsync(context.ContextId.ToString());
            }
        }