Пример #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);
        }
Пример #2
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">文件主键</param>
        /// <returns>影响行数</returns>
        public int Delete(BaseUserInfo userInfo, string id)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                result      = manager.Delete(id);
            });
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 批量保存
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="result"></param>
        /// <returns>影响行数</returns>
        public int BatchSave(BaseUserInfo userInfo, DataTable dt)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                result      = manager.BatchSave(dt);
            });
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件</param>
        /// <param name="enabled">有效</param>
        /// <returns>主键</returns>
        public string Upload(BaseUserInfo userInfo, string folderId, string fileName, byte[] file, bool enabled)
        {
            string result = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                result      = manager.Upload(folderId, fileName, file, enabled);
            });
            return(result);
        }
Пример #5
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>文件</returns>
        public byte[] Download(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);
                result      = manager.Download(id);
            });
            return(result);
        }
Пример #6
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);
        }
Пример #7
0
        /// <summary>
        /// 按主键数组获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">组织机构主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByIds(BaseUserInfo userInfo, string[] ids)
        {
            var dt = new DataTable(BaseFileEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager  = new BaseFileManager(dbHelper, userInfo);
                dt           = manager.GetDataTable(BaseFileEntity.FieldId, ids, BaseFileEntity.FieldSortCode);
                dt.TableName = BaseFileEntity.TableName;
            });
            return(dt);
        }
Пример #8
0
        /// <summary>
        /// 重命名
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="newName">新名称</param>
        /// <param name="enabled">有效</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Rename(BaseUserInfo userInfo, string id, string newName, bool enabled, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            statusCode    = string.Empty;
            statusMessage = string.Empty;

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileEntity  fileEntity  = new BaseFileEntity();
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    DataTable       dataTable   = fileManager.GetDataTableById(id);
                    fileEntity.GetSingle(dataTable);
                    fileEntity.FileName = newName;
                    fileEntity.Enabled  = enabled ? 1 : 0;
                    returnValue         = fileManager.Update(fileEntity, out statusCode);
                    statusMessage       = fileManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(returnValue);
        }
Пример #9
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="search">查询</param>
        /// <returns>数据表</returns>
        public DataTable Search(BaseUserInfo userInfo, string searchValue)
        {
            var dt = new DataTable(BaseFileEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager  = new BaseFileManager(dbHelper, userInfo);
                dt           = manager.Search(searchValue);
                dt.TableName = BaseFileEntity.TableName;
            });

            return(dt);
        }
Пример #10
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">文件主键数组</param>
        /// <returns>影响行数</returns>
        public int BatchDelete(BaseUserInfo userInfo, string[] ids)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                for (int i = 0; i < ids.Length; i++)
                {
                    result += manager.Delete(ids[i]);
                }
            });
            return(result);
        }
Пример #11
0
        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <returns>存在</returns>
        public bool Exists(BaseUserInfo userInfo, string folderId, string fileName)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            bool returnValue = false;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    //returnValue = fileManager.Exists(new KeyValuePair<string, object>(BaseFileEntity.FieldFolderId, folderId), new KeyValuePair<string, object>(BaseFileEntity.FieldFileName, fileName));
                    //加入删除状态为0的条件
                    List <KeyValuePair <string, object> > parametersList = new List <KeyValuePair <string, object> >();
                    parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, folderId));
                    parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileName));
                    parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldDeletionStateCode, 0));
                    returnValue = fileManager.Exists(parametersList);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.FileService_Exists, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(returnValue);
        }
Пример #12
0
        /// <summary>
        /// 更新文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">文件主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件内容</param>
        /// <param name="statusCode">返回状态</param>
        /// <param name="statusMessage">反悔信息</param>
        /// <returns></returns>
        public int UpdateFile(BaseUserInfo userInfo, string id, string fileName, byte[] file, out string statusCode, out string statusMessage)
        {
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            int    result        = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager   = new BaseFileManager(dbHelper, userInfo);
                result        = manager.UpdateFile(id, fileName, file, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }
Пример #13
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file"></param>
        /// <param name="description"></param>
        /// <param name="enabled"></param>
        /// <param name="statusCode"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public string Add(BaseUserInfo userInfo, string folderId, string fileName, byte[] file, string description, bool enabled, out string statusCode, out string statusMessage)
        {
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            string result        = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager   = new BaseFileManager(dbHelper, userInfo);
                result        = manager.Add(folderId, fileName, file, description, enabled, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }
Пример #14
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file"></param>
        /// <param name="description"></param>
        /// <param name="enabled"></param>
        /// <param name="statusCode"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public string Add(BaseUserInfo userInfo, string folderId, string fileName, byte[] file, string description, bool enabled, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            statusCode    = string.Empty;
            statusMessage = string.Empty;

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    returnValue   = fileManager.Add(folderId, fileName, file, description, enabled, out statusCode);
                    statusMessage = fileManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }
Пример #15
0
        /// <summary>
        /// 分块上传文件添加
        /// </summary>
        /// <param name="folderId"></param>
        /// <param name="fileName"></param>
        /// <param name="file"></param>
        /// <param name="filesize"></param>
        /// <param name="enabled"></param>
        /// <returns></returns>
        public string UplaodeByBlock(string folderId, string filePath, string fileName, byte[] file, int filesize, bool enabled)
        {
            // 检查是否已经存在
            //string result = this.GetId(new KeyValuePair<string, object>(BaseFileEntity.FieldFolderId, folderId), new KeyValuePair<string, object>(BaseFileEntity.FieldFileName, fileName));
            // 检查是否已经存在,加入删除状态为0的条件
            List <KeyValuePair <string, object> > parametersList = new List <KeyValuePair <string, object> >();

            parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, folderId));
            parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileName));
            parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldDeletionStateCode, 0));
            string result = this.GetId(parametersList);

            if (!String.IsNullOrEmpty(result))
            {
                // 更新数据
                this.UpdateFile(result, fileName, file);
                //在能够真实模仿C/S中的提示确定信息对话框的B/S版本出来之前,先做如下处理:前面的文件有重复的,打删除标志来处理,因为客户不会闲着没事,老传文件,且服务器都是几百个G的空间
                // 删除数据
                BaseFileManager manager        = new BaseFileManager();
                int             intReturnValue = manager.SetDeleted(result);
                // 添加数据
                BaseFileEntity entity = new BaseFileEntity();
                entity.FolderId = folderId;
                entity.FilePath = filePath;
                entity.FileName = fileName;
                entity.Contents = file;
                entity.FileSize = filesize;
                entity.Enabled  = enabled ? 1 : 0;
                result          = this.AddObject(entity);
            }
            else
            {
                // 添加数据
                BaseFileEntity entity = new BaseFileEntity();
                entity.FolderId = folderId;
                entity.FilePath = filePath;
                entity.FileName = fileName;
                entity.Contents = file;
                entity.FileSize = filesize;
                entity.Enabled  = enabled ? 1:0;
                result          = this.AddObject(entity);
            }
            return(result);
        }
Пример #16
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">文件主键数组</param>
        /// <returns>影响行数</returns>
        public int BatchDelete(BaseUserInfo userInfo, string[] ids)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    for (int i = 0; i < ids.Length; i++)
                    {
                        returnValue += fileManager.Delete(ids[i]);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(returnValue);
        }
Пример #17
0
        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <returns>存在</returns>
        public bool Exists(BaseUserInfo userInfo, string folderId, string fileName)
        {
            bool result = false;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                //result = fileManager.Exists(new KeyValuePair<string, object>(BaseFileEntity.FieldFolderId, folderId), new KeyValuePair<string, object>(BaseFileEntity.FieldFileName, fileName));
                //加入删除状态为0的条件
                List <KeyValuePair <string, object> > parametersList = new List <KeyValuePair <string, object> >();
                parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFolderId, folderId));
                parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldFileName, fileName));
                parametersList.Add(new KeyValuePair <string, object>(BaseFileEntity.FieldDeletionStateCode, 0));
                result = manager.Exists(parametersList);
            });

            return(result);
        }
Пример #18
0
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="search">查询</param>
        /// <returns>数据表</returns>
        public DataTable Search(BaseUserInfo userInfo, string searchValue)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            DataTable dataTable = new DataTable(BaseFileEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    dataTable           = fileManager.Search(searchValue);
                    dataTable.TableName = BaseFileEntity.TableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(dataTable);
        }
Пример #19
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>文件</returns>
        public byte[] Download(BaseUserInfo userInfo, string id)
        {
            // 写入调试信息
#if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
#endif

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
#endif

            byte[] returnValue = null;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                    returnValue = fileManager.Download(id);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.FileService_Download, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
#if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
#endif

            return(returnValue);
        }
Пример #20
0
        /// <summary>
        /// 分块上传文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="folderId">文件夹主键</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件</param>
        /// <param name="enabled">有效</param>
        /// <returns>主键</returns>
        public string UplaodeByBlock(BaseUserInfo userInfo, string folderId, string fileName, byte[] file, int filesize, bool enabled)
        {
            string result = string.Empty;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var fileManager = new BaseFileManager(dbHelper, userInfo);
                //上传到磁盘
                if (BaseSystemInfo.UploadStorageMode == "Disk")
                {
                    result = fileManager.UplaodeByBlock(folderId, BaseSystemInfo.UploadPath, fileName, null, filesize, enabled);
                    CreateBlankFile(fileName, filesize);
                    UploadFileChunkBytes(file, 0, fileName);
                }
                else
                {
                    result = fileManager.UplaodeByBlock(folderId, BaseSystemInfo.UploadPath, fileName, file, filesize, enabled);
                }
            });
            return(result);
        }
Пример #21
0
        /// <summary>
        /// 分段上传文件 ,2012-10-14 HJC Add 暂时支持SQL数据库
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="length"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public string UplaodeByBlockUpdate(BaseUserInfo userInfo, string Id, string fileName, int length, byte[] file)
        {
            string result = string.Empty;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseFileManager(dbHelper, userInfo);
                if (BaseSystemInfo.UploadStorageMode == "Disk")
                {
                    UploadFileChunkBytes(file, length, fileName);
                }
                else
                {
                    result = manager.UplaodeByBlockUpdate(Id, length, file);
                }

                //分节上转不记录日志文件
                // BaseLogManager.Instance.Add(result, this.serviceName, AppMessage.FileService_Upload, MethodBase.GetCurrentMethod());
            });
            return(result);
        }
Пример #22
0
        /// <summary>
        /// 重命名
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="newName">新名称</param>
        /// <param name="enabled">有效</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Rename(BaseUserInfo userInfo, string id, string newName, bool enabled, out string statusCode, out string statusMessage)
        {
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            int    result        = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                BaseFileEntity fileEntity = new BaseFileEntity();
                var manager = new BaseFileManager(dbHelper, userInfo);
                var dt      = manager.GetDataTableById(id);
                fileEntity.GetSingle(dt);
                fileEntity.FileName = newName;
                fileEntity.Enabled  = enabled ? 1 : 0;
                result        = manager.Update(fileEntity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }
Пример #23
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件内容</param>
        /// <param name="toUserId">发送给谁主键</param>
        /// <returns>文件主键</returns>
        public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseFolderEntity  folderEntity  = new BaseFolderEntity();
                    BaseFolderManager folderManager = new BaseFolderManager(dbHelper, userInfo);
                    // 检查相应的系统必备文件夹
                    folderManager.FolderCheck();
                    BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetEntity(toUserId);
                    if (!string.IsNullOrEmpty(userEntity.Id))
                    {
                        // 04:判断发送者的空间是否存在?
                        // 05:判断已收文件夹是否存在?
                        if (!folderManager.Exists(userEntity.Id.ToString()))
                        {
                            folderEntity.FolderName        = userEntity.RealName + AppMessage.FileService_File;
                            folderEntity.ParentId          = "UserSpace";
                            folderEntity.Id                = userEntity.Id.ToString();
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        // 06:判断来自谁的文件夹是否存在?
                        // 07:判断发给谁的文件夹是否存在?
                        if (!folderManager.Exists(toUserId + "_Receive"))
                        {
                            folderEntity.FolderName        = AppMessage.FileService_ReceiveFile;
                            folderEntity.ParentId          = toUserId;
                            folderEntity.Id                = toUserId + "_Receive";
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId))
                        {
                            folderEntity.FolderName        = userEntity.RealName + "(" + userEntity.UserName + ")";
                            folderEntity.ParentId          = userInfo.Id + "_Send";
                            folderEntity.Id                = userInfo.Id + "_Send_" + toUserId;
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id))
                        {
                            folderEntity.FolderName        = userInfo.RealName + "(" + userInfo.UserName + ")";
                            folderEntity.ParentId          = toUserId + "_Receive";
                            folderEntity.Id                = toUserId + "_Receive_" + userInfo.Id;
                            folderEntity.Enabled           = 1;
                            folderEntity.DeletionStateCode = 0;
                            folderManager.AddEntity(folderEntity);
                        }
                        // 08:已发送文件夹多一个文件。
                        // 09:已接收文件夹多一个文件。
                        BaseFileEntity fileEntity = new BaseFileEntity();
                        fileEntity.FileName  = fileName;
                        fileEntity.Contents  = file;
                        fileEntity.Enabled   = 1;
                        fileEntity.ReadCount = 0;
                        fileEntity.FolderId  = userInfo.Id + "_Send_" + toUserId;
                        // 把修改人显示出来
                        fileEntity.ModifiedBy     = userInfo.RealName;
                        fileEntity.ModifiedUserId = userInfo.Id;
                        fileEntity.ModifiedOn     = DateTime.Now;
                        BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo);
                        fileManager.AddEntity(fileEntity);
                        fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id;
                        returnValue         = fileManager.AddEntity(fileEntity);
                        // string webHostUrl = BaseSystemInfo.WebHostUrl;
                        // if (string.IsNullOrEmpty(webHostUrl))
                        // {
                        //    webHostUrl = "WebHostUrl";
                        // }
                        // 10:应该还发一个短信提醒一下才对。
                        BaseMessageEntity messageEntity = new BaseMessageEntity();
                        messageEntity.Id           = Guid.NewGuid().ToString();
                        messageEntity.CategoryCode = MessageCategory.Send.ToString();
                        messageEntity.FunctionCode = MessageFunction.Message.ToString();
                        messageEntity.ObjectId     = returnValue;
                        messageEntity.ReceiverId   = toUserId;
                        // target=\"_blank\"
                        messageEntity.Contents          = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + returnValue + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile;
                        messageEntity.IsNew             = (int)MessageStateCode.New;
                        messageEntity.ReadCount         = 0;
                        messageEntity.DeletionStateCode = 0;
                        messageEntity.Enabled           = 1;
                        BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo);
                        returnValue = messageManager.Add(messageEntity);
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return(returnValue);
        }
Пример #24
0
        /// <summary>
        /// 发送文件
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="fileName">文件名</param>
        /// <param name="file">文件内容</param>
        /// <param name="toUserId">发送给谁主键</param>
        /// <returns>文件主键</returns>
        public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId)
        {
            string result = string.Empty;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                BaseFolderEntity folderEntity = new BaseFolderEntity();
                var folderManager             = new BaseFolderManager(dbHelper, userInfo);
                // 检查相应的系统必备文件夹
                folderManager.FolderCheck();
                BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetObject(toUserId);
                if (!string.IsNullOrEmpty(userEntity.Id))
                {
                    // 04:判断发送者的空间是否存在?
                    // 05:判断已收文件夹是否存在?
                    if (!folderManager.Exists(userEntity.Id))
                    {
                        folderEntity.FolderName        = userEntity.RealName + AppMessage.FileService_File;
                        folderEntity.ParentId          = "UserSpace";
                        folderEntity.Id                = userEntity.Id;
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    // 06:判断来自谁的文件夹是否存在?
                    // 07:判断发给谁的文件夹是否存在?
                    if (!folderManager.Exists(toUserId + "_Receive"))
                    {
                        folderEntity.FolderName        = AppMessage.FileService_ReceiveFile;
                        folderEntity.ParentId          = toUserId;
                        folderEntity.Id                = toUserId + "_Receive";
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId))
                    {
                        folderEntity.FolderName        = userEntity.RealName + "(" + userEntity.UserName + ")";
                        folderEntity.ParentId          = userInfo.Id + "_Send";
                        folderEntity.Id                = userInfo.Id + "_Send_" + toUserId;
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id))
                    {
                        folderEntity.FolderName        = userInfo.RealName + "(" + userInfo.UserName + ")";
                        folderEntity.ParentId          = toUserId + "_Receive";
                        folderEntity.Id                = toUserId + "_Receive_" + userInfo.Id;
                        folderEntity.Enabled           = 1;
                        folderEntity.DeletionStateCode = 0;
                        folderManager.AddObject(folderEntity);
                    }
                    // 08:已发送文件夹多一个文件。
                    // 09:已接收文件夹多一个文件。
                    BaseFileEntity fileEntity = new BaseFileEntity();
                    fileEntity.FileName       = fileName;
                    fileEntity.Contents       = file;
                    fileEntity.Enabled        = 1;
                    fileEntity.ReadCount      = 0;
                    fileEntity.FolderId       = userInfo.Id + "_Send_" + toUserId;
                    // 把修改人显示出来
                    fileEntity.ModifiedBy     = userInfo.RealName;
                    fileEntity.ModifiedUserId = userInfo.Id;
                    fileEntity.ModifiedOn     = DateTime.Now;
                    var fileManager           = new BaseFileManager(dbHelper, userInfo);
                    fileManager.AddObject(fileEntity);
                    fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id;
                    result = fileManager.AddObject(fileEntity);
                    // string webHostUrl = BaseSystemInfo.WebHost;
                    // if (string.IsNullOrEmpty(webHostUrl))
                    // {
                    //    webHostUrl = "WebHostUrl";
                    // }
                    // 10:应该还发一个短信提醒一下才对。
                    BaseMessageEntity messageEntity = new BaseMessageEntity();
                    //messageEntity.Id = Guid.NewGuid().ToString("N");
                    messageEntity.CategoryCode = MessageCategory.Send.ToString();
                    messageEntity.FunctionCode = MessageFunction.Message.ToString();
                    messageEntity.ObjectId     = result;
                    messageEntity.ReceiverId   = toUserId;
                    // target=\"_blank\"
                    messageEntity.Contents          = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + result + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile;
                    messageEntity.IsNew             = (int)MessageStateCode.New;
                    messageEntity.ReadCount         = 0;
                    messageEntity.DeletionStateCode = 0;
                    var messageManager      = new BaseMessageManager(dbHelper, userInfo);
                    messageManager.Identity = true;
                    result = messageManager.Add(messageEntity);
                }
            });
            return(result);
        }