/// <summary> /// Creates the message handlers. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="messageHandlerFactory">The message handler factory.</param> /// <param name="encodingFactory">The encoding factory that provides functionality to lookup a dictionary containing value converters..</param> /// <param name="addMessageHandler">The add message handler.</param> /// <returns>MessageHandlersCollection.</returns> /// <exception cref="System.ArgumentOutOfRangeException">Name;Duplicated transport name</exception> internal static MessageHandlersCollection CreateMessageHandlers (MessageHandlerConfiguration[] configuration, IMessageHandlerFactory messageHandlerFactory, IEncodingFactory encodingFactory, Action <IMessageHandler, AssociationConfiguration> addMessageHandler) { MessageHandlersCollection _collection = new MessageHandlersCollection(); foreach (MessageHandlerConfiguration _configuration in configuration) { if (_collection.ContainsKey(_configuration.Name)) { throw new ArgumentOutOfRangeException("Name", "Duplicated transport name"); } IMessageHandler _handler = null; switch (_configuration.TransportRole) { case AssociationRole.Consumer: MessageReaderConfiguration _readerConfiguration = (MessageReaderConfiguration)_configuration; _handler = messageHandlerFactory.GetIMessageReader(_configuration.Name, _configuration.Configuration, encodingFactory.UADecoder); foreach (ConsumerAssociationConfiguration _consumerAssociation in _readerConfiguration.ConsumerAssociationConfigurations) { addMessageHandler(_handler, _consumerAssociation); } break; case AssociationRole.Producer: MessageWriterConfiguration _writerConfiguration = (MessageWriterConfiguration)_configuration; _handler = messageHandlerFactory.GetIMessageWriter(_configuration.Name, _configuration.Configuration, encodingFactory.UAEncoder); foreach (ProducerAssociationConfiguration _producerAssociation in _writerConfiguration.ProducerAssociationConfigurations) { addMessageHandler(_handler, _producerAssociation); } break; default: break; } _collection.Add(_configuration.Name, _handler); } return(_collection); }