public void UpLog() { if (IsUpExceptionData) { return; } DataTable dt = CRM_LogAnaysitContentBLL.GetLogInfoByIsUpload(0);//未上传的数据 if (dt != null && dt.Rows.Count > 0) { int Id = Convert.ToInt32(dt.Rows[0][0].ToString()); string fileName = dt.Rows[0][1].ToString(); string contents = dt.Rows[0][2].ToString(); string paramss = dt.Rows[0][3].ToString(); DataSet ds = CRM_LogAnaysitContentBLL.UpLogRunpro("YL_VehicleVisit8_M", paramss); if (ds != null && Convert.ToInt32(ds.Tables[0].Rows[0][0]) > 0) // 正常(没报异常) { CRM_LogAnaysitContentBLL.UpdateLog(Id, 1); // 数据(0:未上传,1:上传成功,-1上传失败) InsertListBox(string.Format("文件【{0}】数据上报成功:{1}", fileName, contents)); LogUtil.WriteInfo(string.Format("文件【{0}】数据上报成功:{1}", fileName, contents)); DictThread["UpLog"].Join(Joinms); } else { CRM_LogAnaysitContentBLL.UpdateLog(Id, -1); // 数据(0:未上传,1:上传成功,-1上传失败) InsertListBox(string.Format("文件【{0}】数据上报失败:{1}", fileName, contents)); LogUtil.WriteInfo(string.Format("文件【{0}】数据上报失败:{1}", fileName, contents)); DictThread["UpLog"].Join(Joinms); } } }
public void UpExceptionLogData() { if (!IsUpExceptionData || IsFinishUp) { return; } try { if (IsFirstExceptionData == 0) { CRM_LogAnaysitContentaAssistsBLL.PLDelete(); CRM_LogAnaysitContentaAssistsBLL.PLAdd(); IsFirstExceptionData = 1; } DataTable dt = CRM_LogAnaysitContentaAssistsBLL.QueryLogData(); if (dt != null && dt.Rows.Count > 0) { int logAssistID = Convert.ToInt32(dt.Rows[0][0]); int logID = Convert.ToInt32(dt.Rows[0][1]); string fileName = dt.Rows[0][2].ToString(); string contents = dt.Rows[0][3].ToString(); string paramss = dt.Rows[0][4].ToString(); DataSet ds = CRM_LogAnaysitContentBLL.UpLogRunpro("YL_VehicleVisit8_M", paramss); if (ds != null && Convert.ToInt32(ds.Tables[0].Rows[0][0]) > 0) // 正常(没报异常) { CRM_LogAnaysitContentBLL.UpdateLog(logID, 1); // 数据(0:未上传,1:上传成功,-1上传失败) CRM_LogAnaysitContentaAssistsBLL.Delete(logAssistID); InsertListBox(string.Format("文件【{0}】处理异常数据上报成功:{1}", fileName, contents)); LogUtil.WriteInfo(string.Format("文件【{0}】处理异常数据上报成功:{1}", fileName, contents)); DictThread["UpExceptionLogData"].Join(Joinms); } else { CRM_LogAnaysitContentaAssistsBLL.Delete(logAssistID); InsertListBox(string.Format("文件【{0}】处理异常数据上报失败:{1}", fileName, contents)); LogUtil.WriteInfo(string.Format("文件【{0}】处理异常数据上报失败:{1}", fileName, contents)); DictThread["UpExceptionLogData"].Join(Joinms); } } else { IsFinishUp = true; InsertListBox("处理异常数据已执行完毕!"); LogUtil.WriteInfo("处理异常数据已执行完毕!"); } } catch (Exception ex) { IsFinishUp = true; InsertListBox("处理异常数据异常:" + ex.Message); LogUtil.WriteInfo("处理异常数据异常:" + ex.Message); } }
/// <summary> /// 解析日志并上报数据库公共方法 /// </summary> /// <param name="fileName"></param> /// <param name="filePath"></param> /// <param name="Pro_Name"></param> /// <param name="td"></param> public void AnysisLog(string fileName, string filePath, string Pro_Name) { bool IsReading = false, IsFirst = true, IsMatch = false; string specialInfo = string.Empty, LogPrint = string.Empty; FileStream fs = null; //MemoryStream ms = new MemoryStream(File.ReadAllBytes(filePath)); StreamReader sr = null; try { fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); sr = new StreamReader(fs); #region 读流 while (sr.Peek() > -1) { //GC.Collect();// 垃圾回收,避免内存不足。 string info = sr.ReadLine(); if (info.Replace(" ", "").Length == 2 && info.Replace(" ", "") == "}]" && IsReading) { specialInfo += info.Replace("\\n", ""); specialInfo = "[{ LogPrint:\"" + LogPrint + "\"," + specialInfo; IsReading = false; IsFirst = true; List <UpDefinedVisit> upDefinedVisit = JsonHelper.DeserializeJsonToList <UpDefinedVisit>(specialInfo); if (!upDefinedVisit[0].inPos.bd.p.ToString().Contains(ContainsStr) && !upDefinedVisit[0].outPos.bd.p.ToString().Contains(ContainsStr)) { continue; } string parms1 = CRM_LogAnaysitContentBLL.Add(fileName, specialInfo, 1, upDefinedVisit, Pro_Name, 0); // 苹果数据 string parms2 = CRM_LogAnaysitContentBLL.AddType2(fileName, specialInfo, 1, upDefinedVisit, Pro_Name, 0, 0); // 苹果数据 DataSet ds = CRM_LogAnaysitContentBLL.UpLogRunpro("P_LogAnaysitTool_DefinedVisit", parms1); if (ds.Tables[0].Rows[0]["ack"].ToString() == "1") { int visitID = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]); for (int i = 0; i < upDefinedVisit[0].defined.Count; i++) { if (upDefinedVisit[0].defined[i].type == "Photo") { Photo photo = JsonHelper.DeserializeJsonToObject <Photo>(upDefinedVisit[0].defined[i].value); if (photo.photoId == "") { continue; } } string paramsstr = string.Format("@VisitID={0},@FieldID={1},@FieldValue='{2}'", visitID, upDefinedVisit[0].defined[i].markId, upDefinedVisit[0].defined[i].value); CRM_LogAnaysitContentBLL.UpLogRunpro("P_LogAnaysitTool_CusShopVisitItemInfo", paramsstr); } } else { LogUtil.WriteInfo("上传失败:" + parms1); } specialInfo = string.Empty; LogPrint = string.Empty; } if (IsReading) { specialInfo += info.Replace("\\n", ""); } if (info.Contains(Pro_Name) && info.Length <= 50 && IsFirst) { string json = CombineInsideSpaces(info.Substring(22)); string personID = info.Substring(23).Split('_')[0]; if (personID == "0") { LogPrint = info.Substring(0, 19); IsReading = true; IsFirst = false; IsMatch = true; } else { specialInfo = string.Empty; LogPrint = string.Empty; IsReading = false; IsFirst = true; continue; } } //do something } #endregion if (!IsMatch) { InsertListBox(string.Format("文件【{0}】没有匹配的数据!", fileName)); LogUtil.WriteInfo("文件【" + fileName + "】没有匹配的数据!"); } else { InsertListBox(string.Format("文件【{0}】已执行完毕(读日志)!", fileName)); LogUtil.WriteInfo("文件【" + fileName + "】已执行完毕(读日志)!"); } } //catch (OutOfMemoryException ex) //{ // InsertListBox(string.Format("文件【{0}】内存溢出,以文件流的形式重新调用【AnysisLog】", filePath)); // LogUtil.WriteInfo(string.Format("文件【{0}】内存溢出,以文件流的形式重新调用【AnysisLog】", filePath)); // AnysisLog(fileName, filePath, Pro_Name, 0); // return; //} catch (FileNotFoundException ex) { } catch (DirectoryNotFoundException ex) { } catch (Exception ex) { InsertListBox(string.Format("文件【{0}】,调用【AnysisLog】异常:{1})", filePath, ex.Message)); LogUtil.WriteInfo(string.Format("文件【{0}】,调用【AnysisLog】异常:{1})", filePath, ex.Message)); } finally { //if (ms != null) //{ // ms.Close(); // ms.Dispose(); //} if (fs != null) { fs.Close(); fs.Dispose(); } if (sr != null) { sr.Close(); sr.Dispose(); } } }