/// <summary> /// 客户端下载文件生成处理 /// </summary> /// <param name="yljgbm"></param> /// <param name="czList"></param> /// <returns></returns> public string downLoadFileCreate(string rndPrefix, string yljgbm, string czList, string dataType) { //lock (locker) //{ string functionName = "downLoadInfoByParm"; try { //2017-08-24 mq添加,用于判断时间间隔 //if (CheckDownloadDataExpire.CanDirectDownload(GetDownloadDirPath(), dataType, GetInterval(), yljgbm)) //{ // return CheckDownloadDataExpire.GetDownloadFilePath(dataType, yljgbm); //} DoServiceNew doservicenew = new DoServiceNew(); string resultStr = doservicenew.DoDownLoadInfo(rndPrefix, yljgbm, czList, dataType); ////将生成的文件对应的保存到静态变量中 //CheckDownloadDataExpire.AddDownloadInfo(new DownloadInfo(resultStr, dataType, yljgbm)); //日志处理 TxtLogger.Debug(string.Format("{0}:[{1}{2}]:[{3}]", functionName, yljgbm, "数据下载结束", resultStr)); return(resultStr); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]", functionName, yljgbm, "数据下载错误", ex.Message)); throw new Exception(string.Format("{1}:处理异常:{0}", ex.Message, functionName)); } //} }
/// <summary> /// 数据写到数据库中 /// </summary> /// <param name="dtPara"></param> private static void dataToDbFromDt(DataTable dtPara, string GuidStr) { TxtLogger.Error(string.Format("{0}:[{1}]", "dataToDbFromDt", GuidStr)); try { if (dtPara != null && dtPara.Rows.Count > 0) { //每次处理的数据条数 int pagecount = 2000; //将数据按照处理条数分次处理 for (int i = 0; i <= dtPara.Rows.Count / pagecount; i++) { DataTable dt = dtPara.Clone(); for (int j = i * pagecount; (j < (i + 1) * pagecount && j < dtPara.Rows.Count); j++) { dt.ImportRow(dtPara.Rows[j]); } DataColumn dtColumn = new DataColumn(); dtColumn.ColumnName = "DeleteGuid"; dtColumn.DefaultValue = GuidStr; dt.Columns.Add(dtColumn); TxtLogger.Debug("TableName:" + dtPara.TableName.Split(new char[] { '-' })[0]); //数据库处理 MultiInsertData(dt, dtPara.TableName.Split(new char[] { '-' })[0]); } } } catch (Exception ex) { throw ex; } }
public static bool DoFileIsExcute(string clientUser) { try { lock (upLocker) { //获取数据处理的状态 DBOracle dboracle = new DBOracle(); //CLCXZT 处理程序状态 1停止 2运行中 DataTable dt = dboracle.ExcuteDataTable_oracle("select * from T_JK_CXZT where CLCXZT='2' "); if (dt != null && dt.Rows.Count > 0) { TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "DoFileIsExcute", clientUser, "程序已经启动")); //程序正在执行中 return(true); } else { //处理程序没有执行,启动处理程序 string sql_Insert = string.Format("insert into T_JK_CXZT(CLCXBM,CLCXSM,CLCXZT,CZY,KSSJ)values('{0}','{1}','{2}','{3}','{4}') ", clientUser, clientUser, "2", clientUser, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")); //从数据库中获取数据状态 //DBOracle dboracle = new DBOracle(); int insertResult = dboracle.ExecuteNonQuery_oracle(sql_Insert); TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "DoFileIsExcute", clientUser, "程序正常启动")); return(false); } } } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]", "DoFileIsExcute", clientUser, "设定程序启动状态错误", ex.Message)); throw new Exception(string.Format("DoFileIsExcute:设定程序启动状态错误:{0}", ex.Message)); } }
/// <summary> /// 将Excel中的内容转换为数据集合DataSet,调用数据库处理 /// </summary> /// <param name="ExcelFilePathAll"></param> /// <returns></returns> public static bool DoExcelTextToDb(string ExcelFilePathAll, string GuidStr) { try { TxtLogger.Error(string.Format("{0}:[{1}]:[{2}]", "doExcelTextToDb", ExcelFilePathAll, GuidStr)); //mq 2017-11-24上面操作语句注释,加入以下语句。 commonExcel commonexcel = new commonExcel(); DataSet ds = commonexcel.ExcelFileToDataSet(ExcelFilePathAll, GuidStr); if (ds != null && ds.Tables.Count > 0) { foreach (DataTable dt in ds.Tables) { dataToDbFromDt(dt, GuidStr); } } } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}]:[{2}]:[{3}]", "doExcelTextToDb", ExcelFilePathAll, "数据保存异常", ex.Message + ex.StackTrace)); DBLogger.Insert(DBLogger.GetLoggerInfo(ExcelFilePathAll, ex.Message + Environment.NewLine + ex.StackTrace, GuidStr, 0)); //throw ex; return(false); } return(true); }
public void DoFile(string clientUser, string GuidStr, string yljgbm) { TxtLogger.Debug(string.Format("{0}:[{1}]:[{2}]", "DoFile", clientUser, "文件处理开始")); //取得本地的保存文件地址 string filePathAll = Common.GetUploadeFilePath(); string filePathAllTo = Common.GetExcuteFilePath(); try { //文件处理 if (FileHelper.CopyDirectory(filePathAll, filePathAllTo)) { //将文件内容保存到数据库中 DoFileToDb(filePathAllTo, GuidStr, yljgbm, clientUser); //处理完当前数据后再次扫描是否存在需要处理的文件 DoFile(clientUser, GuidStr, yljgbm); } TxtLogger.Debug(string.Format("{0}:[{1}]:[{2}]", "DoFile", clientUser, "文件处理结束")); DBLogger.Insert(new LoggerInfo(clientUser, "DoFile 文件处理结束", 1)); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}]:[{2}]:[{3}]", "DoFile", clientUser, "文件处理异常", ex.Message)); DBLogger.Insert(new LoggerInfo(clientUser, string.Format("DoFile文件处理异常,{0}", ex.Message), 0)); throw ex; } finally { //将状态改变回来 Checker.ChangeExcuteStatus(); } return; }
public static bool CopyDirectory(string DirectoryPath, string DirAddress)//复制文件夹, { //是否存在要处理的文件 bool isExistsFile = false; //要处理的文件数量 int fileCount = 0; try { if (!Directory.Exists(DirAddress)) { Directory.CreateDirectory(DirAddress); } DirectoryInfo DirectoryArray = new DirectoryInfo(DirectoryPath); FileInfo[] Files = DirectoryArray.GetFiles(); //获取该文件夹下的文件列表 DirectoryInfo[] Directorys = DirectoryArray.GetDirectories(); //获取该文件夹下的文件夹列表 foreach (FileInfo theFile in Files) //逐个复制文件 { //如果临时文件夹下存在与应用程序所在目录下的文件同名的文件,则删除应用程序目录下的文件 if (File.Exists(DirAddress + "\\" + Path.GetFileName(theFile.FullName))) { File.Delete(DirAddress + "\\" + Path.GetFileName(theFile.FullName)); //将临时文件夹的文件移到应用程序所在的目录下 File.Move(theFile.FullName, DirAddress + "\\" + Path.GetFileName(theFile.FullName)); fileCount++; } else { //将临时文件夹的文件移到应用程序所在的目录下 File.Move(theFile.FullName, DirAddress + "\\" + Path.GetFileName(theFile.FullName)); fileCount++; } } ////删除处理完的文件目录 foreach (DirectoryInfo Dir in Directorys)//逐个获取文件夹名称,并递归调用方法本身 { bool result = CopyDirectory(DirectoryPath + "\\" + Dir.Name, DirAddress + "\\" + Dir.Name); if (result == true) { isExistsFile = true; } } //只要存在要处理的文件就返回true if (fileCount > 0) { isExistsFile = true; } } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]:[{4}]", "copyDirectory", DirectoryPath, "设定程序启动状态错误", ex.Message, ex.StackTrace)); return(false); } return(isExistsFile); }
public string DoFileThread(string clientUser, string GuidStr, string yljgbm) { try { //文件处理是否已经启动 true:已经启动 false:未启动 if (Checker.DoFileIsExcute(clientUser) == false) { startThread(clientUser, GuidStr, yljgbm); } TxtLogger.Debug(string.Format("{0}:[{1} {2}]]", "DoFileThread", clientUser, "上传数据处理程序启动")); DBLogger.Insert(new LoggerInfo(clientUser, "DoFileThread上传数据处理程序启动", 1)); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "DoFileThread", clientUser, "上传数据处理程序启动异常", ex.Message)); DBLogger.Insert(new LoggerInfo(clientUser, string.Format("DoFileThread上传数据处理程序启动异常,{0}", ex.Message), 0)); return(string.Format("0-{0}-{1}", "DoFileThread", ex.Message)); } return(string.Format("1-{0}-{1}", "DoFileThread", "正常结束")); }
public bool Verify(string fileName, string md5) { bool isVerify = true; try { //文件保存的路径 string filePathAll = Upload.Common.GetFilePathAll(fileName); string filePathAllTo = Upload.Common.GetFilePathAllTo(fileName); if (fileName.EndsWith("xls") == false) { //先判断是否是zip签名图片文件,如果是,单独处理 //先将zip移动到zip_file目录中,再解压缩,进行复制操作 if (fileName.EndsWith("zip")) { return(ZipFileOperation(fileName, md5, filePathAll)); } filePathAllTo = Upload.Common.GetXdtImgFilePathToAll(fileName); } string uploadMessage = "上传数据验证结束"; //判断文件是否正确 if (md5 != Common.Md5(filePathAll)) { isVerify = false; uploadMessage = "上传数据验证异常"; filePathAllTo = Upload.Common.GetErrorFilePath(fileName); } Upload.FileHelper.CopyDirectoryOneFile(filePathAll, filePathAllTo); TxtLogger.Debug(string.Format("{0}:[{1} {2}]", "Verify", fileName, uploadMessage)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "上传数据验证结束", 1)); } catch (Exception ex) { isVerify = false; TxtLogger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "Verify", fileName, "上传数据验证异常", ex.Message)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "上传数据验证异常," + ex.Message, 0)); } return(isVerify); }
public bool CreateFile(string fileName) { bool isCreate = true; try { //上传的文件的保存路径 string filePath = System.Configuration.ConfigurationManager.AppSettings["ExcelUpFile"]; string filePathAll = string.Format("{0}{1}\\{2}", filePath, "upLoade_execute", fileName); //首先设置上传服务器文件的路径 然后发布web服务 发布的时候要自己建一个自己知道的文件夹 "C:\NMGIS_Video\" "C:\NMGIS_Video\" FileStream fs = new FileStream(filePathAll, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Close(); TxtLogger.Debug(string.Format("{0}:[{1} {2}]", "CreateFile", fileName, "数据上传的文件创建完成")); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传的文件创建完成", 1)); } catch (Exception ex) { isCreate = false; TxtLogger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "CreateFile", fileName, "数据上传错误", ex.Message)); DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传错误," + ex.Message, 0)); } return(isCreate); }
/// <summary> /// 复制文件夹中的所有文件到指定文件夹 /// </summary> /// <param name="DirectoryPath">源文件夹路径</param> /// <param name="DirAddress">保存路径</param> public static void CopyDirectoryOneFile(string DirectoryPath, string DirAddress)//复制文件夹, { //保存文件的路径 string filePathTo = Path.GetDirectoryName(DirAddress); //保存文件的文件名称 string fileName = Path.GetFileName(DirAddress); try { //文件目录的处理 if (!Directory.Exists(filePathTo)) { Directory.CreateDirectory(filePathTo); } //获取要复制的文件 if (File.Exists(DirectoryPath)) { //取得要copy的文件 if (File.Exists(DirAddress)) { File.Delete(DirAddress); } //将临时文件夹的文件移到应用程序所在的目录下 File.Move(DirectoryPath, DirAddress); } TxtLogger.Debug(string.Format("{0}:[{1}{2}]]", "copyDirectoryOneFile", DirAddress, "数据复制完成")); } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}{2}]:[{3}]", "DoFileIsExcute", DirectoryPath, "设定程序启动状态错误", ex.Message)); throw new Exception("copyDirectoryOneFile处理错误:" + fileName + ":" + ex.Message); } }
private bool DoFileToDb(string DirectoryPath, string GuidStr, string yljgbm, string clientUser) { bool isExistsFile = false; string errorFile = ""; try { //获取该文件夹下的文件列表 FileInfo[] Files = FileHelper.GetFilesInDirectory(DirectoryPath); //获取该文件夹下的文件夹列表 DirectoryInfo[] Directorys = FileHelper.GetDirectorysInDirectory(DirectoryPath); //逐个处理文件 foreach (FileInfo theFile in Files) { FileInfoOperation(theFile, GuidStr, yljgbm, clientUser); } //逐个获取文件夹名称,并递归调用方法本身 foreach (DirectoryInfo Dir in Directorys) { bool result = FileHelper.CopyDirectory(DirectoryPath + "\\" + Dir.Name, Common.GetBackupFilePath() + "\\" + Dir.Name); if (result) { isExistsFile = true; } } //只要存在要处理的文件就返回true } catch (Exception ex) { TxtLogger.Error(string.Format("{0}:[{1}]:[{2}]", "DoFileToDb", "数据保存异常", ex.Message)); DBLogger.Insert(DBLogger.GetLoggerInfo(errorFile, ex.Message, GuidStr, 0)); return(false); } return(isExistsFile); }