Esempio n. 1
0
        /// <summary>
        /// Updates the message instance.
        /// </summary>
        /// <param name="newInstance">The new instance.</param>
        public void UpdateMessageInstance(object newInstance)
        {
            var sameInstance = ReferenceEquals(Instance, newInstance);

            Instance = newInstance;

            if (sameInstance)
            {
                return;
            }

            var newLogicalMessage = factory.Create(newInstance);

            Metadata = newLogicalMessage.Metadata;
        }
Esempio n. 2
0
        List <LogicalMessage> Extract(TransportMessage physicalMessage)
        {
            if (physicalMessage.Body == null || physicalMessage.Body.Length == 0)
            {
                return(new List <LogicalMessage>());
            }

            var messageMetadata = MessageMetadataRegistry.GetMessageTypes(physicalMessage);

            using (var stream = new MemoryStream(physicalMessage.Body))
            {
                var messageTypesToDeserialize = messageMetadata.Select(metadata => metadata.MessageType).ToList();

                return(MessageSerializer.Deserialize(stream, messageTypesToDeserialize)
                       .Select(x => LogicalMessageFactory.Create(x.GetType(), x, physicalMessage.Headers))
                       .ToList());
            }
        }
        List <LogicalMessage> Extract(TransportMessage physicalMessage)
        {
            if (physicalMessage.Body == null || physicalMessage.Body.Length == 0)
            {
                return(new List <LogicalMessage>());
            }

            string messageTypeIdentifier;
            var    messageMetadata = new List <MessageMetadata>();

            if (physicalMessage.Headers.TryGetValue(Headers.EnclosedMessageTypes, out messageTypeIdentifier))
            {
                foreach (var messageTypeString in messageTypeIdentifier.Split(';'))
                {
                    if (DoesTypeHaveImplAddedByVersion3(messageTypeString))
                    {
                        continue;
                    }

                    var metadata = MessageMetadataRegistry.GetMessageMetadata(messageTypeString);
                    if (metadata == null)
                    {
                        continue;
                    }
                    messageMetadata.Add(metadata);
                }

                if (messageMetadata.Count == 0 && physicalMessage.MessageIntent != MessageIntentEnum.Publish)
                {
                    log.WarnFormat("Could not determine message type from message header '{0}'. MessageId: {1}", messageTypeIdentifier, physicalMessage.Id);
                }
            }

            using (var stream = new MemoryStream(physicalMessage.Body))
            {
                var messageTypesToDeserialize = messageMetadata.Select(metadata => metadata.MessageType).ToList();

                return(MessageSerializer.Deserialize(stream, messageTypesToDeserialize)
                       .Select(x => LogicalMessageFactory.Create(x.GetType(), x, physicalMessage.Headers))
                       .ToList());
            }
        }