public bool Analy() { List<KeyValuePair<DateTime, string>> receiveLines = LoadLines(_receiveFilePath); List<KeyValuePair<DateTime, string>> sendLines = LoadLines(_sendFilePath); try { List<KeyValuePair<byte, bool>> messageQueue = new List<KeyValuePair<byte, bool>>(); //KeyValuePair<byte, bool>表示一个字节,byte指示字节的值,bool表示字节是否可用,若为false则表示改字节已被取走 ComponentAnalyzer componentAnalyzer = new ComponentAnalyzer(sendLines); OleDbConnection oleDbCon = DatabaseConnection.GetConnection(); oleDbCon.Open(); for(int lineIndex = 0; lineIndex < receiveLines.Count; ++lineIndex) { string line = receiveLines[lineIndex].Value; DateTime time = receiveLines[lineIndex].Key; byte[] data = Transfer.SToBa(line); foreach(byte b in data) messageQueue.Add(new KeyValuePair<byte, bool>(b, true)); if (messageQueue.Count >= 2000) throw new Exception("消息队列过长!"); //测试代码,测试对解析到哪儿 Console.Write("完成" + (lineIndex * 100 / receiveLines.Count) + "%"); Console.WriteLine("解析到" + time.ToString()); int componentId, azimuth, obliquity; componentAnalyzer.Analy(time,messageQueue, out componentId, out azimuth, out obliquity); VIAnalyzer.Analy(time, messageQueue, oleDbCon, componentId, azimuth, obliquity); QXAnalyzer.Analy(time, messageQueue, oleDbCon); while(true) { //删掉队首已被取走的字节 while (messageQueue.Count != 0 && !messageQueue[0].Value) messageQueue.RemoveAt(0); int indexOfFirstNotUse = -1; for (int i = 0; i < messageQueue.Count; ++i) { if (!messageQueue[i].Value) { indexOfFirstNotUse = i; break; } } //如果队列中没有被取走的字节,说明没有出错 if (indexOfFirstNotUse == -1) break; //取走队列中的出错的数据 List<byte> errorData = new List<byte>(); for (int i = 0; i < indexOfFirstNotUse; ++i) { errorData.Add(messageQueue[i].Key); messageQueue[i] = new KeyValuePair<byte, bool>(messageQueue[i].Key, false); } _errorLog.Add("Error#" + time + "#" + lineIndex + "#" + Transfer.BaToS(errorData.ToArray())); } } oleDbCon.Close(); } catch(Exception ex) { throw new Exception(_receiveFilePath + "解析失败:" + ex.Message, ex); } return true; }
public bool Analy() { List <KeyValuePair <DateTime, string> > receiveLines = LoadLines(_receiveFilePath); List <KeyValuePair <DateTime, string> > sendLines = LoadLines(_sendFilePath); try { List <KeyValuePair <byte, bool> > messageQueue = new List <KeyValuePair <byte, bool> >(); //KeyValuePair<byte, bool>表示一个字节,byte指示字节的值,bool表示字节是否可用,若为false则表示改字节已被取走 ComponentAnalyzer componentAnalyzer = new ComponentAnalyzer(sendLines); OleDbConnection oleDbCon = DatabaseConnection.GetConnection(); oleDbCon.Open(); for (int lineIndex = 0; lineIndex < receiveLines.Count; ++lineIndex) { string line = receiveLines[lineIndex].Value; DateTime time = receiveLines[lineIndex].Key; byte[] data = Transfer.SToBa(line); foreach (byte b in data) { messageQueue.Add(new KeyValuePair <byte, bool>(b, true)); } if (messageQueue.Count >= 2000) { throw new Exception("消息队列过长!"); } //测试代码,测试对解析到哪儿 Console.Write("完成" + (lineIndex * 100 / receiveLines.Count) + "%"); Console.WriteLine("解析到" + time.ToString()); int componentId, azimuth, obliquity; componentAnalyzer.Analy(time, messageQueue, out componentId, out azimuth, out obliquity); VIAnalyzer.Analy(time, messageQueue, oleDbCon, componentId, azimuth, obliquity); QXAnalyzer.Analy(time, messageQueue, oleDbCon); while (true) { //删掉队首已被取走的字节 while (messageQueue.Count != 0 && !messageQueue[0].Value) { messageQueue.RemoveAt(0); } int indexOfFirstNotUse = -1; for (int i = 0; i < messageQueue.Count; ++i) { if (!messageQueue[i].Value) { indexOfFirstNotUse = i; break; } } //如果队列中没有被取走的字节,说明没有出错 if (indexOfFirstNotUse == -1) { break; } //取走队列中的出错的数据 List <byte> errorData = new List <byte>(); for (int i = 0; i < indexOfFirstNotUse; ++i) { errorData.Add(messageQueue[i].Key); messageQueue[i] = new KeyValuePair <byte, bool>(messageQueue[i].Key, false); } _errorLog.Add("Error#" + time + "#" + lineIndex + "#" + Transfer.BaToS(errorData.ToArray())); } } oleDbCon.Close(); } catch (Exception ex) { throw new Exception(_receiveFilePath + "解析失败:" + ex.Message, ex); } return(true); }