public FileMetadata SaveFile(FileDTO file)
        {
            var basePath = @"D:\";
            var chkSum = FileHelper.MD5File(file.FileStream);
            bool isAdd = true;
            var media = _fileMediaRepo.DbSet().Where(c => c.CheckSum == chkSum).FirstOrDefault();
            //复制相同文件重复上次
            if (media == null)
            {
                var relativePath = file.CreatedTime.ToString("yyyyMMdd") + @"\";
                var fullPath = basePath + relativePath + Guid.NewGuid();
                media = FileFactory.CreateFileMeida(file.FileStream, chkSum, fullPath, relativePath);
                _fileMediaRepo.Add(media);
            }
            var metaData = _fileMetadataRepo.DbSet().Where(c => c.Id == file.Id).FirstOrDefault();
            if (metaData == null)
            {
                var extension = file.ResourceName.Substring(file.ResourceName.LastIndexOf("."));
                metaData = FileFactory.CreateFile(
                    file.Id,
                    file.ResourceName,
                    file.CatalogUri,
                    file.CreatedTime,
                    extension,
                    media.Id,
                    file.CreatedTime,
                    file.Owner,
                    file.Owner,
                    file.ResourceSize,
                    file.Propertys
                    );
            }
            else
            {
                isAdd = false;
                metaData.Revision++;
                metaData.LastModifiedTime = file.CreatedTime;
                metaData.LastModifier = file.Owner;
                metaData.ResourceName = file.ResourceName;
                metaData.CatalogUri = file.CatalogUri;
                metaData.Extension = file.ResourceName.Substring(file.ResourceName.LastIndexOf("."));
            }

            var version = new FileVersion
            {
                Remark = "",
                Id = Guid.NewGuid().ToString().ToUpper(),
                ModifiedTime = metaData.LastModifiedTime,
                Modifier = metaData.LastModifier,
                Revision = metaData.Revision,
                FileMetadata = metaData,
                FileId = metaData.Id,
                FileInfor = JsonConvert.SerializeObject(metaData)
            };
            metaData.Versions.Add(version);

            if (isAdd)
            {
                _fileMetadataRepo.Add(metaData);
            }

            var i = _unitOfWork.Commit();

            return metaData;
        }
 public static FileDTO ConvertToFileDTO(this ResoureMessage resoure)
 {
     if (resoure == null)
     {
         return null;
     }
     FileDTO dto = new FileDTO
     {
         CatalogUri = resoure.Catalog,
         CreatedTime = resoure.CreatedTime,
         FileStream = resoure.FileContent,
         Id = resoure.FileId,
         Owner = resoure.Owner,
         ResourceName = resoure.FileName,
         ResourceSize = resoure.FileSize,
         Propertys = new PropertyCollection()
     };
     foreach (var pair in resoure.KeyTags)
     {
         FileMetadataEAVProperty property = new FileMetadataEAVProperty
         {
             FileId = resoure.FileId,
             Name = pair.Key,
             Value = pair.Value
         };
         dto.Propertys.Add(property);
     }
     return dto;
 }
        public FileMetadata CopyFile(string srcFileId, FileDTO dstFile)
        {
            var sourceAttach = _fileMediaRepo.Get(srcFileId).ShouldNotDefault("无法找到ID = {0} 的附件记录", srcFileId);

            if (String.IsNullOrEmpty(dstFile.Id))
            {
                dstFile.Id = Guid.NewGuid().ToString();
            }
            return SaveFile(dstFile);
        }
 public static FileDTO ConvertToFileDTO(this ResoureMetadataDTO metadata)
 {
     if (metadata == null)
     {
         return null;
     }
     FileDTO dto = new FileDTO
     {
         CatalogUri = metadata.Catalog,
         CreatedTime = metadata.CreatedTime,
         Id = metadata.FileId,
         Owner = metadata.Owner,
         ResourceName = metadata.FileName,
         ResourceSize = metadata.FileSize
     };
     foreach (var pair in metadata.KeyTags)
     {
         FileMetadataEAVProperty property = new FileMetadataEAVProperty
         {
             Name = pair.Key,
             Value = pair.Value
         };
     }
     return dto;
 }