Example #1
0
        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( );
            }
        }
        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( );
            }
        }