private void RegisterNonShared(Type messageType, Type containerType, MessageHandlerAttribute attribute, Action <object, object, Message> action, Type tokenType, object container = null) { if (attribute == null) { throw new ArgumentNullException("attribute"); } if (action == null) { throw new ArgumentNullException("action"); } var assembly = containerType.Assembly; // handlers are organized by assemblies to build an hierarchie // if the assembly is not registered yet we add it to the end if (!m_nonSharedHandlers.ContainsKey(assembly)) { m_nonSharedHandlers.Add(assembly, new Dictionary <Type, List <MessageHandler> >()); } if (!m_nonSharedHandlers[assembly].ContainsKey(messageType)) { m_nonSharedHandlers[assembly].Add(messageType, new List <MessageHandler>()); } m_nonSharedHandlers[assembly][messageType].Add(new MessageHandler(container, containerType, messageType, attribute, action, tokenType)); }
public MessageHandler(object container, Type containerType, Type messageType, MessageHandlerAttribute handlerAttribute, Action <object, object, Message> action, Type tokenType) { Container = container; ContainerType = containerType; MessageType = messageType; Attribute = handlerAttribute; Action = action; TokenType = tokenType; }
public MessageHandler(object container, Type containerType, Type messageType, MessageHandlerAttribute handlerAttribute, Action<object, object, Message> action, Type tokenType) { Container = container; ContainerType = containerType; MessageType = messageType; Attribute = handlerAttribute; Action = action; TokenType = tokenType; }
public void RegisterNonShared(Type messageType, Type containerType, MessageHandlerAttribute attribute, Action<object, object, Message> action, Type tokenType, object container = null) { if (attribute == null) throw new ArgumentNullException("attribute"); if (action == null) throw new ArgumentNullException("action"); var assembly = containerType.Assembly; // handlers are organized by assemblies to build an hierarchie // if the assembly is not registered yet we add it to the end if (!m_nonSharedHandlers.ContainsKey(assembly)) m_nonSharedHandlers.Add(assembly, new Dictionary<Type, List<MessageHandler>>()); if (!m_nonSharedHandlers[assembly].ContainsKey(messageType)) m_nonSharedHandlers[assembly].Add(messageType, new List<MessageHandler>()); m_nonSharedHandlers[assembly][messageType].Add(new MessageHandler(container, containerType, messageType, attribute, action, tokenType)); }
public static void Register(Type messageType, Type containerType, MessageHandlerAttribute attribute, Action<object, object, Message> action, Type tokenType, object container = null) { if (attribute == null) throw new ArgumentNullException("attribute"); if (action == null) throw new ArgumentNullException("action"); var assembly = containerType.Assembly; // handlers are organized by assemblies to build an hierarchie // if the assembly is not registered yet we add it to the end if (!m_handlers.ContainsKey(assembly)) m_handlers.Add(assembly, new Dictionary<Type, List<MessageHandler>>()); if (!m_handlers[assembly].ContainsKey(messageType)) m_handlers[assembly].Add(messageType, new List<MessageHandler>()); IMessageFilter filter = null; if (attribute.FilterType != null) { if (!attribute.FilterType.HasInterface(typeof(IMessageFilter))) throw new Exception(string.Format("Cannot register handler {0} in {1}, the filter type {2} doesn't implement IMessageFilter", messageType, containerType, attribute.FilterType)); ConstructorInfo ctor; if ((ctor = attribute.FilterType.GetConstructor(new Type[0])) == null) throw new Exception(string.Format("Cannot register handler {0} in {1}, the filter type {2} hasn't a default constructor", messageType, containerType, attribute.FilterType)); filter = (IMessageFilter)ctor.Invoke(new object[0]); } m_handlers[assembly][messageType].Add(new MessageHandler(container, containerType, messageType, attribute, action, tokenType, filter)); }