/// <summary>
        /// Creates and configures the provider to use to connect to the data feed.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private IListenerProvider DetermineListenerProvider(Configuration config)
        {
            IListenerProvider result = Listener.Provider;

            var settings = config.BaseStationSettings;

            switch (config.BaseStationSettings.ConnectionType)
            {
            case ConnectionType.COM:
                var existingSerialProvider = result as ISerialListenerProvider;
                if (existingSerialProvider == null || existingSerialProvider.BaudRate != settings.BaudRate || existingSerialProvider.ComPort != settings.ComPort ||
                    existingSerialProvider.DataBits != settings.DataBits || existingSerialProvider.Handshake != settings.Handshake ||
                    existingSerialProvider.Parity != settings.Parity || existingSerialProvider.ShutdownText != settings.ShutdownText ||
                    existingSerialProvider.StartupText != settings.StartupText || existingSerialProvider.StopBits != settings.StopBits)
                {
                    var serialProvider = Factory.Singleton.Resolve <ISerialListenerProvider>();
                    serialProvider.BaudRate     = settings.BaudRate;
                    serialProvider.ComPort      = settings.ComPort;
                    serialProvider.DataBits     = settings.DataBits;
                    serialProvider.Handshake    = settings.Handshake;
                    serialProvider.Parity       = settings.Parity;
                    serialProvider.ShutdownText = settings.ShutdownText;
                    serialProvider.StartupText  = settings.StartupText;
                    serialProvider.StopBits     = settings.StopBits;
                    result = serialProvider;
                }
                break;

            case ConnectionType.TCP:
                var existingTcpProvider = result as ITcpListenerProvider;
                if (existingTcpProvider == null || existingTcpProvider.Address != settings.Address || existingTcpProvider.Port != settings.Port)
                {
                    var tcpProvider = Factory.Singleton.Resolve <ITcpListenerProvider>();
                    tcpProvider.Address = settings.Address;
                    tcpProvider.Port    = settings.Port;
                    result = tcpProvider;
                }
                break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="bytesExtractor"></param>
        /// <param name="rawMessageTranslator"></param>
        /// <param name="autoReconnect"></param>
        public void ChangeSource(IListenerProvider provider, IMessageBytesExtractor bytesExtractor, IRawMessageTranslator rawMessageTranslator, bool autoReconnect)
        {
            lock (_SyncLock) {
                bool changed = false;

                if (provider != Provider || bytesExtractor != BytesExtractor || rawMessageTranslator != RawMessageTranslator)
                {
                    if (Provider != null)
                    {
                        Disconnect();
                    }
                    if (RawMessageTranslator != null && RawMessageTranslator != rawMessageTranslator)
                    {
                        RawMessageTranslator.Dispose();
                    }

                    Provider             = provider;
                    BytesExtractor       = bytesExtractor;
                    RawMessageTranslator = rawMessageTranslator;

                    TotalMessages    = 0;
                    TotalBadMessages = 0;

                    changed = true;
                }

                if (changed)
                {
                    OnSourceChanged(EventArgs.Empty);
                    if (autoReconnect)
                    {
                        Connect(false);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="bytesExtractor"></param>
        /// <param name="rawMessageTranslator"></param>
        /// <param name="autoReconnect"></param>
        public void ChangeSource(IListenerProvider provider, IMessageBytesExtractor bytesExtractor, IRawMessageTranslator rawMessageTranslator, bool autoReconnect)
        {
            lock(_SyncLock) {
                bool changed = false;

                if(provider != Provider || bytesExtractor != BytesExtractor || rawMessageTranslator != RawMessageTranslator) {
                    if(Provider != null) Disconnect();
                    if(RawMessageTranslator != null && RawMessageTranslator != rawMessageTranslator) RawMessageTranslator.Dispose();

                    Provider = provider;
                    BytesExtractor = bytesExtractor;
                    RawMessageTranslator = rawMessageTranslator;

                    TotalMessages = 0;
                    TotalBadMessages = 0;

                    changed = true;
                }

                if(changed) {
                    OnSourceChanged(EventArgs.Empty);
                    if(autoReconnect) Connect(false);
                }
            }
        }