/// <summary> /// 读取指定设备的采集点的日志数据 /// </summary> /// <param name="dtuID"></param> /// <param name="dataPointID"></param> /// <param name="date"></param> /// <returns></returns> public LogCollection ReadDPLog(string zdID, string mac, DateTime date, int pageNum, int pageSize, ReadLogDataType lType) { LogCollection str = new LogCollection() { Rows = 0, ListTxtMessage = new List <TxtMessage>() }; string basePath = path.Substring(0, path.LastIndexOf("\\")); string fileName = string.Empty; if (lType == ReadLogDataType.DTU) { fileName = basePath + string.Format("\\Log\\{0:yyyyMMdd}\\ZD-{1}.txt", date, zdID); } else if (lType == ReadLogDataType.System) { fileName = basePath + string.Format("\\Log\\{0:yyyyMMdd}\\Log.log", date); } else if (lType == ReadLogDataType.OneMeterData) { // return new LogStreamWriter(path + string.Format("\\Log\\OneMeterData\\{0:yyyyMMdd}\\{1:yyyyMMddHH}.txt", now, mac)); fileName = basePath + string.Format("\\Log\\OneMeterData\\{0:yyyyMMdd}\\{1}.txt", date, mac); } if (File.Exists(fileName)) { FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // 创建一个数据流读入器,和打开的文件关联 StreamReader srMyfile = new StreamReader(fs); try { // 把文件指针重新定位到文件的开始 srMyfile.BaseStream.Seek(0, SeekOrigin.Begin); // 打印文件文本内容 int sIndex = (pageNum - 1) * pageSize; int eIndex = (pageNum) * pageSize; int sCount = 0; string s1; while ((s1 = srMyfile.ReadLine()) != null) { if (s1 != "") { if (sCount >= sIndex && sCount < eIndex) { str.ListTxtMessage.Add(new TxtMessage() { Message = s1 }); } sCount++; } } str.Rows = sCount; } catch { } finally { srMyfile.Close(); fs.Close(); } } else { TxtMessage t = new TxtMessage(); if (lType == ReadLogDataType.DTU) { t.Message = string.Format("设备:{0},{1}日调度记录不存在。", zdID, date.ToString("yyyyMMdd")); } else if (lType == ReadLogDataType.System) { t.Message = string.Format("{0}月系统信息日志记录不存在。", date.ToString("yyyyMM")); } else if (lType == ReadLogDataType.OneMeterData) { t.Message = string.Format("表:{0},{1}日志记录不存在。", mac, date.ToString("yyyyMMdd")); } str.Rows = 1; str.ListTxtMessage.Add(t); } return(str); }
/// <summary> /// 获取日志文件 /// </summary> /// <param name="cjdID"></param> /// <param name="mac"></param> /// <param name="date"></param> /// <param name="pageNum"></param> /// <param name="pageSize"></param> /// <param name="lType"></param> /// <returns></returns> public LogCollection getDCSLog(string cjdID, string mac, DateTime date, int pageNum, int pageSize, ReadLogDataType lType) { return(Log.getInstance().ReadDPLog(cjdID, mac, date, pageNum, pageSize, lType)); }
/// <summary> /// 获取采集端日志信息 /// </summary> /// <param name="cjdID"></param> /// <param name="mac"></param> /// <param name="date"></param> /// <param name="pageNum"></param> /// <param name="pageSize"></param> /// <param name="lType"></param> /// <returns></returns> public LogCollection GetDCSLog(string cjdID, string mac, DateTime date, int pageNum, int pageSize, ReadLogDataType lType) { DCSService dscService = DCSRegister.getInstance().getDcsSevice(cjdID); if (dscService != null) { return(dscService.getIDCSClient.getDCSLog(cjdID, mac, date, pageNum, pageSize, lType)); } else { return(new LogCollection() { ListTxtMessage = new List <TxtMessage>(), Rows = 0 }); } }