//--// 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 IotHubConfig iotHubConfig = Loader.GetIotHubConfig( ); _sender = new MessageSender <SensorDataContract>(iotHubConfig.IotHubConnectionString, _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))); } }
public void Initialize(Dictionary <string, object> settings) { string[] fieldNames = new string[] { "IotHubConfigFile", "TagStateManager", "TagToIotHubMessageConverter" }; FieldValidator.CheckMissingFields(settings, fieldNames); string iotHubConfigFile = settings.GetValueOrNull("IotHubConfigFile") as string; _iotHubConfig = ConfigUtility.ReadConfig <IotHubConfig>(iotHubConfigFile); _dataConverter = settings.GetValueOrNull("TagToIotHubMessageConverter") as IConverter <Tag, object>; _tagStateManager = settings.GetValueOrNull("TagStateManager") as TagStateManager; _deviceClienPool = new DeviceClientPool(); _deviceClienPool.Initialize(_iotHubConfig.IotHubHostName, _iotHubConfig.TelemetryDevicePool); }
public void Initialize(Dictionary <string, object> settings) { string[] fieldNames = new string[] { "IotHubConfigFile", "MessageConverter.OpcUa", "MessageExchange.Messaging", "MessageConverter.IotHub", "Logger" }; FieldValidator.CheckMissingFields(settings, fieldNames); string iotHubConfigFile = settings.GetValueOrNull("IotHubConfigFile") as string; _iotHubConfig = ConfigUtility.ReadConfig <IotHubConfig>(iotHubConfigFile); _toIotHubDataConverter = settings.GetValueOrNull("MessageConverter.IotHub") as IConverter <TExchangeMsg, object>; _alarmMessageExchange = settings.GetValueOrNull("MessageExchange.Messaging") as IMessageExchange <TExchangeMsg>; _logger = settings.GetValueOrNull("Logger") as ILogger; _deviceClienPool = new DeviceClientPool(); _deviceClienPool.Initialize(_iotHubConfig.IotHubHostName, _iotHubConfig.AlarmDevicePool); }
internal static IotHubConfig GetIotHubConfig( ) { IotHubConfigSection section = ConfigurationManager.GetSection("IotHubConfig") as IotHubConfigSection; IotHubConfig configData = null; if (section != null) { configData = new IotHubConfig { IotHubConnectionString = section.IotHubConnectionString, }; } return(configData); }
public void Initialize(Dictionary <string, object> settings) { //ConfigureSettings(settings); string[] fieldNames = new string[] { "IotHubConfigFile", "Logger", "CmdExecutor", "CmdConverter" }; FieldValidator.CheckMissingFields(settings, fieldNames); string iotHubConfigFile = settings.GetValueOrNull("IotHubConfigFile") as string; _iotHubConfig = ConfigUtility.ReadConfig <IotHubConfig>(iotHubConfigFile); _cmdConverter = settings.GetValueOrNull("CmdConverter") as IConverter <string, TCmd>; _cmdExecutor = settings.GetValueOrNull("CmdExecutor") as ICommandExecutor <TCmd>; _logger = settings.GetValueOrNull("Logger") as ILogger; _deviceClientPool = new DeviceClientPool(); _deviceClientPool.Initialize(_iotHubConfig.IotHubHostName, _iotHubConfig.CommandDevicePool); }
//--// private static void InitGateway(ILogger logger) { if (logger == null) { throw new ArgumentException("Cannot run service without logging"); } _logger = logger; if (logger is TunableLogger) { TunableLogger.LoggingLevel loggingLevel = TunableLogger.LevelFromString(ConfigurationManager.AppSettings.Get("LoggingLevel")); (( TunableLogger )logger).Level = (loggingLevel != TunableLogger.LoggingLevel.Undefined) ? loggingLevel : TunableLogger.LoggingLevel.Errors; } try { System.Threading.Tasks.TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; // Name the Windows Service _gatewayQueue = new GatewayQueue <QueuedItem>( ); IotHubConfig iotHubConfig = Loader.GetIotHubConfig(); if (iotHubConfig == null) { _logger.LogError("IoT Hub connection configuration is missing"); return; } _MessageSender = new MessageSender <SensorDataContract>(iotHubConfig.IotHubConnectionString, _logger); _batchSenderThread = new BatchSenderThread <QueuedItem, SensorDataContract>( _gatewayQueue, _MessageSender, null, //m => DataTransforms.AddTimeCreated(DataTransforms.SensorDataContractFromQueuedItem(m, _Logger)), new Func <QueuedItem, string>(m => m.JsonData), _logger); _dataIntakeLoader = new DeviceAdapterLoader(Loader.GetSources( ), Loader.GetEndpoints( ), _logger); TaskWrapper.Run(() => 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))); } } catch (Exception ex) { _logger.LogError("Exception creating Gateway: " + ex.Message); } }