Exemple #1
0
        /// <summary>
        /// 保存附件(支持大文件分片传输)
        /// </summary>
        /// <param name="folderId">附件夹主键</param>
        /// <param name="fileGuid">文件主键</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="chunks">文件总共分多少片</param>
        /// <param name="userInfo"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool SaveAnnexes(string folderId, string fileGuid, string fileName, int chunks, UserInfo userInfo, string filePath = "")
        {
            try
            {
                //获取文件完整文件名(包含绝对路径)
                //文件存放路径格式:/Resource/ResourceFile/{userId}/{date}/{guid}.{后缀名}
                string virtualPath    = "";
                string uploadDate     = DateTime.Now.ToString("yyyyMMdd");
                string FileEextension = Path.GetExtension(fileName);
                if (string.IsNullOrEmpty(filePath))
                {
                    filePath    = Config.GetValue("AnnexesFile");
                    virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, FileEextension);
                }
                else
                {
                    virtualPath = string.Format("{0}/{1}", filePath, fileName);
                }
                //创建文件夹
                string path = Path.GetDirectoryName(virtualPath);
                Directory.CreateDirectory(path);
                AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
                if (!System.IO.File.Exists(virtualPath))
                {
                    long filesize = SaveAnnexesToFile(fileGuid, virtualPath, chunks);
                    if (filesize == -1)// 表示保存失败
                    {
                        RemoveChunkAnnexes(fileGuid, chunks);
                        return(false);
                    }
                    //文件信息写入数据库
                    fileAnnexesEntity.F_Id             = fileGuid;
                    fileAnnexesEntity.F_FileName       = fileName;
                    fileAnnexesEntity.F_FilePath       = virtualPath;
                    fileAnnexesEntity.F_FileSize       = filesize.ToString();
                    fileAnnexesEntity.F_FileExtensions = FileEextension;
                    fileAnnexesEntity.F_FileType       = FileEextension.Replace(".", "");
                    fileAnnexesEntity.F_CreateUserId   = userInfo.userId;
                    fileAnnexesEntity.F_CreateUserName = userInfo.realName;


                    SaveEntity(folderId, fileAnnexesEntity);
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 保存数据实体
 /// </summary>
 /// <param name="folderId">附件夹主键</param>
 /// <param name="annexesFileEntity">附件实体数据</param>
 public void SaveEntity(string folderId, AnnexesFileEntity annexesFileEntity)
 {
     try
     {
         annexesFileService.SaveEntity(folderId, annexesFileEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
 /// <summary>
 /// 保存数据实体
 /// </summary>
 /// <param name="folderId">附件夹主键</param>
 /// <param name="annexesFileEntity">附件实体数据</param>
 public void SaveEntity(string folderId, AnnexesFileEntity annexesFileEntity)
 {
     try
     {
         annexesFileEntity.Create();
         annexesFileEntity.F_FolderId = folderId;
         this.BaseRepository().Insert(annexesFileEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// 保存附件(支持大文件分片传输)
 /// </summary>
 /// <param name="fileGuid">文件主键</param>
 /// <param name="fileName">文件名称</param>
 /// <param name="chunks">文件总共分多少片</param>
 /// <param name="fileStream">文件二进制流</param>
 /// <returns></returns>
 public string SaveAnnexes(string fileGuid, string fileName, int chunks)
 {
     try
     {
         UserInfo userInfo = LoginUserInfo.Get();
         //获取文件完整文件名(包含绝对路径)
         //文件存放路径格式:/Resource/ResourceFile/{userId}/{date}/{guid}.{后缀名}
         string filePath       = Config.GetValue("AnnexesFile");
         string uploadDate     = DateTime.Now.ToString("yyyyMMdd");
         string FileEextension = Path.GetExtension(fileName);
         string virtualPath    = string.Format("{0}/{1}/{2}/{3}{4}", filePath, userInfo.userId, uploadDate, fileGuid, FileEextension);
         //创建文件夹
         string path = Path.GetDirectoryName(virtualPath);
         Directory.CreateDirectory(path);
         AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
         if (!System.IO.File.Exists(virtualPath))
         {
             long filesize = SaveAnnexesToFile(fileGuid, virtualPath, chunks);
             if (filesize == -1)// 表示保存失败
             {
                 RemoveChunkAnnexes(fileGuid, chunks);
                 return("");
             }
         }
         return(virtualPath);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }