Example #1
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>文件</returns>
        public byte[] Downloads(BaseUserInfo userInfo, string id)
        {
            byte[] result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                if (BaseSystemInfo.UploadStorageMode == "Disk")
                {
                    manager.UpdateReadCount(id);                    // 阅读次数要加一
                    BaseFileEntity entity = manager.GetObject(id);

                    System.IO.FileStream fs = null;
                    //建立二进制读取
                    System.IO.BinaryReader br = null;
                    fs     = new FileStream(entity.FilePath + entity.FileName, System.IO.FileMode.Open);
                    br     = new BinaryReader((Stream)fs);
                    result = br.ReadBytes((int)fs.Length);
                    br.Close();
                    fs.Close();
                }
                else
                {
                    result = manager.Download(id);
                }
            });
            return(result);
        }
Example #2
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseFileEntity GetObject(BaseUserInfo userInfo, string id)
        {
            BaseFileEntity entity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                entity      = manager.GetObject(id);
            });
            return(entity);
        }