コード例 #1
0
        /// <summary>
        /// Convert message off the wire from byte[] into a concrete implementation of IIntegrationMessage
        /// delegates to custom extractors and defaults to Json deserialization
        /// </summary>
        private IIntegrationMessage _extractMessage(byte[] messageData, MessageTypeProperties props)
        {
            IIntegrationMessage message;

            if (props.HasCustomExtractor)
            {
                IMessageExtractor extractor = null;
                if (_messageExtractorCache.ContainsKey(props.MessageTypeIdentifier))
                {
                    extractor = _messageExtractorCache[props.MessageTypeIdentifier];
                }
                else
                {
                    extractor = (IMessageExtractor)Activator.CreateInstance(props.Type, true);
                    _messageExtractorCache.Add(props.MessageTypeIdentifier, extractor);
                }
                message = extractor.Extract(messageData);
            }
            else
            {
                //by default the message is json and will be deserialized to the type with a matching MessageTypeIdentifier property:"MessageType"
                var json = Encoding.UTF8.GetString(messageData);
                message = (IIntegrationMessage)JsonConvert.DeserializeObject(json, props.Type, _serializerSettings);
            }
            return(message);
        }