public static IEnumerable <DequeuedMessage> Dequeue(int count) { var emailQueue = DataController.GetEmailQueue(); var messages = emailQueue.GetMessages(count); foreach (var message in messages) { using (var memoryStream = new MemoryStream(message.AsBytes)) { var emailMessage = EmailMessage.Deserialize(memoryStream); yield return(new DequeuedMessage(message, emailQueue, emailMessage)); } } }
public EmailMessage Get(string id) { using (SqlEmailServiceContext configContext = new SqlEmailServiceContext(this.nameOrConnectionString)) { Guid itemID = new Guid(id); EmailQueueItem item = configContext.EmailQueueItems.FirstOrDefault(x => x.ID == itemID && x.SendDate == null); if (item != null) { EmailMessage message = EmailMessage.Deserialize(item.Message); message.ErrorMessage = item.ErrorMessage; message.SendDate = item.SendDate; message.RetryAttempt = item.RetryAttempt; return(message); } } return(null); }