public static void SendAllQueuedMessages() { using (var dataBinding = new MessageDataAccessor()) { dataBinding.RemoveBarredMessages(); List<MessageEntity> list = new List<MessageEntity>(); ICollection<MessageQueueEntity> queueList = dataBinding.GetTopQueuedMessages(); while (queueList.Count > 0) { list.Clear(); foreach (var message in queueList) { list.Add(new MessageEntity() { NumberTo = message.Number, Text = message.Text, OriginId = message.OriginId, UniqueId = message.UniqueId }); } // send the list of 1000 SendSMS(list); // if sent successfully we remove the item from the queue foreach (MessageEntity message in list) { dataBinding.RemoveSentMessages(message.UniqueId); } queueList = dataBinding.GetTopQueuedMessages(); } } }
public static void SendQueuedMessages(Guid batchId) { using (var dataBinding = new MessageDataAccessor()) { List<MessageEntity> list = new List<MessageEntity>(); foreach (var message in dataBinding.GetQueuedMessages(batchId)) { list.Add(new MessageEntity() { NumberTo = message.Number, Text = message.Text, OriginId = message.OriginId, UniqueId = message.UniqueId }); } SendSMS(list); // if sent successfully we remove the item from the queue foreach (MessageEntity message in list) { dataBinding.RemoveSentMessages(message.UniqueId); } } }