virtual public void Execute() { while (true) { LogData data; //double check lock (_dataQueue) { if (_dataQueue.Count > 0) { lock (_dataQueue) { data = _dataQueue.Dequeue(); } //判断是否需要打印起始行 if (!_hadLogFiles.Contains(data._type.ToString())) { MyFileStream.WriteFile(_logFileFullPath, data._type.ToString(), string.Format("<-begin line 文件名-数据 {0}->", DateTime.Now.ToString())); _hadLogFiles.Add(data._type.ToString()); } //打印 MyFileStream.WriteFile(_logFileFullPath, data._type.ToString(), data._data); } } } }
/// <summary> /// 输出峰值到peaks文件 /// </summary> /// <param name="_curFullPath"></param> /// <param name="fileFullName"></param> /// <param name="peaks"></param> private void OutPutPeaks(string _curFullPath, string fileFullName, UInt32[] peaks) { if (peaks.Length < 2) { MyFileStream.WriteFile(_curFullPath + "\\数据", "peaks", string.Format("<-start 峰值-文件名-时间-序号 {0};{1}->", DateTime.Now.ToString(), _counter++)); return; } //控制台 Console.WriteLine("文件:{0}\t峰值a:{1} 峰值b:{2}", fileFullName, peaks[0], peaks[1]); //文件 MyFileStream.WriteFile(_curFullPath + "\\数据", "peaks", string.Format("{0} {1}\t{2};\t{3}\t{4}", peaks[0], peaks[1], fileFullName, DateTime.Now.ToString(), _counter++)); }
/// <summary> /// 初始化 /// 1。扫描所有文件 /// 2。读取文件所有内容 /// </summary> private void Init() { if (!MyFileStream.ScanAllFiles(_path, out _allFiles) || _allFiles.Count <= 0) { return; } foreach (string fileFullName in _allFiles.Values) { if (!ReadAndDecodeFile(fileFullName)) { //读取文件失败 _allFiles.Remove(fileFullName); } } }
/// <summary> /// 读取一个文件的所有行,并解析 /// </summary> /// <param name="fileFullName"></param> private bool ReadAndDecodeFile(string fileFullName) { Dictionary <UInt32, string> lineDic; //读取文件的内容 if (!MyFileStream.ReadFileLines(fileFullName, out lineDic) || lineDic.Count <= 0) { return(false); } //获取每一行的date, 和对应的值 foreach (string line in lineDic.Values) { //获取一行的数值 UInt32 date = GetLineDate(line); UInt32 value = GetLineValue(line); //放进字典 AddDic(fileFullName, date, value); } return(true); }