Exemplo n.º 1
0
        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();
                }           
            }

        }