Ejemplo n.º 1
0
        private async Task _SendFailedAsync(Library.Queue.ITransaction <QueueItem> qResult, string message)
        {
            if (Int32.Parse(Config.AppSettings["MaximumSendTry"]) > qResult.Data.TryCount)
            {
                await _sendTryDataSource.CreateTrySendAsync(new SendTry
                {
                    ReceiverMessageID = qResult.Data.Id
                    ,
                    Message = message
                });

                _queueService.Enqueue(qResult.Data);
            }
            else
            {
                await _messageDataSource.SetSendAsync(new Send
                {
                    ReceiverMessageID = qResult.Data.Data.MessageReceiver.ID
                    ,
                    IsSent = false
                    ,
                    Message = message
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loops till message queue become empty then stop looping
        /// </summary>
        /// <returns></returns>
        public async Task <AppCore.Result> ProcessAsync()
        {
            /*check if current priority is empty or not if is empty
             * then swich to other priorities,
             * if all priorities all empty then set Running to false
             */
            if (_queueService.QueueCount(QueueHelper.Instance.CurrentPriority).Equals(0))
            {
                QueueHelper.Instance.Next(_queueService);
            }

            /*
             * Loop While queue message become empty
             */
            while (QueueHelper.Instance.Running)
            {
                Library.Queue.ITransaction <QueueItem> qResult = null;
                try
                {
                    qResult = _queueService.Dequeue(QueueHelper.Instance.CurrentPriority, TimeSpan.FromMilliseconds(300));

                    var sendResult = await _SendAsync(qResult.Data.Data.MessageReceiver);

                    if (!sendResult.Success)
                    {
                        await _SendFailedAsync(qResult, sendResult.Message);
                    }
                    else
                    {
                        await _messageDataSource.SetSendAsync(new Send
                        {
                            ReceiverMessageID = qResult.Data.Data.MessageReceiver.ID
                            ,
                            IsSent = true
                            ,
                            Message = "Message was Sent Successfully"
                        });
                    }
                }
                catch (Exception e)
                {
                    _logger?.Error(e);
                    await _SendFailedAsync(qResult, e.Message);
                }
                finally
                {
                    QueueHelper.Instance.Next(_queueService);
                }
            }

            return(AppCore.Result.Successful());
        }
        public async Task <AppCore.Result> ProcessAsync()
        {
            if (_queueService.QueueCount(QueueHelper.Instance.CurrentPriority).Equals(0))
            {
                QueueHelper.Instance.Next(_queueService);
            }

            while (QueueHelper.Instance.Running)
            {
                Library.Queue.ITransaction <Model.QueueItem> qResult = null;
                try
                {
                    qResult = _queueService.Dequeue(QueueHelper.Instance.CurrentPriority, TimeSpan.FromMilliseconds(300));

                    var sendResult = await _SendAsync(qResult.Data.Data.Mail);

                    if (!sendResult.Success)
                    {
                        await _SendFailedAsync(qResult, sendResult.Message);
                    }
                    else
                    {
                        await _messageDataSource.SetSendAsync(new Model.Send
                        {
                            MailID = qResult.Data.Id
                            ,
                            IsSent = true
                            ,
                            Message = "Message was sent successfully"
                        });
                    }
                }
                catch (Exception e)
                {
                    _logger?.Error(e);
                    await _SendFailedAsync(qResult, e.Message);
                }
                finally
                {
                    QueueHelper.Instance.Next(_queueService);
                }
            }

            return(AppCore.Result.Successful());
        }