public async Task <Result <IRetrievedMessages> > GetMessages(TimeSpan visibilityTimeout, CancellationToken ct) { try { var cloudQueueMessages = await queue.GetMessagesAsync(CloudQueueMessage.MaxNumberOfMessagesToPeek, visibilityTimeout, null, null, ct).ConfigureAwait(false); var retrievedMessages = new RetrievedMessages(cloudQueueMessages.Select(m => new Message(m.Id, m.AsBytes, m.PopReceipt, m.DequeueCount)).ToArray()); return(new Result <IRetrievedMessages>(HttpStatusCode.OK, retrievedMessages)); } catch (StorageException ex) { return(FromException <IRetrievedMessages>(ex)); } }
public bool ProcessCommand(string command) { if (command.ToLower().StartsWith("quit")) { // Remove the messages... DeletedMessages.Sort(); DeletedMessages.Reverse(); foreach (int deletedMessage in DeletedMessages) { _messages.RemoveAt(deletedMessage - 1); } return(false); } if (command.ToLower().StartsWith("user")) { Send("+OK\r\n"); return(true); } if (command.ToLower().StartsWith("capa")) { string capabilities = "USER\r\nUIDL\r\nTOP\r\n"; if (_connectionSecurity == eConnectionSecurity.eCSSTARTTLSRequired || _connectionSecurity == eConnectionSecurity.eCSSTARTTLSOptional) { capabilities += "STLS\r\n"; } string response = "+OK CAPA list follows\r\n" + capabilities + "." + "\r\n"; Send(response); return(true); } if (command.ToLower().StartsWith("stls")) { Send("+OK Begin TLS negotiation\r\n"); _tcpConnection.HandshakeAsServer(SslSetup.GetCertificate()); return(true); } if (command.ToLower().StartsWith("pass")) { Send("+OK\r\n"); return(true); } if (command.ToLower().StartsWith("uidl")) { if (!SupportsUIDL) { Send("-ERR unhandled command\r\n"); return(true); } Send("+OK\r\n"); for (int i = 0; i < _messages.Count; i++) { Send(string.Format("{0} UniqueID-{1}\r\n", i + 1, _messages[i].GetHashCode())); } Send(".\r\n"); return(true); } if (command.ToLower().StartsWith("retr")) { command = command.Substring(5); command = command.TrimEnd('\n'); command = command.TrimEnd('\r'); int messageID = Convert.ToInt32(command); RetrievedMessages.Add(messageID); string message = _messages[messageID - 1]; switch (SendBufferMode) { case BufferMode.Split: { Send("+OK\r\n"); Send(message); Send("\r\n.\r\n"); break; } case BufferMode.SingleBuffer: { Send("+OK\r\n" + message + "\r\n.\r\n"); break; } case BufferMode.MessageAndTerminatonTogether: { Send("+OK\r\n"); Send(message + "\r\n.\r\n"); break; } } if (DisconnectAfterRetrCompletion) { return(false); } return(true); } if (command.ToLower().StartsWith("dele")) { command = command.Substring(5); command = command.TrimEnd('\n'); command = command.TrimEnd('\r'); int messageID = Convert.ToInt32(command); DeletedMessages.Add(messageID); Send("+OK\r\n"); return(true); } return(true); }
public bool ProcessCommand(string command) { if (command.ToLower().StartsWith("quit")) { // Remove the messages... DeletedMessages.Sort(); DeletedMessages.Reverse(); foreach (int deletedMessage in DeletedMessages) { _messages.RemoveAt(deletedMessage - 1); } return(false); } if (command.ToLower().StartsWith("user")) { Send("+OK\r\n"); return(true); } if (command.ToLower().StartsWith("pass")) { Send("+OK\r\n"); return(true); } if (command.ToLower().StartsWith("uidl")) { if (!SupportsUIDL) { Send("-ERR unhandled command\r\n"); return(true); } Send("+OK\r\n"); for (int i = 0; i < _messages.Count; i++) { Send(string.Format("{0} UniqueID-{1}\r\n", i + 1, _messages[i].GetHashCode())); } Send(".\r\n"); return(true); } if (command.ToLower().StartsWith("retr")) { command = command.Substring(5); command = command.TrimEnd('\n'); command = command.TrimEnd('\r'); int messageID = Convert.ToInt32(command); RetrievedMessages.Add(messageID); string message = _messages[messageID - 1]; Send("+OK\r\n"); Send(message); Send("\r\n.\r\n"); return(true); } if (command.ToLower().StartsWith("dele")) { command = command.Substring(5); command = command.TrimEnd('\n'); command = command.TrimEnd('\r'); int messageID = Convert.ToInt32(command); DeletedMessages.Add(messageID); Send("+OK\r\n"); return(true); } return(true); }