public void PostMessage(Message msg) { lock(m_WritingQueue) { m_WritingQueue.Enqueue(msg); Monitor.Pulse(m_WritingQueue); } }
public static Message Parse(string rawMessage) { Message msg = new Message(); if (rawMessage.StartsWith(":")) // has prefix { int indexOfSpace = rawMessage.IndexOf(" "); msg.m_prefix = rawMessage.Substring(1, indexOfSpace - 1); rawMessage = rawMessage.Substring(indexOfSpace + 1); } int indexOfCommandSpace = rawMessage.IndexOf(" "); if (indexOfCommandSpace != -1) { msg.m_command = rawMessage.Substring(0, indexOfCommandSpace); rawMessage = rawMessage.Substring(indexOfCommandSpace); // reserve this space int indexOfTrailing = rawMessage.IndexOf(" :"); // Space+Colon if (indexOfTrailing != -1) { if (indexOfTrailing == 0) { msg.m_parameters = new string[1]; msg.m_parameters[0] = rawMessage.Substring(2); } else { string beforeTrailing = rawMessage.Substring(0, indexOfTrailing); string trailing = rawMessage.Substring(indexOfTrailing + 2); string[] splits = beforeTrailing.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); msg.m_parameters = new string[splits.Length + 1]; Array.Copy(splits, msg.m_parameters, splits.Length); msg.m_parameters[msg.m_parameters.Length - 1] = trailing; } } else { string[] splits = rawMessage.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); msg.m_parameters = splits; } } else { msg.m_command = rawMessage; msg.m_parameters = new string[0]; } return msg; }