/// <summary> /// /// </summary> private Reply ReadReply() { List <ReplyLine> replyLines = new List <ReplyLine>(); while (true) { ReplyLine replyLine = new ReplyLine { Status = ReadStatus() }; replyLines.Add(replyLine); switch ((char)Receive(1)[0]) { case '-': replyLine.ReplyText = ReadReplyText(); break; case '+': replyLine.ReplyText = ReadReplyText(); // TODO(Zvp): data break; case ' ': // end reply line, can return here replyLine.ReplyText = ReadReplyText(); return(new Reply { ReplyLines = replyLines }); default: throw new MessengerException("Unexpected Divider, Expected '-', '+' or ' '."); } } }
/// <summary> /// /// </summary> /// <param name="reply"></param> private void ThrowIfNotOk(Reply reply) { if (!reply.IsOk) { ReplyLine replyLine = reply.ReplyLines.First(); throw new CommandException(replyLine.Status, replyLine.ReplyText); } }
/// <summary> /// /// </summary> /// <param name="replyLine"></param> /// <returns></returns> private Tuple <string, string> GetKeyValueFromReplyLine(ReplyLine replyLine) { if (replyLine.ReplyText.Contains("=")) { string[] keyValue = replyLine.ReplyText.Split(new char[] { '=' }); return(Tuple.Create(keyValue[0], keyValue[1])); } else { return(Tuple.Create(replyLine.ReplyText, string.Empty)); } }
/// <summary> /// /// </summary> /// <param name="keyword"></param> /// <returns></returns> public Tuple <string, string> GetConfiguration(string keyword) { // "GETCONF" 1*(SP keyword) CRLF Reply reply = _messenger.Send(new Command { Keyword = "GETCONF", Arguments = new object[] { keyword } }); ThrowIfNotOk(reply); ReplyLine replyLine = reply.ReplyLines.First(); return(GetKeyValueFromReplyLine(replyLine)); }