예제 #1
0
 public static AssetCreatedDto FromCommand(CreateAsset command, AssetCreatedResult result)
 {
     return(new AssetCreatedDto
     {
         Id = result.IdOrValue,
         FileName = command.File.FileName,
         FileSize = command.File.FileSize,
         FileType = command.File.FileName.FileType(),
         FileVersion = result.FileVersion,
         MimeType = command.File.MimeType,
         IsImage = command.ImageInfo != null,
         IsDuplicate = result.IsDuplicate,
         PixelWidth = command.ImageInfo?.PixelWidth,
         PixelHeight = command.ImageInfo?.PixelHeight,
         Tags = result.Tags,
         Version = result.Version
     });
 }
예제 #2
0
        public static AssetCreatedDto FromCommand(CreateAsset command, AssetCreatedResult result)
        {
            var response = new AssetCreatedDto
            {
                Id          = command.AssetId,
                FileName    = command.File.FileName,
                FileSize    = command.File.FileSize,
                FileType    = command.File.FileName.FileType(),
                FileVersion = result.Version,
                MimeType    = command.File.MimeType,
                IsImage     = command.ImageInfo != null,
                PixelWidth  = command.ImageInfo?.PixelWidth,
                PixelHeight = command.ImageInfo?.PixelHeight,
                Tags        = result.Tags,
                Version     = result.Version
            };

            return(response);
        }
예제 #3
0
        public override async Task HandleAsync(CommandContext context, NextDelegate next)
        {
            var tempFile = context.ContextId.ToString();

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

                    if (!createAsset.Duplicate)
                    {
                        var existing =
                            await assetQuery.FindByHashAsync(contextProvider.Context,
                                                             createAsset.FileHash,
                                                             createAsset.File.FileName,
                                                             createAsset.File.FileSize);

                        if (existing != null)
                        {
                            var result = new AssetCreatedResult(existing, true);

                            context.Complete(result);

                            await next(context);

                            return;
                        }
                    }

                    await UploadAsync(context, tempFile, createAsset, createAsset.Tags, true, next);
                }
                finally
                {
                    await assetFileStore.DeleteAsync(tempFile);

                    createAsset.File.Dispose();
                }

                break;
            }

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

                    await UploadAsync(context, tempFile, updateAsset, null, false, next);
                }
                finally
                {
                    await assetFileStore.DeleteAsync(tempFile);

                    updateAsset.File.Dispose();
                }

                break;
            }

            default:
                await HandleCoreAsync(context, false, next);

                break;
            }
        }