예제 #1
0
        /// <summary>
        /// Sets status of the queue
        /// </summary>
        public async Task SetStatus(QueueStatus status, IMessageDeliveryHandler newDeliveryHandler = null)
        {
            QueueStatus prevStatus = Status;
            IQueueState prevState  = State;

            if (prevStatus == status)
            {
                return;
            }

            QueueStatusAction leave = await State.LeaveStatus(status);

            if (leave == QueueStatusAction.Deny)
            {
                return;
            }

            if (leave == QueueStatusAction.DenyAndTrigger)
            {
                await Trigger();

                return;
            }

            Status = status;
            State  = QueueStateFactory.Create(this, status);

            QueueStatusAction enter = await State.EnterStatus(prevStatus);

            if (enter == QueueStatusAction.Deny || enter == QueueStatusAction.DenyAndTrigger)
            {
                Status = prevStatus;
                State  = prevState;
                await prevState.EnterStatus(prevStatus);

                if (enter == QueueStatusAction.DenyAndTrigger)
                {
                    await Trigger();
                }

                return;
            }

            if (Channel.EventHandler != null)
            {
                await Channel.EventHandler.OnQueueStatusChanged(this, prevStatus, status);
            }

            if (enter == QueueStatusAction.AllowAndTrigger)
            {
                _ = Trigger();
            }
        }
예제 #2
0
        /// <summary>
        /// Sets status of the queue
        /// </summary>
        public async Task SetStatus(QueueStatus status, IMessageDeliveryHandler newDeliveryHandler = null)
        {
            QueueStatus prevStatus = Status;

            try
            {
                IQueueState prevState = State;
                if (prevStatus == status)
                {
                    return;
                }

                QueueStatusAction leave = await State.LeaveStatus(status);

                if (leave == QueueStatusAction.Deny)
                {
                    return;
                }

                if (leave == QueueStatusAction.DenyAndTrigger)
                {
                    await Trigger();

                    return;
                }

                Status = status;
                State  = QueueStateFactory.Create(this, status);

                QueueStatusAction enter = await State.EnterStatus(prevStatus);

                if (enter == QueueStatusAction.Deny || enter == QueueStatusAction.DenyAndTrigger)
                {
                    Status = prevStatus;
                    State  = prevState;
                    await prevState.EnterStatus(prevStatus);

                    if (enter == QueueStatusAction.DenyAndTrigger)
                    {
                        await Trigger();
                    }

                    return;
                }

                if (newDeliveryHandler != null)
                {
                    DeliveryHandler = newDeliveryHandler;
                }

                foreach (IQueueEventHandler handler in Server.QueueEventHandlers)
                {
                    await handler.OnStatusChanged(this, prevStatus, status);
                }

                if (enter == QueueStatusAction.AllowAndTrigger)
                {
                    _ = Trigger();
                }
            }
            catch (Exception e)
            {
                Server.SendError("SET_QUEUE_STATUS", e, $"QueueName:{Name}, PrevStatus:{prevStatus} NextStatus:{status}");
            }
        }