public Message Parse(string msg) { Message result = null; try { string Comd = ""; Dictionary<string, string> dictionary = new Dictionary<string, string>(); string[] msgs = msg.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (msgs.Length < 4) { msgs = new string[4]; msgs[0] = ""; msgs[1] = ""; msgs[2] = ""; msgs[3] = ""; } Comd = msgs[0]; dictionary.Add("BillNo", msgs[1]); dictionary.Add("Result", msgs[2]); dictionary.Add("MSG", msgs[3]); result = new Message(true, msg, Comd, dictionary); } catch { result = new Message(msg); } return result; }
private void client_OnReceive(object sender, ReceiveEventArgs e) { Message message = null; if (null != protocol) message = protocol.Parse(e.Read(10)); else { message = new Message(e.Read()); } string text = string.Format("recv: <--- {0}", e.Read()); WriteToLog(text); if (message.Parsed) DispatchState(message.Command, message.Parameters); dtTime = DateTime.Now; }