//--// public WindowsService(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 { _THREADING.TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; // Name the Windows Service ServiceName = Constants.WindowsServiceName; _gatewayQueue = new GatewayQueue <QueuedItem>( ); AMQPConfig amqpConfig = Loader.GetAMQPConfig( ); if (amqpConfig == null) { _logger.LogError("AMQP configuration is missing"); return; } _AMPQSender = new AMQPSender <SensorDataContract>( amqpConfig.AMQPSAddress, amqpConfig.EventHubName, amqpConfig.EventHubMessageSubject, amqpConfig.EventHubDeviceId, amqpConfig.EventHubDeviceDisplayName, _logger ); _batchSenderThread = new BatchSenderThread <QueuedItem, SensorDataContract>( _gatewayQueue, _AMPQSender, null, //m => DataTransforms.AddTimeCreated(DataTransforms.SensorDataContractFromQueuedItem(m, _Logger)), new Func <QueuedItem, string>(m => m.JsonData), _logger); _dataIntakeLoader = new DeviceAdapterLoader(Loader.GetSources( ), Loader.GetEndpoints( ), _logger); } catch (Exception ex) { _logger.LogError("Exception creating WindowsService: " + ex.Message); } }
private static GatewayService CreateGateway(AMQPConfig amqpConfig) { try { var _gatewayQueue = new GatewayQueue <QueuedItem>(); var _AMPQSender = new AMQPSender <string>( amqpConfig.AMQPSAddress, amqpConfig.EventHubName, amqpConfig.EventHubMessageSubject, amqpConfig.EventHubDeviceId, amqpConfig.EventHubDeviceDisplayName, _Logger ); var _batchSenderThread = new BatchSenderThread <QueuedItem, string>( _gatewayQueue, _AMPQSender, null, m => m.JsonData, _Logger); _batchSenderThread.Start(); GatewayService service = new GatewayService( _gatewayQueue, _batchSenderThread ) { Logger = _Logger }; service.OnDataInQueue += (data) => _batchSenderThread.Process(); _Logger.Flush(); return(service); } catch (Exception ex) { _Logger.LogError("Exception on creating Gateway: " + ex.Message); } return(null); }
private static GatewayService CreateGateway(AMQPConfig amqpConfig) { try { var _gatewayQueue = new GatewayQueue<QueuedItem>(); var _AMPQSender = new AMQPSender<string>( amqpConfig.AMQPSAddress, amqpConfig.EventHubName, amqpConfig.EventHubMessageSubject, amqpConfig.EventHubDeviceId, amqpConfig.EventHubDeviceDisplayName, _Logger ); var _batchSenderThread = new BatchSenderThread<QueuedItem, string>( _gatewayQueue, _AMPQSender, null, m => m.JsonData, _Logger); _batchSenderThread.Start(); GatewayService service = new GatewayService( _gatewayQueue, _batchSenderThread ) { Logger = _Logger }; service.OnDataInQueue += (data) => _batchSenderThread.Process(); _Logger.Flush(); return service; } catch (Exception ex) { _Logger.LogError("Exception on creating Gateway: " + ex.Message); } return null; }
//--// public WindowsService( 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 { _THREADING.TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; // Name the Windows Service ServiceName = Constants.WindowsServiceName; _gatewayQueue = new GatewayQueue<QueuedItem>( ); AMQPConfig amqpConfig = Loader.GetAMQPConfig( ); if( amqpConfig == null ) { _logger.LogError( "AMQP configuration is missing" ); return; } _AMPQSender = new AMQPSender<SensorDataContract>( amqpConfig.AMQPSAddress, amqpConfig.EventHubName, amqpConfig.EventHubMessageSubject, amqpConfig.EventHubDeviceId, amqpConfig.EventHubDeviceDisplayName, _logger ); _batchSenderThread = new BatchSenderThread<QueuedItem, SensorDataContract>( _gatewayQueue, _AMPQSender, 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 WindowsService: " + ex.Message ); } }
//AMQPReceiver<string> _receiver; public Gateway(string amqpsAddress, string entityPath) { _sender = new AMQPSender<string>(amqpsAddress, entityPath); }
//--// 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>( ); AMQPConfig amqpConfig = Loader.GetAMQPConfig( ); if( amqpConfig == null ) { _logger.LogError( "AMQP configuration is missing" ); return; } _AMPQSender = new AMQPSender<SensorDataContract>( amqpConfig.AMQPSAddress, amqpConfig.EventHubName, amqpConfig.EventHubMessageSubject, amqpConfig.EventHubDeviceId, amqpConfig.EventHubDeviceDisplayName, _logger ); _batchSenderThread = new BatchSenderThread<QueuedItem, SensorDataContract>( _gatewayQueue, _AMPQSender, 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 ); } }