Ejemplo n.º 1
0
        public async Task ProcessQueueAsync(ISmsProcessor processor)
        {
            var queue = await TextMessageQueue.GetMailInQueueAsync(this.Database).ConfigureAwait(false);

            var config = new SmsConfig(this.Database, this.Processor);

            this.Processor = processor;

            if (this.IsEnabled())
            {
                foreach (var mail in queue)
                {
                    var message = SmsHelper.GetMessage(config, mail);

                    await processor.SendAsync(message).ConfigureAwait(false);

                    if (message.Status == Status.Completed)
                    {
                        mail.Delivered   = true;
                        mail.DeliveredOn = DateTimeOffset.UtcNow;

                        await TextMessageQueue.SetSuccessAsync(this.Database, mail.QueueId).ConfigureAwait(false);
                    }
                }
            }
        }