Exemple #1
0
 /// <summary>
 /// Triggers queue created, updated or deleted events
 /// </summary>
 public void Trigger(HorseQueue queue, string node = null)
 {
     base.Trigger(new QueueEvent
     {
         Name             = queue.Name,
         Topic            = queue.Topic,
         Status           = queue.Status.ToString(),
         Messages         = queue.MessageCount(),
         PriorityMessages = queue.PriorityMessageCount(),
         Node             = node
     });
 }
        /// <summary>
        /// Finds and dequeues a message from the queue.
        /// If there is not message, returns null
        /// </summary>
        private async Task <Tuple <QueueMessage, int, int> > DequeueMessage(bool fifo, bool getInfo, ClearDecision clear)
        {
            QueueMessage message          = null;
            int          prioMessageCount = 0;
            int          messageCount     = 0;

            await _queue.RunInListSync(() =>
            {
                //pull from prefential messages
                if (_queue.PriorityMessagesList.Count > 0)
                {
                    if (fifo)
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        message = _queue.PriorityMessagesList.First.Value;
                        _queue.PriorityMessagesList.RemoveFirst();
                    }
                    else
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        message = _queue.PriorityMessagesList.Last.Value;
                        _queue.PriorityMessagesList.RemoveLast();
                    }

                    if (message != null)
                    {
                        message.IsInQueue = false;
                    }
                }

                //if there is no prefential message, pull from standard messages
                if (message == null && _queue.MessagesList.Count > 0)
                {
                    if (fifo)
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        message = _queue.MessagesList.First.Value;
                        _queue.MessagesList.RemoveFirst();
                    }
                    else
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        message = _queue.MessagesList.Last.Value;
                        _queue.MessagesList.RemoveLast();
                    }

                    if (message != null)
                    {
                        message.IsInQueue = false;
                    }
                }

                if (getInfo)
                {
                    prioMessageCount = _queue.PriorityMessageCount();
                    messageCount     = _queue.MessageCount();
                }

                if (clear == ClearDecision.All)
                {
                    _queue.ClearAllMessages();
                }

                else if (clear == ClearDecision.HighPriority)
                {
                    _queue.ClearHighPriorityMessages();
                }

                else if (clear == ClearDecision.DefaultPriority)
                {
                    _queue.ClearRegularMessages();
                }
            });

            return(new Tuple <QueueMessage, int, int>(message, prioMessageCount, messageCount));
        }