public void Write(ErrorLog message) { string logpath = LogConfig.Instance.ErrorLogPath; //string filepath = logpath + "\\ErrorLog\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".xml"; string filepath = string.Empty; if (string.IsNullOrEmpty(logpath)) { filepath = AppDomain.CurrentDomain.BaseDirectory; } else { filepath = logpath; } filepath += @"/ErrorLog/"; if (!Directory.Exists(filepath)) //如果文件夹不存在 { DirectoryInfo dirinfo = System.IO.Directory.CreateDirectory(filepath);//创建文件夹 } filepath += DateTime.Now.ToString("yyyy-MM-dd") + Thread.CurrentThread.ManagedThreadId.ToString() + ".xml"; // 异步写 AutoResetEvent manualEvent = new AutoResetEvent(false); AsyncWriteLogCaller caller = new AsyncWriteLogCaller(WriteLog); IAsyncResult result = caller.BeginInvoke(message, filepath, null, null); manualEvent.WaitOne(3000, false); }
public void SendMail(ErrorLog message) { try { System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(LogConfig.Instance.SMTPServer); client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(LogConfig.Instance.SMTPLogin, LogConfig.Instance.SMTPPassword);//CredentialCache.DefaultNetworkCredentials;//// CredentialCache.DefaultNetworkCredentials;// new ; client.DeliveryMethod = SmtpDeliveryMethod.Network; MailAddress from = new MailAddress(LogConfig.Instance.ErrorEmailSender); MailAddress to = new MailAddress(LogConfig.Instance.ErrorEmailReceiver); System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(from, to); mailMessage.BodyEncoding = System.Text.Encoding.UTF8; mailMessage.IsBodyHtml = true; //mailMessage.Subject = "Auto Generated Error Message – Version " + message.AWBVersion; //mail body StringBuilder body = new StringBuilder(); body.Append("<html ><head><style type='text/css' >td{font-size:12px;bold:true;}</style></head><body><table border=1 width=600px align=center> <tr><td colspan=4 >Error Log</td></tr>"); body.Append("<tr><td>Client Host Name:</td><td colspan='3'>" + message.ClientHostName + "</td></tr>"); body.Append("<tr><td>Client Host Address:</td><td colspan='3'>" + message.ClientHostAddress + "</td></tr>"); body.Append("<tr><td>Computer Name:</td><td colspan='3'>" + message.ComputerName + "</td></tr>"); body.Append("<tr><td>Created On:</td><td colspan='3'>" + message.CreatedOn + "</td></tr>"); body.Append("<tr><td colspan=4>Login Information</td></tr>"); body.Append("<tr><td> Login User Name:</td><td>" + message.LoginUser + "</td><td>Login User ID:</td><td>" + message.LoginUserId + "</td></tr>"); //body.Append("<tr><td>Organization ID:</td><td colspan=3>" + message.OrganizationID + "</td></tr>"); body.Append("<tr><td colspan=4>Exception Details</td></tr>"); body.Append("<tr><td>Error URL:</td><td colspan='3'>" + message.ErrorURL + "</td></tr>"); body.Append("<tr><td>Error Stack Trace:</td><td colspan='3'>" + message.ErrorMessage.ToString() + "</td></tr>"); body.Append("<tr><td colspan=4>Server Information</td></tr>"); body.Append("<tr><td>Server OS:</td><td colspan='3'>" + message.ServerOS + "</td></tr>"); body.Append("<tr><td>Server .Net Runtime:</td><td colspan='3'>" + message.ServerNetRuntime + "</td></tr>"); //body.Append("<tr><td>AWB Assemblies Version:</td><td colspan='3'>" + message.AWBAssembliesVersion + "</td></tr>"); body.Append("<tr><td colspan=4>Client Information</td></tr>"); body.Append("<tr><td>Client OS:</td><td colspan='3'>" + message.ClientOS + "</td></tr>"); body.Append("<tr><td>Client OS Language:</td><td colspan='3'>" + message.ClientOSLanguage + "</td></tr>"); body.Append("<tr><td>Client Browser:</td><td colspan='3'>" + message.ClientBrowser + "</td></tr>"); body.Append("<tr><td>Client Browser Language:</td><td colspan='3'>" + message.ClientBrowserLanguage + "</td></tr>"); body.Append("<tr><td>Client .Net Runtime:</td><td colspan='3'>" + message.ClientNetRuntime + "</td></tr>"); body.Append("<tr><td>Client JavaScript Support:</td><td colspan='3'>" + (message.ClientJavaScriptSupport == true ? "Yes" : "No") + "</td></tr>"); body.Append("</table></body></html>"); mailMessage.Body = body.ToString(); client.Send(mailMessage); } catch (Exception ex) { Tracer.Error(ex.ToString()); } }
public void Write(ErrorLog message) { //string pk = Guid.NewGuid().ToString(); //string baseSql = "INSERT INTO SMT_ErrorMessageBase (SMT_ErrorMessageId, CreatedOn, CreatedBy, ModifiedOn, ModifiedBy, StateCode, StatusCode, DeletionStateCode,OrganizationId) " // + " VALUES ('{0}', {1},{2},{3}, {4},{5},{6}, {7},{8}) "; //string exSql = "INSERT INTO SMT_ErrorMessageExtensionBase (SMT_ErrorMessageId,SMT_ComputerName,SMT_AWBAssemblyVersion,SMT_AWBVersion," // + " SMT_ClientBrowser,SMT_ClientBrowserLanguage,SMT_ClientJavaScriptSupport,SMT_ClientNetRuntime,SMT_ClientOS," // + " SMT_ClientOSLanguage,SMT_ServerOS,SMT_ServerNetRuntime,SMT_Message,SMT_ErrorStackTrace,SMT_ErrorURL)" // + " values (@SMT_ErrorMessageId,@SMT_ComputerName,@SMT_AWBAssemblyVersion,@SMT_AWBVersion," // + " @SMT_ClientBrowser,@SMT_ClientBrowserLanguage,@SMT_ClientJavaScriptSupport,@SMT_ClientNetRuntime,@SMT_ClientOS," // + " @SMT_ClientOSLanguage,@SMT_ServerOS,@SMT_ServerNetRuntime,@SMT_ErrorMessage,@SMT_ErrorStackTrace,@SMT_ErrorURL)"; //baseSql = string.Format(baseSql, pk, "getutcdate()", "dbo.fn_FindUserGuid()", "getutcdate() ", " dbo.fn_FindUserGuid()", 0, 1, 0, "dbo.fn_FindOrganizationGuid()"); //ParameterCollection pcoll = new ParameterCollection(); //pcoll.Add("@SMT_ErrorMessageId", pk); //pcoll.Add("@SMT_ComputerName", ConvertHelper.ToSqlParameter(message.ComputerName)); //pcoll.Add("@SMT_AWBAssemblyVersion", ConvertHelper.ToSqlParameter(message.AWBAssembliesVersion)); //pcoll.Add("@SMT_AWBVersion", ConvertHelper.ToSqlParameter(message.AWBVersion)); //pcoll.Add("@SMT_ClientBrowser", ConvertHelper.ToSqlParameter(message.ClientBrowser)); //pcoll.Add("@SMT_ClientBrowserLanguage", ConvertHelper.ToSqlParameter(message.ClientBrowserLanguage)); //pcoll.Add("@SMT_ClientJavaScriptSupport", ConvertHelper.ToSqlParameter(message.ClientJavaScriptSupport == true ? 1 : 0)); //pcoll.Add("@SMT_ClientNetRuntime", ConvertHelper.ToSqlParameter(message.ClientNetRuntime)); //pcoll.Add("@SMT_ClientOS", ConvertHelper.ToSqlParameter(message.ClientOS)); //pcoll.Add("@SMT_ClientOSLanguage", ConvertHelper.ToSqlParameter(message.ClientOSLanguage)); //pcoll.Add("@SMT_ServerOS", ConvertHelper.ToSqlParameter(message.ServerOS)); //pcoll.Add("@SMT_ServerNetRuntime", ConvertHelper.ToSqlParameter(message.ServerNetRuntime)); //pcoll.Add("@SMT_ErrorMessage", ConvertHelper.ToSqlParameter(message.ErrorMessage)); //pcoll.Add("@SMT_ErrorStackTrace", ConvertHelper.ToSqlParameter(message.ErrorStackTrace)); //pcoll.Add("@SMT_ErrorURL", ConvertHelper.ToSqlParameter(message.ErrorURL)); //IDAO dao = null; //try //{ // dao = new SqlServerDAO(LogConfig.Instance.ConnectionString); // dao.BeginTransaction(); // dao.ExecuteNonQuery(baseSql, CommandType.Text); // dao.ExecuteNonQuery(exSql, CommandType.Text, pcoll); // dao.Commit(); //} //catch (Exception ex) //{ // if (dao != null) // { // dao.Rollback(); // } // throw ex; //} }
public void WriteLog(ErrorLog message) { //Loggers = new List<ILogger>(); // Loggers = InitLogger(); foreach (ILogger l in InitLogger()) { l.Write(message); } if (LogConfig.Instance.SendErrorEmail == "Yes") { if (aleadySendEmail == false) { SendMail(message); aleadySendEmail = true; } } }
protected override void OnStart(string[] args) { //服务启动 this.timerImportRd.Enabled = true; Tracer.Debug("启动服务成功"); string msg = "定时打卡服务启动服务成功。"; Tracer.Debug(msg); TestMode = "False"; TestCompanyIp = string.Empty; SMT.Foundation.Log.LogManager log = new SMT.Foundation.Log.LogManager(); Exception ex = new Exception(msg); ErrorLog msgsend = new ErrorLog(ex); log.SendMail(msgsend); strElapsedHour = ConfigurationManager.AppSettings["ElapsedHour"].ToString(); TestMode = "False"; TestCompanyIp = string.Empty; TestMode = ConfigurationManager.AppSettings["TestMode"].ToString(); strNewDevices = ConfigurationManager.AppSettings["newDevice"].ToString(); iPort = int.Parse(ConfigurationManager.AppSettings["clockPort"].ToString()); strIPs = ConfigurationManager.AppSettings["clockIp"].ToString(); strCompanyIDs = ConfigurationManager.AppSettings["companyID"].ToString(); StrCustomerName = ConfigurationManager.AppSettings["CustomerName"].ToString(); if (TestMode == "true") { string Interval = ConfigurationManager.AppSettings["TestInterval"].ToString(); timerImportRd.Interval = int.Parse(Interval); TestCompanyIp = ConfigurationManager.AppSettings["TestCompanyIp"].ToString(); TestElapsedHour = ConfigurationManager.AppSettings["TestElapsedHour"].ToString(); Tracer.Debug("测试模式已开启" + ",Interval=" + timerImportRd.Interval + ",TestCompanyIp=" + TestCompanyIp + ",TestElapsedHour=" + TestElapsedHour); } }
private void AppendXML(ErrorLog message, string filepath) { XmlDocument doc = new XmlDocument(); doc.Load(filepath); XmlElement root = doc.DocumentElement; // 获取根节点 XmlElement errorlog = doc.CreateElement("LOG_ErrorLog"); root.AppendChild(errorlog); XmlElement eid = doc.CreateElement("LOG_ErrorLogID"); eid.InnerText = message.ErrorLogID; errorlog.AppendChild(eid); //XmlElement element2 = doc.CreateElement("LOG_AWBVersion"); //element2.InnerText = message.AWBVersion; //errorlog.AppendChild(element2); //XmlElement element3 = doc.CreateElement("LOG_AWBAssembliesVersion"); //element3.InnerText = message.AWBAssembliesVersion; //errorlog.AppendChild(element3); XmlElement element2 = doc.CreateElement("ClientHostName"); element2.InnerText = message.ClientHostName; errorlog.AppendChild(element2); XmlElement element3 = doc.CreateElement("ClientHostAddress"); element3.InnerText = message.ClientHostAddress; errorlog.AppendChild(element3); XmlElement element4 = doc.CreateElement("LOG_ClientBrowser"); element4.InnerText = message.ClientBrowser; errorlog.AppendChild(element4); XmlElement element5 = doc.CreateElement("LOG_ClientBrowserLanguage"); element5.InnerText = message.ClientBrowserLanguage; errorlog.AppendChild(element5); XmlElement element6 = doc.CreateElement("LOG_ClientJavaScriptSupport"); element6.InnerText = message.ClientJavaScriptSupport == true ? "Yes" : "No"; errorlog.AppendChild(element6); XmlElement element7 = doc.CreateElement("LOG_ClientNetRuntime"); element7.InnerText = message.ClientNetRuntime; errorlog.AppendChild(element7); XmlElement element8 = doc.CreateElement("LOG_ClientOS"); element8.InnerText = message.ClientOS; errorlog.AppendChild(element8); XmlElement element9 = doc.CreateElement("LOG_ClientOSLanguage"); element9.InnerText = message.ClientOSLanguage; errorlog.AppendChild(element9); XmlElement element10 = doc.CreateElement("LOG_ServerOS"); element10.InnerText = message.ServerOS; errorlog.AppendChild(element10); XmlElement element11 = doc.CreateElement("LOG_ServerNetRuntime"); element11.InnerText = message.ServerNetRuntime; errorlog.AppendChild(element11); XmlElement element12 = doc.CreateElement("LOG_ComputerName"); element12.InnerText = message.ComputerName; errorlog.AppendChild(element12); XmlElement element13 = doc.CreateElement("LOG_ErrorExecutionTrace"); element13.InnerText = message.ErrorExecutionTrace; errorlog.AppendChild(element13); XmlElement element14 = doc.CreateElement("LOG_ErrorMessag"); element14.InnerText = message.ErrorMessage; errorlog.AppendChild(element14); XmlElement element15 = doc.CreateElement("LOG_ErrorStackTrace"); element15.InnerText = message.ErrorStackTrace; errorlog.AppendChild(element15); XmlElement element16 = doc.CreateElement("LOG_ErrorURL"); element16.InnerText = message.ErrorURL; errorlog.AppendChild(element16); XmlElement element17 = doc.CreateElement("LOG_LoginUser"); element17.InnerText = message.LoginUser; errorlog.AppendChild(element17); XmlElement element18 = doc.CreateElement("LOG_OrganizationID"); element18.InnerText = message.OrganizationID; errorlog.AppendChild(element18); XmlElement element19 = doc.CreateElement("LOG_CreatedOn"); element19.InnerText = message.CreatedOn; errorlog.AppendChild(element19); root.AppendChild(errorlog); doc.Save(filepath); }
private void CreateNewXML(ErrorLog message, string filepath) { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("LOG_ErrorLogs"); doc.AppendChild(root); XmlElement errorlog = doc.CreateElement("LOG_ErrorLog"); root.AppendChild(errorlog); //add detail error log info XmlElement element1 = doc.CreateElement("LOG_ErrorLogID"); element1.InnerText = message.ErrorLogID; errorlog.AppendChild(element1); XmlElement element2 = doc.CreateElement("LOG_CurrentTheadID"); element2.InnerText = message.ThreadId; errorlog.AppendChild(element2); //XmlElement element2 = doc.CreateElement("LOG_AWBVersion"); //element2.InnerText = message.AWBVersion; //errorlog.AppendChild(element2); //XmlElement element3 = doc.CreateElement("LOG_AWBAssembliesVersion"); //element3.InnerText = message.AWBAssembliesVersion; //errorlog.AppendChild(element3); XmlElement element4 = doc.CreateElement("LOG_ClientBrowser"); element4.InnerText = message.ClientBrowser; errorlog.AppendChild(element4); XmlElement element5 = doc.CreateElement("LOG_ClientBrowserLanguage"); element5.InnerText = message.ClientBrowserLanguage; errorlog.AppendChild(element5); XmlElement element6 = doc.CreateElement("LOG_ClientJavaScriptSupport"); element6.InnerText = message.ClientJavaScriptSupport == true ? "Yes" : "No"; errorlog.AppendChild(element6); XmlElement element7 = doc.CreateElement("LOG_ClientNetRuntime"); element7.InnerText = message.ClientNetRuntime; errorlog.AppendChild(element7); XmlElement element8 = doc.CreateElement("LOG_ClientOS"); element8.InnerText = message.ClientOS; errorlog.AppendChild(element8); XmlElement element9 = doc.CreateElement("LOG_ClientOSLanguage"); element9.InnerText = message.ClientOSLanguage; errorlog.AppendChild(element9); XmlElement element10 = doc.CreateElement("LOG_ServerOS"); element10.InnerText = message.ServerOS; errorlog.AppendChild(element10); XmlElement element11 = doc.CreateElement("LOG_ServerNetRuntime"); element11.InnerText = message.ServerNetRuntime; errorlog.AppendChild(element11); XmlElement element12 = doc.CreateElement("LOG_ComputerName"); element12.InnerText = message.ComputerName; errorlog.AppendChild(element12); XmlElement element13 = doc.CreateElement("LOG_ErrorExecutionTrace"); element13.InnerText = message.ErrorExecutionTrace; errorlog.AppendChild(element13); XmlElement element14 = doc.CreateElement("LOG_ErrorMessag"); element14.InnerText = message.ErrorMessage; errorlog.AppendChild(element14); XmlElement element15 = doc.CreateElement("LOG_ErrorStackTrace"); element15.InnerText = message.ErrorStackTrace; errorlog.AppendChild(element15); XmlElement element16 = doc.CreateElement("LOG_ErrorURL"); element16.InnerText = message.ErrorURL; errorlog.AppendChild(element16); XmlElement element17 = doc.CreateElement("LOG_LoginUser"); element17.InnerText = message.LoginUser; errorlog.AppendChild(element17); XmlElement element18 = doc.CreateElement("LOG_OrganizationID"); element18.InnerText = message.OrganizationID; errorlog.AppendChild(element18); XmlElement element19 = doc.CreateElement("LOG_CreatedOn"); element19.InnerText = message.CreatedOn; errorlog.AppendChild(element19); //add xml head XmlProcessingInstruction xpi = doc.CreateProcessingInstruction("xml", "version='1.0' encoding='utf-8'"); doc.InsertBefore(xpi, doc.ChildNodes[0]); doc.Save(filepath); }
/// <summary> /// Retrieve ErrorLogs according to the datetime period and userid. /// </summary> /// <param name="dtfrom"></param> /// <param name="dtto"></param> /// <param name="strUserID"></param> /// <returns></returns> //public DataSet RetrieveErrorLogs(DateTime dtfrom, DateTime dtto, string strUserID) //{ // DataSet rds = new DataSet(); // int interval = DateTime.Compare(dtto, dtfrom); // string path; // for (int i = 0; i <= interval; i++) // { // path = LogConfig.Instance.ErrorLogPath + "ErrorLog" + dtfrom.AddDays(i).ToString("yyyy-MM-dd") + ".xml"; // DataSet ds = new DataSet(); // if (File.Exists(path)) // { // ds.ReadXml(path); // if (rds.Tables.Count == 0) // { // DataTable dt = new DataTable(); // dt = ds.Tables[0].Copy(); // dt.Clear(); // rds.Tables.Add(dt); // } // DataRow[] rows = ds.Tables[0].Select("LOG_LoginUser='******'"); // if (rows.Length > 0) // { // foreach (DataRow row in rows) // { // DataRow newrow = rds.Tables[0].NewRow(); // for (int j = 0; j < rds.Tables[0].Columns.Count; j++) // { // newrow[j] = row[j]; // } // rds.Tables[0].Rows.Add(newrow); // } // } // ds.Dispose(); // } // } // return rds; //} ///// <summary> ///// Retrieve a ErrorLog according to the ErrorLogID ///// </summary> ///// <param name="ErrorLogID"></param> ///// <returns></returns> //public ErrorLog RetrieveErrorLogById(System.Guid ErrorLogID) //{ // string[] files = Directory.GetFiles(LogConfig.Instance.ErrorLogPath, "ErrorLog*.xml", SearchOption.TopDirectoryOnly); // XmlDocument doc = new XmlDocument(); // ErrorLog log = new ErrorLog(); // foreach (string file in files) // { // doc.Load(file); // XmlElement root = doc.DocumentElement; // foreach (XmlNode node in root.ChildNodes) // { // if (node.FirstChild.InnerText == ErrorLogID.ToString() && node.ChildNodes.Count == 19) // { // log.ErrorLogID = ErrorLogID.ToString(); // log.AWBVersion = node.ChildNodes[1].InnerText; // log.AWBAssembliesVersion = node.ChildNodes[2].InnerText; // log.ClientBrowser = node.ChildNodes[3].InnerText; // log.ClientBrowserLanguage = node.ChildNodes[4].InnerText; // log.ClientJavaScriptSupport = node.ChildNodes[5].InnerText=="Yes"?true:false; // log.ClientNetRuntime = node.ChildNodes[6].InnerText; // log.ClientOS = node.ChildNodes[7].InnerText; // log.ClientOSLanguage = node.ChildNodes[8].InnerText; // log.ServerOS = node.ChildNodes[9].InnerText; // log.ServerNetRuntime = node.ChildNodes[10].InnerText; // log.ComputerName = node.ChildNodes[11].InnerText; // log.ErrorExecutionTrace = node.ChildNodes[12].InnerText; // log.ErrorMessage = node.ChildNodes[13].InnerText; // log.ErrorStackTrace = node.ChildNodes[14].InnerText; // log.ErrorURL = node.ChildNodes[15].InnerText; // log.LoginUser = node.ChildNodes[16].InnerText; // log.OrganizationID = node.ChildNodes[17].InnerText; // log.CreatedOn = node.ChildNodes[18].InnerText; // } // else // { // continue; // } // } // } // return log; //} ///// <summary> ///// Delete a ErrorLog according to the Errorlog ID ///// </summary> ///// <param name="strErrorLogID"></param> //public void DeleteErrorLog(Guid ErrorLogID) //{ // string[] files = Directory.GetFiles(LogConfig.Instance.ErrorLogPath, "ErrorLog*.xml", SearchOption.TopDirectoryOnly); // XmlDocument doc = new XmlDocument(); // foreach (string file in files) // { // doc.Load(file); // XmlElement root = doc.DocumentElement; // foreach (XmlNode node in root.ChildNodes) // { // if (node.FirstChild.InnerText == ErrorLogID.ToString()) // { // root.RemoveChild(node); // doc.Save(file); // return; // } // else // { // continue; // } // } // } //} private void WriteLog(ErrorLog message, string filepath) { if (File.Exists(filepath)) { AppendXML(message, filepath); } else { CreateNewXML(message, filepath); } }
private void GetGeneralLogDataAndUpload(bool bIsConnected, string strCurIP) { try { if (bIsConnected == false) { Tracer.Debug("连接打卡机失败,打卡机IP为:" + strCurIP); return; } DateTime dtFrom = new DateTime(); DateTime dtTo = new DateTime(); DateTime.TryParse(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), out dtFrom); dtTo = dtFrom.AddDays(1).AddSeconds(-1); if (TestMode == "true") { Tracer.Debug("测试模式下开始下载打卡记录:下载时间段:" + dtFrom.ToString("yyyy-MM-dd HH:mm:ss") + " 截止日期:" + dtTo.ToString("yyyy-MM-dd HH:mm:ss")); } //DateTime.TryParse(DateTime.Now.AddSeconds(-1).ToString(), out dtTo); int idwTMachineNumber = 0; int idwEnrollNumber = 0; int idwEMachineNumber = 0; int idwVerifyMode = 0; int idwInOutMode = 0; int idwYear = 0; int idwMonth = 0; int idwDay = 0; int idwHour = 0; int idwMinute = 0; List<T_HR_EMPLOYEECLOCKINRECORD> entTempList = new List<T_HR_EMPLOYEECLOCKINRECORD>(); entTempList.Clear(); axCZKEM1.EnableDevice(iMachineNumber, false);//disable the device if (axCZKEM1.ReadGeneralLogData(iMachineNumber))//read all the attendance records to the memory { if (bIsNewDevice) { string sdwEnrollNumber = string.Empty; int idwSecond = 0; int idwWorkcode = 0; while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory { DateTime dtCurrent = new DateTime(); DateTime.TryParse(idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString(), out dtCurrent); if (dtCurrent < dtFrom) { continue; } if (dtCurrent >= dtTo) { continue; } T_HR_EMPLOYEECLOCKINRECORD entTemp = new T_HR_EMPLOYEECLOCKINRECORD(); entTemp.CLOCKINRECORDID = System.Guid.NewGuid().ToString().ToUpper(); entTemp.FINGERPRINTID = sdwEnrollNumber; entTemp.CLOCKID = idwWorkcode.ToString(); entTemp.PUNCHDATE = DateTime.Parse(dtCurrent.ToString("yyyy-MM-dd") + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString()); entTemp.PUNCHTIME = idwHour.ToString() + ":" + idwMinute.ToString(); entTempList.Add(entTemp); } } else { while (axCZKEM1.GetGeneralLogData(iMachineNumber, ref idwTMachineNumber, ref idwEnrollNumber, ref idwEMachineNumber, ref idwVerifyMode, ref idwInOutMode, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute))//get records from the memory { DateTime dtCurrent = new DateTime(); DateTime.TryParse(idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString(), out dtCurrent); if (dtCurrent < dtFrom) { continue; } if (dtCurrent >= dtTo) { continue; } T_HR_EMPLOYEECLOCKINRECORD entTemp = new T_HR_EMPLOYEECLOCKINRECORD(); entTemp.CLOCKINRECORDID = System.Guid.NewGuid().ToString().ToUpper(); entTemp.FINGERPRINTID = idwEnrollNumber.ToString(); entTemp.CLOCKID = idwTMachineNumber.ToString(); entTemp.PUNCHDATE = DateTime.Parse(dtCurrent.ToString("yyyy-MM-dd") + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":00"); entTemp.PUNCHTIME = idwHour.ToString() + ":" + idwMinute.ToString(); entTempList.Add(entTemp); } } } axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device axCZKEM1.Disconnect(); int count = entTempList.Count(); if (count == 0) { string msg = DateTime.Now.ToString() + ",连接打卡机下载的记录数为0,请联系管理员检查打卡机是否正常,打卡机IP为:" + strCurIP; Tracer.Debug(msg); SMT.Foundation.Log.LogManager log = new SMT.Foundation.Log.LogManager(); Exception ex = new Exception(msg); ErrorLog msgsend = new ErrorLog(ex); log.SendMail(msgsend); } Tracer.Debug("下载打卡记录成功,打卡机IP为:" + strCurIP + "。已断开打卡机连接。下载记录数:"+entTempList.Count()); string strMsg = string.Empty; List<string> companyIds = new List<string>(); companyIds = GetCompanyID(strCurIP); foreach (var strCompanyId in companyIds) { if (TestMode == "true") { foreach (var ent in entTempList) { Tracer.Debug("员工指纹编码:"+ent.FINGERPRINTID + " 打卡时间:"+ ent.PUNCHDATE +":"+ ent.PUNCHTIME); } } else { clientAtt.ImportClockInRdListByWSRealTime(strCompanyId, entTempList.ToArray(), dtFrom, dtTo, strCurIP, ref strMsg); } Tracer.Debug("导入打卡记录成功,打卡机IP为:" + strCurIP + "。导入的公司ID为:" + strCompanyId); } } catch (Exception ex) { Tracer.Debug("导入打卡记录失败,打卡机IP为:" + strCurIP + "。失败原因为:" + ex.ToString()); } }
private void ImportRd() { if (clientAtt==null) clientAtt = new AttendanceServiceClient(); DateTime dtCur = DateTime.Now; if (string.IsNullOrWhiteSpace(strElapsedHour)) { Tracer.Debug(DateTime.Now.ToString() + ",导入打卡记录定时配置项(Key = ElapsedHour)未读取到"); return; } string[] ips = strIPs.Split(','); string[] companyIDs = strCompanyIDs.Split(','); listImportCompanys.Clear(); foreach (string companyID in companyIDs) { listImportCompanys.Add(companyID); } if (TestMode == "true") { if (dtCur.Hour.ToString() != TestElapsedHour) { Tracer.Debug(DateTime.Now.ToString() + ",导入打卡记录未在指定时间内"); return; } listImportIPs.Clear(); listImportIPs.Add(TestCompanyIp); Tracer.Debug("测试模式下,导入的公司ip为:" + listImportIPs[0].ToString() + ",导入开始"); } else { } if (dtCur.Hour != Convert.ToInt32(ConfigurationManager.AppSettings["ElapsedHour"])) { Tracer.Debug(DateTime.Now.ToString() + ",导入打卡记录未在指定时间内"); return; } Tracer.Debug(DateTime.Now.ToString() + ",开始导入打卡记录,设置的导入时间点为每天:" + strElapsedHour + " 点,导入的端口为:" + iPort); foreach (string str in ips) { listImportIPs.Add(str); Tracer.Debug(DateTime.Now.ToString() + ",导入的打卡机ip包括:" + str); } foreach (string companyID in companyIDs) { //strImportCompanys.Add(companyID); Tracer.Debug(DateTime.Now.ToString() + ",导入的公司ip包括:" + companyID); } try { foreach (string strCurIP in listImportIPs) { bool bIsConnected = false; bIsNewDevice = false; Tracer.Debug("开始连接打卡机,打卡机IP为:" + strCurIP + " 端口号:" + iPort); bIsConnected = axCZKEM1.Connect_Net(strCurIP, iPort); if (bIsConnected == true) { Tracer.Debug("连接打卡机成功,打卡机IP为:" + strCurIP); axCZKEM1.RegEvent(iMachineNumber, 65535); if (!string.IsNullOrWhiteSpace(strNewDevices)) { if (strNewDevices.Contains(strCurIP)) { bIsNewDevice = true; } } Tracer.Debug("开始下载打卡记录,打卡机IP为:" + strCurIP); GetGeneralLogDataAndUpload(bIsConnected, strCurIP); } else { string msg=DateTime.Now.ToString() + ",连接打卡机失败,请联系网管检查打卡机是否正常接入网络,打卡机IP为:" + strCurIP; Tracer.Debug(msg); SMT.Foundation.Log.LogManager log = new SMT.Foundation.Log.LogManager(); Exception ex = new Exception(msg); ErrorLog msgsend = new ErrorLog(ex); log.SendMail(msgsend); } } Tracer.Debug(DateTime.Now.ToString() + ",导入打卡记录全部完成"); } catch (Exception ex) { Tracer.Debug(DateTime.Now.ToString() + ",导入打卡记录发生异常,异常原因:" + ex.ToString()); } }
protected override void OnStop() { //服务停止 this.timerImportRd.Enabled = false; string msg = "定时打卡服务已停止,请确认是否异常停止。"; Tracer.Debug(msg); TestMode = "False"; TestCompanyIp = string.Empty; SMT.Foundation.Log.LogManager log = new SMT.Foundation.Log.LogManager(); Exception ex = new Exception(msg); ErrorLog msgsend = new ErrorLog(ex); log.SendMail(msgsend); Tracer.Debug( "定时打卡服务已停止,已发送邮件。"); Thread.Sleep(5000);//windows服务完全停止后,会将发送邮件的进程也停掉 Tracer.Debug("定时打卡服务已完全停止。"); }