Exemplo n.º 1
0
        StringContent CreateMessageEntityBody(Message message)
        {
            var messageToSend = new RestMSMessage
            {
                Address   = message.Header.Topic,
                MessageId = message.Header.Id.ToString(),
                Content   = new RestMSMessageContent
                {
                    Value    = message.Body.Value,
                    Type     = MediaTypeNames.Text.Plain,
                    Encoding = Encoding.ASCII.WebName
                }
            };

            var messageHeaders = new List <RestMSMessageHeader> {
                new RestMSMessageHeader {
                    Name = "MessageType", Value = message.Header.MessageType.ToString()
                }
            };

            messageHeaders.AddRange(message.Header.Bag.Select(customHeader => new RestMSMessageHeader {
                Name = customHeader.Key, Value = Encoding.ASCII.GetString((byte[])customHeader.Value)
            }));

            messageToSend.Headers = messageHeaders.ToArray();

            string messageContent;

            if (!XmlRequestBuilder.TryBuild(messageToSend, out messageContent))
            {
                return(null);
            }
            return(new StringContent(messageContent));
        }
Exemplo n.º 2
0
        private static MessageHeader ReadMessageHeaders(RestMSMessage restMSMessage)
        {
            var messageId = Guid.Empty;

            if (!Guid.TryParse(restMSMessage.MessageId, out messageId))
            {
                return(FailureMessageHeader(messageId, restMSMessage.Address));
            }

            var messageType = MessageType.MT_NONE;

            if (restMSMessage.Headers == null || !restMSMessage.Headers.Any())
            {
                return(FailureMessageHeader(messageId, restMSMessage.Address));
            }

            var messageTypeString = restMSMessage.Headers.First(header => header.Name == "MessageType").Value;

            if (messageTypeString == null)
            {
                return(FailureMessageHeader(messageId, restMSMessage.Address));
            }

            if (!Enum.TryParse <MessageType>(messageTypeString, out messageType))
            {
                return(FailureMessageHeader(messageId, restMSMessage.Address));
            }

            var messageHeader = new MessageHeader(messageId, restMSMessage.Address, messageType);

            restMSMessage.Headers.Each(header => messageHeader.Bag.Add(header.Name, header.Value));
            return(messageHeader);
        }
Exemplo n.º 3
0
        public static Message CreateMessage(RestMSMessage restMSMessage)
        {
            var header = ReadMessageHeaders(restMSMessage);
            var body   = ReadMessageBody(restMSMessage);

            return(new Message(header, body));
        }
Exemplo n.º 4
0
        NameValueCollection GetHeadersFromMessage(RestMSMessage messageSpecification)
        {
            var headers = new NameValueCollection();

            if (messageSpecification.Headers != null)
            {
                messageSpecification.Headers.Each(header => headers.Add(header.Name, header.Value));
            }
            return(headers);
        }
Exemplo n.º 5
0
        private static MessageBody ReadMessageBody(RestMSMessage restMSMessage)
        {
            var srcEncoding = Encoding.GetEncoding(0);

            if (restMSMessage.Content.Encoding == "QuotedPrintable" || restMSMessage.Content.Encoding == "Plain")
            {
                srcEncoding = Encoding.ASCII;
            }
            //TODO: Handle base64 messages which are allowed by specification

            var bytes = srcEncoding.GetBytes(restMSMessage.Content.Value);
            var body  = Encoding.Convert(srcEncoding, Encoding.Unicode, bytes);

            return(new MessageBody(Encoding.Unicode.GetString(body)));
        }
Exemplo n.º 6
0
        public HttpResponseMessage PostMessageToFeed(string name, RestMSMessage messageSpecification)
        {
            var addMessageToFeedCommand = new AddMessageToFeedCommand(
                name,
                messageSpecification.Address,
                messageSpecification.ReplyTo ?? "",
                GetHeadersFromMessage(messageSpecification),
                GetAttachmentFromMessage(messageSpecification.Content)
                );

            commandProcessor.Send(addMessageToFeedCommand);

            var item = new RestMSMessagePosted()
            {
                Count = addMessageToFeedCommand.MatchingJoins
            };

            return(Request.CreateResponse <RestMSMessagePosted>(HttpStatusCode.OK, item));
        }