/// <summary>
        /// Initializes the data set infrastructure.
        /// </summary>
        private void Initialize()
        {
            if (BindingFactory == null)
            {
                throw new ArgumentNullException(nameof(BindingFactory));
            }
            if (EncodingFactory == null)
            {
                throw new ArgumentNullException(nameof(EncodingFactory));
            }
            if (MessageHandlerFactory == null)
            {
                throw new ArgumentNullException(nameof(MessageHandlerFactory));
            }
            if (ConfigurationFactory == null)
            {
                throw new ArgumentNullException(nameof(ConfigurationFactory));
            }
            DisposeMessageHandlersCollection();
            ConfigurationData _configuration = ConfigurationFactory.GetConfiguration();

            AssociationsCollection = AssociationsCollection.CreateAssociations(_configuration.DataSets, BindingFactory, EncodingFactory);
            ConfigurationFactory.OnAssociationConfigurationChange += AssociationsCollection.OnConfigurationChangeHandler;
            MessageHandlersCollection = MessageHandlersCollection.CreateMessageHandlers(_configuration.MessageHandlers, MessageHandlerFactory, EncodingFactory, AssociationsCollection.AddMessageHandler);
            ConfigurationFactory.OnMessageHandlerConfigurationChange += MessageHandlersCollection.OnConfigurationChangeHandler;
        }
 private void DisposeMessageHandlersCollection()
 {
     if (MessageHandlersCollection == null)
     {
         return;
     }
     foreach (IMessageHandler _handler in MessageHandlersCollection.Values)
     {
         _handler.Dispose();
     }
     MessageHandlersCollection = null; //to make sure no one will use them anymore.
 }
示例#3
0
        /// <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);
        }