/// <summary>
        /// 取得實體存放資料筆數 By SourceId
        /// </summary>
        /// <param name="storageSourceType">檔案來源類別</param>
        /// <param name="sourceId">來源項目的Id</param>
        /// <returns>實體存放資料清單筆數</returns>
        public int CountStorageFileListBySourceId(StorageFileVO.StorageSourceType storageSourceType, int sourceId)
        {
            DetachedCriteria dCriteria = DetachedCriteria.For<StorageFileVO>();
            dCriteria.Add(Expression.Eq("SourceType", (int)storageSourceType));
            dCriteria.Add(Expression.Eq("SourceId", sourceId));

            return NHibernateDao.CountByDetachedCriteria(dCriteria);
        }
 /// <summary>
 /// 刪除實體存放資料 By SourceId
 /// </summary>
 /// <param name="storageSourceType">檔案來源類別</param>
 /// <param name="sourceId">來源項目的Id</param>
 public void DeleteStorageFileBySourceId(StorageFileVO.StorageSourceType storageSourceType, int sourceId)
 {
     IList<StorageFileVO> storageFileList = GetStorageFileList(storageSourceType, sourceId);
     if (storageFileList != null && storageFileList.Count > 0)
     {
         for (int i = 0; i < storageFileList.Count; i++)
         {
             DeleteStorageFile(storageFileList[i]);
         }
     }
 }
        /// <summary>
        /// 新增實體存放資料
        /// </summary>
        /// <param name="storageFileVO">被新增的實體存放資料</param>
        /// <returns>新增後的實體存放資料</returns>
        public StorageFileVO CreateStorageFile(StorageFileVO storageFileVO)
        {
            //檔案搬移到public資料夾
            storageFileVO = StorageHelper.RemoveStorageFile(FolderType.PUBLIC_FOLDER, storageFileVO);
            storageFileVO.IsTemporary = false;

            storageFileVO = StorageFileDao.CreateStorageFile(storageFileVO);
            if (storageFileVO.SortNo == 0)
            {
                storageFileVO.SortNo = storageFileVO.StorageFileId;
                storageFileVO = StorageFileDao.UpdateStorageFile(storageFileVO);
            }
            return storageFileVO;
        }
        /// <summary>
        /// 取得取得實體存放資料清單
        /// </summary>
        /// <param name="storageSourceType">檔案來源類別</param>
        /// <param name="sourceId">來源項目的Id</param>
        /// <returns>實體存放資料清單</returns>
        public IList<StorageFileVO> GetStorageFileList(StorageFileVO.StorageSourceType storageSourceType, int sourceId)
        {
            DetachedCriteria dCriteria = DetachedCriteria.For<StorageFileVO>();
            dCriteria.Add(Expression.Eq("SourceType", (int)storageSourceType));
            dCriteria.Add(Expression.Eq("SourceId", sourceId));

            int count = NHibernateDao.CountByDetachedCriteria(dCriteria);

            if (count == 0)
            {
                return null;
            }

            return NHibernateDao.SearchByDetachedCriteria<StorageFileVO>(dCriteria);
        }
 /// <summary>
 /// 刪除實體存放資料
 /// </summary>
 /// <param name="storageFileVO">被刪除的實體存放資料</param>
 public void DeleteStorageFile(StorageFileVO storageFileVO)
 {
     NHibernateDao.Delete(storageFileVO);
 }
        /// <summary>
        /// 新增實體存放資料
        /// </summary>
        /// <param name="storageFileVO">被新增的實體存放資料</param>
        /// <returns>新增後的實體存放資料</returns>
        public StorageFileVO CreateStorageFile(StorageFileVO storageFileVO)
        {
            NHibernateDao.Insert(storageFileVO);

            return storageFileVO;
        }
        /// <summary>
        /// 更新實體存放資料
        /// </summary>
        /// <param name="storageFileVO">被更新的實體存放資料</param>
        /// <returns>更新後的實體存放資料</returns>
        public StorageFileVO UpdateStorageFile(StorageFileVO storageFileVO)
        {
            NHibernateDao.Update(storageFileVO);

            return storageFileVO;
        }
        /// <summary>
        /// 取得取得實體存放資料清單
        /// </summary>
        /// <param name="storageSourceType">檔案來源類別</param>
        /// <param name="sourceId">來源項目的Id</param>
        /// <param name="pageIndex">分頁索引</param>
        /// <param name="pageSize">分頁大小</param>
        /// <param name="sortField">排序欄位</param>
        /// <param name="sortDesc">升降冪排序</param>
        /// <returns>實體存放資料清單</returns>
        public IList<StorageFileVO> GetStorageFileListBySourceId(StorageFileVO.StorageSourceType storageSourceType, int sourceId, int pageIndex, int pageSize, string sortField, bool sortDesc)
        {
            DetachedCriteria dCriteria = DetachedCriteria.For<StorageFileVO>();
            dCriteria.Add(Expression.Eq("SourceType", (int)storageSourceType));
            dCriteria.Add(Expression.Eq("SourceId", sourceId));

            if (!string.IsNullOrEmpty(sortField))
            {
                if (sortDesc)
                {
                    dCriteria.AddOrder(Order.Desc(sortField));
                }
                else
                {
                    dCriteria.AddOrder(Order.Asc(sortField));
                }
            }

            int count = NHibernateDao.CountByDetachedCriteria(dCriteria);

            if (count == 0)
            {
                return null;
            }

            return NHibernateDao.SearchByDetachedCriteria<StorageFileVO>(dCriteria, pageIndex, pageSize);
        }
        /// <summary>
        /// 搬移實體檔案
        /// </summary>
        /// <param name="folderType">資料夾類型</param>
        /// <param name="storageFileVO">實體存放資料</param>
        /// <returns>搬移後的實體存放資料</returns>
        public StorageFileVO RemoveStorageFile(FolderType folderType, StorageFileVO storageFileVO)
        {
            DirectoryInfo dir = GetStorageDirectory(folderType, true);

            if (File.Exists(storageFileVO.CurrentPath))
            {
                string newFileName = Guid.NewGuid().ToString() + new FileInfo(storageFileVO.CurrentPath).Extension;
                string destFileName = Path.Combine(dir.FullName, newFileName);
                m_Log.Debug("============搬移實體檔案============");
                m_Log.Debug("CurrentPath = " + storageFileVO.CurrentPath);
                m_Log.Debug("destFileName = " + destFileName);
                File.Copy(storageFileVO.CurrentPath, destFileName);
                DeleteFile(storageFileVO.CurrentPath);
                storageFileVO.CurrentPath = destFileName;
            }

            return storageFileVO;
        }
 /// <summary>
 /// 刪除實體存放資料
 /// </summary>
 /// <param name="storageFileVO">被刪除的實體存放資料</param>
 public void DeleteStorageFile(StorageFileVO storageFileVO)
 {
     StorageHelper.DeleteFile(storageFileVO.CurrentPath);
     StorageFileDao.DeleteStorageFile(storageFileVO);
 }
 /// <summary>
 /// 取得實體存放資料筆數 By SourceId
 /// </summary>
 /// <param name="storageSourceType">檔案來源類別</param>
 /// <param name="sourceId">來源項目的Id</param>
 /// <returns>實體存放資料清單筆數</returns>
 public int CountStorageFileListBySourceId(StorageFileVO.StorageSourceType storageSourceType, int sourceId)
 {
     return StorageFileDao.CountStorageFileListBySourceId(storageSourceType, sourceId);
 }
        /// <summary>
        /// 更新實體存放資料
        /// </summary>
        /// <param name="storageFileVO">被更新的實體存放資料</param>
        /// <returns>更新後的實體存放資料</returns>
        public StorageFileVO UpdateStorageFile(StorageFileVO storageFileVO)
        {
            //檔案搬移到public資料夾
            storageFileVO = StorageHelper.RemoveStorageFile(FolderType.PUBLIC_FOLDER, storageFileVO);
            storageFileVO.IsTemporary = false;

            return StorageFileDao.UpdateStorageFile(storageFileVO);
        }
 /// <summary>
 /// 取得取得實體存放資料清單
 /// </summary>
 /// <param name="storageSourceType">檔案來源類別</param>
 /// <param name="sourceId">來源項目的Id</param>
 /// <param name="pageIndex">分頁索引</param>
 /// <param name="pageSize">分頁大小</param>
 /// <param name="sortField">排序欄位</param>
 /// <param name="sortDesc">升降冪排序</param>
 /// <returns>實體存放資料清單</returns>
 public IList<StorageFileVO> GetStorageFileListBySourceId(StorageFileVO.StorageSourceType storageSourceType, int sourceId, int pageIndex, int pageSize, string sortField, bool sortDesc)
 {
     return StorageFileDao.GetStorageFileListBySourceId(storageSourceType, sourceId, pageIndex, pageSize, sortField, sortDesc);
 }
 /// <summary>
 /// 取得取得實體存放資料清單
 /// </summary>
 /// <param name="storageSourceType">檔案來源類別</param>
 /// <param name="sourceId">來源項目的Id</param>
 /// <returns>實體存放資料清單</returns>
 public IList<StorageFileVO> GetStorageFileList(StorageFileVO.StorageSourceType storageSourceType, int sourceId)
 {
     return StorageFileDao.GetStorageFileList(storageSourceType, sourceId);
 }
        public void TestCreateStorageFile()
        {
            string sourceFilePath =@"D:\我的case\小布\鋁門窗\SVN上傳\trunk\doc\規格說明書附件.docx";
            FileInfo fileInfo = new FileInfo(sourceFilePath);
            DirectoryInfo dir = m_StorageFileService.GetStorageDirectory(FolderType.UPLOAD_FOLDER, true);
            string newFileName = Guid.NewGuid().ToString() + fileInfo.Extension;
            string destFileName = Path.Combine(dir.FullName, newFileName);
            File.Copy(sourceFilePath, destFileName);

            StorageFileVO storageFileVO = new StorageFileVO();
            storageFileVO.SourceUri = fileInfo.FullName;
            storageFileVO.CurrentPath = destFileName;
            storageFileVO.FileName = fileInfo.Name;
            storageFileVO.DisplayName = fileInfo.Name;
            storageFileVO.FileSize = fileInfo.Length;
            storageFileVO.SourceType = StorageFileVO.StorageSourceType.Post;
            storageFileVO.SourceId = 1;
            storageFileVO.CreatedBy = "admin";
            storageFileVO.UpdatedBy = "admin";
            storageFileVO.CreatedDate = DateTime.Now;
            storageFileVO.UpdatedDate = DateTime.Now;
            m_StorageFileService.CreateStorageFile(storageFileVO);
        }