Пример #1
0
        private async Task <FileData> GetFileData(IDbConnection connection, IGuidGenerator guidGenerator,
                                                  FileRepository fileRepository, string md5HashString,
                                                  byte[] fileBytes, string fileName, string fileExtension)
        {
            if (!await fileRepository.HasFileWithSameHashAsync(connection, md5HashString))
            {
                var fileId = guidGenerator.GenerateGuid();
                return(new FileData(fileId, true, ImageFormatDetector.GetImageFormat(fileBytes) != ImageFormat.Unknown,
                                    fileBytes, md5HashString, fileBytes.LongLength, fileName, fileExtension));
            }

            var fileDataFromStore = await fileRepository.GetFileByMd5HashAsync(connection, md5HashString);

            return(new FileData(fileDataFromStore.FileId, false,
                                ImageFormatDetector.GetImageFormat(fileDataFromStore.Binary) != ImageFormat.Unknown,
                                fileDataFromStore.Binary, fileDataFromStore.Md5Hash, fileDataFromStore.Size, fileDataFromStore.Name,
                                fileDataFromStore.Extension));
        }