Пример #1
0
        private static MessageHandlerConfiguration[] GetMessageHandlers(AssociationRole associationRole)
        {
            MessageHandlerConfiguration[] _ret = null;
            switch (associationRole)
            {
            case AssociationRole.Consumer:
                _ret = new MessageReaderConfiguration[] { new MessageReaderConfiguration()
                                                          {
                                                              ConsumerAssociationConfigurations = GetConsumerAssociationConfiguration(),
                                                              Configuration = null,
                                                              Name          = "UDP",
                                                              TransportRole = associationRole
                                                          } };
                break;

            case AssociationRole.Producer:
                _ret = new MessageWriterConfiguration[] { new MessageWriterConfiguration()
                                                          {
                                                              ProducerAssociationConfigurations = GetProducerAssociationConfiguration(),
                                                              Configuration = null,
                                                              Name          = "UDP",
                                                              TransportRole = associationRole
                                                          } };
                break;
            }
            return(_ret);
        }
        internal static MessageHandlerConfiguration[] GetMessageHandlers(AssociationRole associationRole)
        {
            MessageHandlerConfiguration[] _ret = null;
            switch (associationRole)
            {
            case AssociationRole.Consumer:
                _ret = new MessageReaderConfiguration[] { new MessageReaderConfiguration()
                                                          {
                                                              ConsumerAssociationConfigurations = GetConsumerAssociationConfiguration(),
                                                              Configuration = new MessageChannelConfiguration()
                                                              {
                                                                  ChannelConfiguration = "4840,True,239.255.255.1,True"
                                                              },
                                                              Name          = "UDP",
                                                              TransportRole = associationRole
                                                          } };
                break;

            case AssociationRole.Producer:
                _ret = new MessageWriterConfiguration[] { new MessageWriterConfiguration()
                                                          {
                                                              ProducerAssociationConfigurations = GetProducerAssociationConfiguration(),
                                                              Configuration = new MessageChannelConfiguration()
                                                              {
                                                                  ChannelConfiguration = "4840,localhost"
                                                              },
                                                              Name          = "UDP",
                                                              TransportRole = associationRole
                                                          } };
                break;
            }
            return(_ret);
        }
Пример #3
0
        private static void CompareMessageWriterConfiguration(MessageWriterConfiguration source, MessageWriterConfiguration mirror)
        {
            Assert.IsNotNull(source);
            Assert.IsNotNull(mirror);
            Assert.AreEqual <AssociationRole>(source.TransportRole, mirror.TransportRole);
            Dictionary <string, ProducerAssociationConfiguration> _mirror2Dictionary = mirror.ProducerAssociationConfigurations.ToDictionary <ProducerAssociationConfiguration, string>(x => x.AssociationName);

            foreach (ProducerAssociationConfiguration _item in source.ProducerAssociationConfigurations)
            {
                Compare(_item, _mirror2Dictionary[_item.AssociationName]);
            }
        }
Пример #4
0
        /// <summary>
        /// Adds the data set configuration.
        /// </summary>
        /// <param name="newDataSetConfiguration">The new data set configuration.</param>
        /// <param name="inFileName">Name of the in file.</param>
        /// <param name="outFileName">Name of the out file.</param>
        /// <param name="writerId">The writer identifier.</param>
        /// <param name="traceSource">The trace source.</param>
        public static void AddDataSetConfiguration(this DataSetConfiguration newDataSetConfiguration, Tuple <string, ushort, Guid> writerId, string inFileName, string outFileName, ITraceSource traceSource)
        {
            traceSource.TraceData(TraceEventType.Verbose, 53, $"Entering {nameof(AddDataSetConfiguration)} method.");
            //open source configuration
            UANetworkingConfiguration <ConfigurationData> _newConfiguration = new UANetworkingConfiguration <ConfigurationData>();
            FileInfo _file2ReadConfiguration = new FileInfo(inFileName);

            _newConfiguration.ReadConfiguration(_file2ReadConfiguration);
            traceSource.TraceData(TraceEventType.Verbose, 53, $"I have read the configuration form the file {_file2ReadConfiguration.FullName}.");
            _newConfiguration.TraceSource = traceSource;
            ConfigurationData _currentConfiguration = _newConfiguration.CurrentConfiguration;
            // ddd new DataSetConfiguration
            List <DataSetConfiguration> _dataSets = _currentConfiguration.DataSets.ToList <DataSetConfiguration>();

            traceSource.TraceData(TraceEventType.Verbose, 53, $"Configuration contains {_dataSets.Count} item of type {nameof(DataSetConfiguration)}.");
            _dataSets.Add(newDataSetConfiguration);
            _currentConfiguration.DataSets = _dataSets.ToArray <DataSetConfiguration>();
            traceSource.TraceData(TraceEventType.Verbose, 53, $"New {nameof(DataSetConfiguration)} has been added to the copnfiguration.");
            // add new association for this DataSet in selected MessageWriterConfiguration
            ProducerAssociationConfiguration _newAssociation = new ProducerAssociationConfiguration()
            {
                AssociationName = newDataSetConfiguration.AssociationName,
                DataSetWriterId = writerId.Item2,
                FieldEncoding   = FieldEncodingEnum.VariantFieldEncoding,
                PublisherId     = writerId.Item3
            };
            MessageWriterConfiguration _selectedWriterConfiguration = _currentConfiguration.MessageHandlers
                                                                      .Where <MessageHandlerConfiguration>(_hn => (_hn.Name == writerId.Item1) && (_hn is MessageWriterConfiguration))
                                                                      .Cast <MessageWriterConfiguration>()
                                                                      .First <MessageWriterConfiguration>();
            List <ProducerAssociationConfiguration> _associationsInWriterConfiguration = _selectedWriterConfiguration.ProducerAssociationConfigurations.ToList <ProducerAssociationConfiguration>();

            _associationsInWriterConfiguration.Add(_newAssociation);
            _selectedWriterConfiguration.ProducerAssociationConfigurations = _associationsInWriterConfiguration.ToArray();
            traceSource.TraceData(TraceEventType.Verbose, 53, $"New {nameof (ProducerAssociationConfiguration)}  has been added to the {nameof(MessageWriterConfiguration)}[{writerId.Item1}].");
            //save the output file
            FileInfo _file2SaveConfiguration = new FileInfo(outFileName);

            _newConfiguration.SaveConfiguration(_file2SaveConfiguration);
            traceSource.TraceData(TraceEventType.Verbose, 53, $"Configuration has been saved to the file {_file2SaveConfiguration.FullName}.");
        }
Пример #5
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);
        }