Exemplo n.º 1
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( );
            }
        }
Exemplo n.º 2
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( );
            }
        }
Exemplo n.º 3
0
        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( );
            }
        }
Exemplo n.º 4
0
        protected override void OnStop( )
        {
            _logger.LogInfo("Service stopping... ");

            _dataIntakeLoader.StopAll( );

            // close web host first (message intake)
            if (_webHost != null)
            {
                _webHost.Close( );
                _webHost = null;
            }

            // shutdown processor (message processing)
            _batchSenderThread.Stop(STOP_TIMEOUT_MS);

            // shut down connection to event hub last
            if (_AMPQSender != null)
            {
                _AMPQSender.Close( );
            }

            _logger.LogInfo("...stopped");
        }