Example #1
0
 protected override void TransformHeaders(IDictionary <string, object> headers)
 {
     foreach (KeyValuePair <string, object> entry in _headersToAdd)
     {
         string key = entry.Key;
         if (_overwrite || DictionaryUtils.Get(headers, key) == null)
         {
             DictionaryUtils.Put(headers, key, entry.Value);
         }
     }
 }
        /// <summary>
        /// try to resolve the handler method from <paramref name="message"/>
        /// </summary>
        /// <param name="message">the message for which a handler mthod should be resolved</param>
        /// <returns>the handler methodf or <c>null</c> if no appropriate handler method could be found</returns>
        public MethodInfo ResolveHandlerMethod(IMessage message)
        {
            MethodInfo method = DictionaryUtils.Get(_methodMap, message.GetType());

            if (method == null)
            {
                Type payloadType = message.Payload.GetType();
                method = DictionaryUtils.Get(_methodMap, payloadType.GetType());
                if (method == null)
                {
                    method = FindClosestMatch(payloadType);
                }
                if (method == null)
                {
                    method = _fallbackMethod;
                }
            }
            return(method);
        }
        private MethodInfo FindClosestMatch(Type payloadType)
        {
            ICollection <Type> expectedTypes = _methodMap.Keys;
            int        minTypeDiffWeight     = Int32.MaxValue;
            MethodInfo matchingMethod        = null;

            foreach (Type expectedType in expectedTypes)
            {
                int typeDiffWeight = GetTypeDifferenceWeight(expectedType, payloadType);
                if (typeDiffWeight < minTypeDiffWeight)
                {
                    minTypeDiffWeight = typeDiffWeight;
                    matchingMethod    = DictionaryUtils.Get(_methodMap, expectedType);
                }
            }
            if (matchingMethod != null)
            {
                DictionaryUtils.Put(_methodMap, payloadType, matchingMethod);
            }
            return(matchingMethod);
        }
                                                              // TODO new ConcurrentDictionary<string, IMessageChannel>();

        public IMessageChannel ResolveChannelName(string channelName)
        {
            return DictionaryUtils.Get(channels, channelName);
        }
Example #5
0
 protected override IMessageChannel DetermineTargetChannel(IMessage message)
 {
     return(DictionaryUtils.Get(_payloadTypeChannelMap, message.Payload.GetType()));
 }