Exemplo n.º 1
0
        public MessagesBagStatus AddMessage(Message message)
        {
            if (_startMessagesSignature.Contains(message.Recipient))
            {
                if (this.Status != MessagesBagStatus.None)
                {
                    throw new MessageMisalignedException($"Received an StartMessege while current status is {this.Status}.");
                }

                this.MessageType = MessagesBag.GetMessageType(message.Recipient);
                this.Messages.Clear();

                return(this.Status = MessagesBagStatus.Open);
            }

            if (message.Recipient == _endMessageSignature)
            {
                if (this.Status != MessagesBagStatus.Collecting)
                {
                    throw new MessageMisalignedException($"Received an EndMessege while current status is {this.Status}.");
                }
                return(this.Status = MessagesBagStatus.Closed);
            }

            if (this.Status == MessagesBagStatus.Closed)
            {
                throw new MessageMisalignedException($"Received {message.Recipient} message while current status is {MessagesBagStatus.Closed}.");
            }

            if (_processableMessages.Contains(message.Recipient) == false)
            {
                throw new MessageMisalignedException($"Queue containing a message type not expected [{message.Recipient}].");
            }

            this.Messages.Add(new Message(MessagesBag.GetRecipient(message.Recipient), message.Body));

            return(this.Status = MessagesBagStatus.Collecting);
        }
Exemplo n.º 2
0
        public MessagesBagStatus AddMessage(Message message)
        {
            if (_startMessagesSignature.Contains(message.MessageType))
            {
                if (this.Status != MessagesBagStatus.Empty)
                {
                    throw new MessageMisalignedException($"Received an StartMessege while current status is {this.Status}.");
                }
                this.MessageType = MessagesBag.GetMessageType(message.MessageType);
                this.Messages.Clear();
                return(this.Status = MessagesBagStatus.Collecting);
            }

            if (message.MessageType == _endMessageSignature)
            {
                if (this.Status != MessagesBagStatus.Collecting)
                {
                    throw new MessageMisalignedException($"Received an EndMessege while current status is {this.Status}.");
                }
                return(this.Status = MessagesBagStatus.Ready);
            }

            if (this.Status == MessagesBagStatus.Ready)
            {
                throw new MessageMisalignedException($"Received {message.MessageType} message while current status is {MessagesBagStatus.Ready}.");
            }

            if (_processableMessages.Contains(message.MessageType) == false)
            {
                throw new MessageMisalignedException($"Queue containing a message type not expected [{message.MessageType}].");
            }

            this.Messages.Add(message);

            return(this.Status = MessagesBagStatus.Collecting);
        }