public void TestRecieveMessagesFromSocketDevice( )
        {
            const int MESSAGES_TO_SEND_BY_SOCKET = 5;
            try
            {
                IList<string> sources = Loader.GetSources( )
                    .Where( m => m.Contains( "Socket" ) ).ToList( );
                IList<SensorEndpoint> endpoints = Loader.GetEndpoints( )
                    .Where( m => m.Name.Contains( "Socket" ) ).ToList( );

                if( endpoints.Count == 0 )
                {
                    throw new Exception( "Need to specify local ip host for Socket interations " +
                                        "and name of endpoint should contain \"Socket\"" );
                }

                GatewayService service = PrepareGatewayService( );

                SensorEndpoint endpoint = endpoints.First( );
                SocketClientTestDevice device = new SocketClientTestDevice( _logger );
                device.Start( endpoint, MESSAGES_TO_SEND_BY_SOCKET );

                DeviceAdapterLoader dataIntakeLoader = new DeviceAdapterLoader(
                    sources,
                    endpoints,
                    _logger );

                _totalMessagesToSend += MESSAGES_TO_SEND_BY_SOCKET;

                dataIntakeLoader.StartAll( service.Enqueue, DataArrived );

                _completed.WaitOne( );

                dataIntakeLoader.StopAll( );

                _batchSenderThread.Stop( STOP_TIMEOUT_MS );
            }
            catch( Exception ex )
            {
                _logger.LogError( "exception caught: " + ex.StackTrace );
            }
            finally
            {
                _batchSenderThread.Stop( STOP_TIMEOUT_MS );
                _sender.Close( );
            }
        }
Exemplo n.º 2
0
        public void TestDeviceAdapter( )
        {
            try
            {
                GatewayService service = PrepareGatewayService( );

                DeviceAdapterLoader dataIntakeLoader = new DeviceAdapterLoader( Loader.GetSources( ), Loader.GetEndpoints( ), _logger );

                _totalMessagesToSend += 5;

                dataIntakeLoader.StartAll( service.Enqueue, DataArrived );

                _completed.WaitOne( );

                dataIntakeLoader.StopAll( );

                _batchSenderThread.Stop( STOP_TIMEOUT_MS );
            }
            catch( Exception ex )
            {
                _logger.LogError( "exception caught: " + ex.StackTrace );
            }
            finally
            {
                _batchSenderThread.Stop( STOP_TIMEOUT_MS );
                _sender.Close( );
            }
        }
        public void TestRealTimeData( )
        {
            const int INITIAL_MESSAGES_BOUND = 5;
            const int STOP_TIMEOUT_MS = 5000; // ms

            try
            {
                IList<string> sources = Loader.GetSources( ).Where(
                    m => !m.Contains( "Mock" )
                        && ( m.Contains( "Socket" ) || m.Contains( "SerialPort" ) )
                    ).ToList( );

                IList<SensorEndpoint> endpoints = Loader.GetEndpoints( );

                if( !endpoints.Any( m => m.Name.Contains( "Socket" ) ) )
                {
                    Console.Out.WriteLine( "Need to specify local ip host for Socket interations " +
                                        "and name of endpoint should contain \"Socket\"" );
                }

                GatewayService service = PrepareGatewayService( );

                DeviceAdapterLoader dataIntakeLoader = new DeviceAdapterLoader(
                    sources,
                    endpoints,
                    _logger );

                _totalMessagesToSend += INITIAL_MESSAGES_BOUND;

                dataIntakeLoader.StartAll( service.Enqueue, DataArrived );

                _completed.WaitOne( );

                dataIntakeLoader.StopAll( );

                _batchSenderThread.Stop( STOP_TIMEOUT_MS );
            }
            catch( Exception ex )
            {
                _logger.LogError( "exception caught: " + ex.StackTrace );
            }
            finally
            {
                _batchSenderThread.Stop( STOP_TIMEOUT_MS );
                _sender.Close( );
            }
        }