Ejemplo n.º 1
0
        public void SaveFile(FileHeader fileHeader, byte[] content, out ExcutedResult result)
        {
            if (fileHeader.Id == default(Guid))
            {
                fileHeader.Id = Guid.NewGuid();
            }

            fileHeader.Key        = GetKey(content);
            fileHeader.CreateTime = DateTimeOffset.Now;
            fileHeader.State      = 1;

            PreSaveFile(fileHeader.Key, out result);
            if (result.Status == EnumStatus.Success)
            {
                return;
            }

            var file = new File {
                Id = fileHeader.Id, Content = content, ContentType = fileHeader.ContentType
            };

            try
            {
                _fileRepository.Insert(file);
                _fileHeaderRepository.Insert(fileHeader);
                result = ExcutedResult.SuccessResult(FileModel.FileHeaderToModel(fileHeader));
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteError(GetType(), ex);
                result = ExcutedResult.FailedResult(BusinessResultCode.FileSaveFail, "");
            }
        }
Ejemplo n.º 2
0
        public void PreSaveFile(string key, out ExcutedResult result)
        {
            var fileHeader = _fileHeaderRepository.FirstOrDefault(p => p.Key == key);

            if (fileHeader == null)
            {
                result = ExcutedResult.FailedResult(BusinessResultCode.FileNotExistYet, "");
                return;
            }
            result = ExcutedResult.SuccessResult(FileModel.FileHeaderToModel(fileHeader));
        }