public List<MpdMessage> ReadChannelsMessages()
{
MpdResponse response = this.getConnection().Exec("readmessages");
if (response.IsError)
throw new MpdResponseException(response.ErrorCode, response.ErrorMessage);
List<MpdMessage> result = new List<MpdMessage>();
Regex LINE_REGEX = new Regex("^(?<key>[A-Z_a-z]*):[ ]{0,1}(?<value>.*)$");
string channel = string.Empty;
foreach (string line in response.Message) {
Match match = LINE_REGEX.Match(line);
if (match.Success) {
string key = match.Result("${key}");
string value = match.Result("${value}");
if (key != null && value != null) {
if (key == "channel")
channel = key;
else if (key == "message")
result.Add(new MpdMessage() { Channel = channel, Message = value, DateTime = DateTime.Now });
}
}
}
return result;
}