コード例 #1
0
ファイル: TxtLoggerTest.cs プロジェクト: hodoje/res
 public void SetupMethod()
 {
     dataToLog = "Data to log.";
     // Until future fix, change this absolute path to whatever you like.
     logDirectory = @"C:\Users\Nikola Karaklic\Desktop\Log";
     txtLogger    = new Mock <TxtLogger>().Object;
 }
コード例 #2
0
        /// <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));
            }
            //}
        }
コード例 #3
0
ファイル: Checker.cs プロジェクト: limin664043519/TJClient
 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));
     }
 }
コード例 #4
0
        public bool Append(string fileName, byte[] buffer)
        {
            bool isAppend = true;

            try
            {
                //上传的文件的保存路径
                string filePath    = System.Configuration.ConfigurationManager.AppSettings["ExcelUpFile"];
                string filePathAll = string.Format("{0}{1}\\{2}", filePath, "upLoade_execute", fileName);
                //保存上传的内容
                FileStream fs = new FileStream(filePathAll, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                fs.Seek(0, SeekOrigin.End);
                fs.Write(buffer, 0, buffer.Length);
                fs.Close();
                TxtLogger.Debug(string.Format("{0}:[{1} {2}]", "Append", fileName, "数据上传"));
                DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传正确", 1));
            }
            catch (Exception ex)
            {
                isAppend = false;
                logger.Error(string.Format("{0}:[{1} {2}]:[{3}]", "Append", fileName, "数据上传错误", ex.Message));
                DBLogger.Insert(DBLogger.GetLoggerInfo(fileName, "数据上传错误," + ex.Message, 0));
            }
            return(isAppend);
        }
コード例 #5
0
        public void Debug(string message, Exception exception)
        {
#if (DEBUG)
            TxtLogger.Append(message);
            TxtLogger.DumpException(exception);
#endif
        }
コード例 #6
0
ファイル: ExcelToDb.cs プロジェクト: limin664043519/TJClient
        /// <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;
            }
        }
コード例 #7
0
ファイル: ExcelToDb.cs プロジェクト: limin664043519/TJClient
 /// <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);
 }
コード例 #8
0
        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;
        }
コード例 #9
0
        public void DebugFormat(Exception exception, IFormatProvider formatProvider, string format, params object[] args)
        {
#if (DEBUG)
            TxtLogger.Append(format, args);
            TxtLogger.DumpException(exception);
#endif
        }
コード例 #10
0
ファイル: FileHelper.cs プロジェクト: limin664043519/TJClient
        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);
        }
コード例 #11
0
 public int Calculate(int amount, int rate)
 {
     try
     {
         int r = amount / rate;
         return(r);
     }
     catch (Exception ex)
     {
         if (this.GetLog == LogType.TXT)
         {
             TxtLogger txf = new TxtLogger();
             txf.Log(ex.Message);
             return(-1);
         }
         XmlLogger xm = new XmlLogger();
         xm.Log(ex.Message);
         return(-1);
     }
 }
コード例 #12
0
 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", "正常结束"));
 }
コード例 #13
0
        public string GetExecuteSql(string tableName)
        {
            DBOracle dboracle     = new DBOracle();
            string   str_dt_title = string.Format("select * from {0} where 1=2 ", tableName);

            TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "生成档案数据表结构", "sql文", str_dt_title));
            DataTable dt_title = dboracle.ExcuteDataTable_oracle(str_dt_title);
            string    strWhere = "";

            if (dt_title.Columns.Contains("P_RGID") && !string.IsNullOrEmpty(_model.CzList))
            {
                strWhere = string.Format(" and P_RGID in ('{0}')", _model.CzList.Replace(",", "','"));
            }
            else if (dt_title.Columns.Contains("PRGID") && !string.IsNullOrEmpty(_model.CzList))
            {
                strWhere = string.Format(" and PRGID in ('{0}')", _model.CzList.Replace(",", "','"));
            }

            if (dt_title.Columns.Contains("YLJGBM") && !string.IsNullOrEmpty(_model.Yljgbm))
            {
                strWhere = strWhere + string.Format(" and yljgbm ='{0}'", _model.Yljgbm);
            }
            else if (dt_title.Columns.Contains("YYBM") && !string.IsNullOrEmpty(_model.Yljgbm))
            {
                strWhere = strWhere + string.Format(" and yybm ='{0}'", _model.Yljgbm);
            }
            //按机构下载时判断结束
            string str_dt_data = string.Format("select * from {0} where 1=1 {1} ", tableName, strWhere);

            if (tableName.ToLower().Equals("t_jk_tjry_txm"))
            {
                strWhere    = string.Format(" and p_rgid in ('{0}')", _model.CzList.Replace(",", "','"));
                str_dt_data = "select * from t_jk_tjry_txm join t_da_jkda_rkxzl on t_jk_tjry_txm.rkxzlid=t_da_jkda_rkxzl.id and t_jk_tjry_txm.nd='{0}' where  1=1 {1}";

                str_dt_data = string.Format(str_dt_data, DateTime.Now.Year, strWhere);
            }

            TxtLogger.Debug(string.Format("{0}:[{1}{2}]", "生成档案数据", "sql文", str_dt_data));
            return(str_dt_data);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: FileHelper.cs プロジェクト: limin664043519/TJClient
        /// <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);
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
 public void Error(string message)
 {
     TxtLogger.Append(message);
 }
コード例 #19
0
 public void Fatal(string message)
 {
     TxtLogger.Append(message);
 }
コード例 #20
0
 public void Fatal(string format, params object[] args)
 {
     TxtLogger.Append(format, args);
 }
 public void SetUp()
 {
     _txtService = new Mock <ITxtLoggerService>();
     _txtLogger  = new TxtLogger(_txtService.Object);
 }
コード例 #22
0
        public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args)
        {
#if (DEBUG)
            TxtLogger.Append(format, args);
#endif
        }
コード例 #23
0
 public void InfoFormat(Exception exception, string format, params object[] args)
 {
     TxtLogger.Append(format, args);
     TxtLogger.DumpException(exception);
 }
コード例 #24
0
        public void Debug(string message)
        {
#if (DEBUG)
            TxtLogger.Append(message);
#endif
        }
コード例 #25
0
 public void InfoFormat(string format, params object[] args)
 {
     TxtLogger.Append(format, args);
 }
コード例 #26
0
 public void Info(string message, Exception exception)
 {
     TxtLogger.Append(message);
     TxtLogger.DumpException(exception);
 }
コード例 #27
0
 public void Info(string message)
 {
     TxtLogger.Append(message);
 }
コード例 #28
0
 public void FatalFormat(Exception exception, IFormatProvider formatProvider, string format, params object[] args)
 {
     TxtLogger.Append(format, args);
     TxtLogger.DumpException(exception);
 }
コード例 #29
0
 public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args)
 {
     TxtLogger.Append(format, args);
 }
コード例 #30
0
        public void Debug(string format, params object[] args)
        {
#if (DEBUG)
            TxtLogger.Append(format, args);
#endif
        }