Exemple #1
0
        internal static AMQPConfig GetAMQPConfig( )
        {
            AMQPServiceConfigSection section = ConfigurationManager.GetSection("AMQPServiceConfig") as AMQPServiceConfigSection;
            AMQPConfig configData            = null;

            if (section != null)
            {
                configData = new AMQPConfig
                {
                    AMQPSAddress              = section.AMQPSAddress,
                    EventHubName              = section.EventHubName,
                    EventHubMessageSubject    = section.EventHubMessageSubject,
                    EventHubDeviceId          = section.EventHubDeviceId,
                    EventHubDeviceDisplayName = section.EventHubDeviceDisplayName
                };
            }

            return(configData);
        }
Exemple #2
0
        //--//

        public CoreTest(ILogger logger)
        {
            if (logger == null)
            {
                throw new ArgumentException("Cannot run tests without logging");
            }

            _completed = new AutoResetEvent(false);

            _logger = logger;

            _rand = new Random( );
            _totalMessagesSent   = 0;
            _totalMessagesToSend = 0;
            _gatewayQueue        = new GatewayQueue <QueuedItem>( );

#if MOCK_SENDER
            _sender = new MockSender <SensorDataContract>(this);
#else
            AMQPConfig amqpConfig = Loader.GetAMQPConfig( );

            _sender = new AMQPSender <SensorDataContract>(
                amqpConfig.AMQPSAddress,
                amqpConfig.EventHubName,
                amqpConfig.EventHubMessageSubject,
                amqpConfig.EventHubDeviceId,
                amqpConfig.EventHubDeviceDisplayName,
                _logger
                );
#endif

            _batchSenderThread = new BatchSenderThread <QueuedItem, SensorDataContract>(
                _gatewayQueue,
                _sender,
                dataTransform: null,
                serializedData: m => (m == null) ? null : m.JsonData,
                logger: _logger
                );
        }
Exemple #3
0
        //--//

        public CoreTest(ILogger logger)
        {
            if (logger == null)
            {
                throw new ArgumentException("Cannot run tests without logging");
            }

            _completed = new AutoResetEvent(false);

            _logger = logger;

            _rand = new Random( );
            _totalMessagesSent   = 0;
            _totalMessagesToSend = 0;
            _gatewayQueue        = new GatewayQueue <QueuedItem>( );

#if MOCK_SENDER
            _sender = new MockSender <SensorDataContract>(this);
#else
            AMQPConfig amqpConfig = Loader.GetAMQPConfig( );

            _sender = new AMQPSender <SensorDataContract>(
                amqpConfig.AMQPSAddress,
                amqpConfig.EventHubName,
                amqpConfig.EventHubMessageSubject,
                amqpConfig.EventHubDeviceId,
                amqpConfig.EventHubDeviceDisplayName,
                _logger
                );
#endif

            _batchSenderThread = new BatchSenderThread <QueuedItem, SensorDataContract>(
                _gatewayQueue,
                _sender,
                dataTransform: null,
                serializedData: m => (m == null) ? null : m.JsonData,
                logger: _logger
                );

            string gatewayIPAddressString = string.Empty;
            IPAddressHelper.GetIPAddressString(ref gatewayIPAddressString);

            DataTransformsConfig dataTransformsConfig = Loader.GetDataTransformsConfig( );
            if (dataTransformsConfig.AttachIP || dataTransformsConfig.AttachTime)
            {
                Func <string, SensorDataContract> transform = (m => DataTransforms.SensorDataContractFromString(m, _logger));

                if (dataTransformsConfig.AttachTime)
                {
                    var transformPrev = transform;
                    transform = (m => DataTransforms.AddTimeCreated(transformPrev(m)));
                }

                if (dataTransformsConfig.AttachTime)
                {
                    var transformPrev = transform;
                    transform = (m => DataTransforms.AddIPToLocation(transformPrev(m), gatewayIPAddressString));
                }

                _gatewayTransform = (m => DataTransforms.QueuedItemFromSensorDataContract(transform(m)));
            }
        }