static void Main(string[] args) { BatchSenderThreadTest t = new BatchSenderThreadTest(SafeLogger.FromLogger(TestLogger.Instance)); t.Run( ); // wait for logging tasks to complete Console.WriteLine("Test completed, press enter to exit"); Console.ReadLine( ); }
public MessageSender(string gatewayIotHubConnectionString, ILogger logger) { Logger = SafeLogger.FromLogger(logger); #if DEBUG_LOG Logger.LogInfo("Connecting to IotHub"); #endif deviceClient = DeviceClient.CreateFromConnectionString(gatewayIotHubConnectionString); deviceClient.OpenAsync(); }
static void Main(string[] args) { // we do not need a tunable logger, but this is a nice way to test it... TunableLogger logger = TunableLogger.FromLogger( SafeLogger.FromLogger(TestLogger.Instance) ); TunableLogger.LoggingLevel loggingLevel = TunableLogger.LevelFromString(ConfigurationManager.AppSettings.Get("LoggingLevel")); logger.Level = (loggingLevel != TunableLogger.LoggingLevel.Undefined) ? loggingLevel : TunableLogger.LoggingLevel.Errors; if (args.Length == 0) { //if started without arguments TestRealData(logger); } foreach (string t in args) { switch (t.Substring(0, 1).Replace("/", "-") + t.Substring(1).ToLowerInvariant( )) { case "-MockData": TestMockData(logger); break; case "-WebService": TestWebService(logger); break; case "-Socket": TestSocket(logger); break; case "-AllTimeBounded": TestMockData(logger); TestWebService(logger); TestSocket(logger); break; case "-RealData": TestRealData(logger); break; } } // wait for logging tasks to complete Console.WriteLine("Press enter to exit"); Console.ReadLine( ); }
public BatchSenderThread(IAsyncQueue <TQueueItem> dataSource, IMessageSender <TQueueItem> dataTarget, Func <TQueueItem, string> serializedData, ILogger logger) : base(SafeLogger.FromLogger(logger)) { if (dataSource == null || dataTarget == null) { throw new ArgumentException("data source and data target cannot be null"); } _operational = new AutoResetEvent(false); _doWork = new AutoResetEvent(false); _running = false; _dataSource = dataSource; _dataTarget = dataTarget; _serializedData = serializedData; _outstandingTasks = 0; }
//--// internal ReliableSender(string amqpsAddress, string eventHubName, ILogger logger) { _eventHubName = eventHubName; _Logger = SafeLogger.FromLogger(logger); try { _address = new Address(amqpsAddress); } catch (Exception ex) { throw new ArgumentException("Please use a correct amqp address: " + ex.Message); } EstablishSender( ); }
private const int MONITORING_INTERVAL = 1000; // ms //--// static void Main(string[] args) { ILogger logger = SafeLogger.FromLogger(MonitorLogger.Instance); // try and open the GatewayService process string monitoringTarget = ConfigurationManager.AppSettings.Get("MonitoringTarget"); string monitoringExecutable = ConfigurationManager.AppSettings.Get("TargetExecutable"); string type = ConfigurationManager.AppSettings.Get("TargetType"); if (String.IsNullOrEmpty(monitoringTarget) || String.IsNullOrEmpty(monitoringExecutable)) { logger.LogError("Error in configuration, cannot start monitoring"); return; } if (String.IsNullOrEmpty(type)) { logger.LogInfo("No type specified, defaulting to 'process'"); type = AbstractMonitor.ProcessType; return; } AbstractMonitor monitor = null; switch (type) { case AbstractMonitor.ProcessType: monitor = new ProcessMonitor(monitoringExecutable, logger); break; case AbstractMonitor.ServiceType: monitor = new ServiceMonitor(monitoringTarget, logger); break; default: throw new ArgumentException(String.Format("Monitoring type {0} is unrecognized", type)); } monitor.MonitoringInterval = MONITORING_INTERVAL; if (monitor.Lock(monitoringTarget)) { monitor.Monitor(); } }
public AMQPSender(string amqpsAddress, string eventHubName, string defaultSubject, string defaultDeviceId, string defaultDeviceDisplayName, ILogger logger) { Logger = SafeLogger.FromLogger(logger); #if DEBUG_LOG Logger.LogInfo("Connecting to Event hub"); #endif if (defaultSubject == null || defaultDeviceId == null || defaultDeviceDisplayName == null || eventHubName == null) { throw new ArgumentException("defaultSubject, defaultDeviceId, defaultDeviceDisplayName, eventHubName cannot be null"); } _defaultSubject = defaultSubject; _defaultDeviceId = defaultDeviceId; _defaultDeviceDisplayName = defaultDeviceDisplayName; _senders = new SendersPool(amqpsAddress, eventHubName, Constants.ConcurrentConnections, Logger); }
static void Main(string[] args) { // we do not need a tunable logger, but this is a nice way to test it... TunableLogger logger = TunableLogger.FromLogger( SafeLogger.FromLogger(TestLogger.Instance) ); TunableLogger.LoggingLevel loggingLevel = TunableLogger.LevelFromString(ConfigurationManager.AppSettings.Get("LoggingLevel")); logger.Level = (loggingLevel != TunableLogger.LoggingLevel.Undefined) ? loggingLevel : TunableLogger.LoggingLevel.Errors; ///////////////////////////////////////////////////////////////////////////////////////////// // Test core service // CoreTest t2 = new CoreTest(logger); t2.Run( ); Console.WriteLine(String.Format("Core Test completed")); ////////////////////////////////////////////////////////////////////////////////////////////// // Test Web service and core service // SensorDataContract sensorData = RandomSensorDataGenerator.Generate( ); string serializedData = JsonConvert.SerializeObject(sensorData); WebServiceTest t1 = new WebServiceTest("http://localhost:8000/GatewayService/API/Enqueue?jsonData=" + serializedData, logger); t1.Run( ); Console.WriteLine(String.Format("WebService Test completed, {0} messages sent", t1.TotalMessagesSent)); ///////////////////////////////////////////////////////////////////////////////////////////// // Test Socket // SocketTest t3 = new SocketTest(logger); t3.Run( ); Console.WriteLine(String.Format("Socket Test completed")); // wait for logging tasks to complete Console.WriteLine("Press enter to exit"); Console.ReadLine( ); }
static void Main(string[] args) { ILogger logger = null; try { logger = TunableLogger.FromLogger( SafeLogger.FromLogger(EventLogger.Instance) ); Run(new WindowsService(logger)); } catch (Exception ex) { if (logger != null) { logger.LogError(ex.ToString( )); } // just return... } }
static void Main(string[] args) { ILogger logger = null; try { logger = TunableLogger.FromLogger( SafeLogger.FromLogger(NLogEventLogger.Instance) ); InitGateway(logger); Start(); } catch (Exception ex) { if (logger != null) { logger.LogError(ex.ToString( )); } // just return... } }
public IotHubSender(IotHubSenderSettings senderSettings, ILogger logger) //string gatewayIotHubConnectionString, ILogger logger) { Logger = SafeLogger.FromLogger(logger); #if DEBUG_LOG Logger.LogInfo("Connecting to IotHub"); #endif /* AzureDevices.RegistryManager registryManager = AzureDevices.RegistryManager.CreateFromConnectionString(senderSettings.IotHubConnectionString); * AddDeviceAsync(registryManager).Wait(); */ deviceClients = new DeviceClientExtCollection(); foreach (DeviceBinding binding in senderSettings.Bindings) { var deviceClient = DeviceClient.CreateFromConnectionString(binding.GatewayHostName); deviceClient.OpenAsync(); deviceClients.Append(binding.DeviceId, deviceClient); } }
//--// public DeviceAdapterLoader(IList <String> sources, IList <SensorEndpoint> endpoints, ILogger logger) { _logger = SafeLogger.FromLogger(logger); #if DEBUG_LOG _logger.LogInfo("Starting loading Data Intakes"); #endif _dataIntakes = new List <DeviceAdapterAbstract>( ); if (endpoints != null) { foreach (SensorEndpoint endpoint in endpoints) { _SensorEndpoints.Add(endpoint); } } #if DEBUG_LOG else { _logger.LogInfo("No list of SensorEndpoints in configuration file, continuing..."); } #endif // // enumerate all types with a IDeviceAdapter interface look in the current directory, in the // running assembly directory and in the entry and executing assembly // var directories = new List <String>( ); directories.Add(Directory.GetCurrentDirectory( )); var di1 = Path.GetDirectoryName(Assembly.GetEntryAssembly( ).Location); var di2 = Path.GetDirectoryName(Assembly.GetCallingAssembly( ).Location); var di3 = Path.GetDirectoryName(Assembly.GetExecutingAssembly( ).Location); // do not duplicate search paths if (!directories.Contains(di1)) { directories.Add(di1); } if (!directories.Contains(di2)) { directories.Add(di2); } if (!directories.Contains(di3)) { directories.Add(di3); } //for each filename will store a flag - whether it was specified at config or not Dictionary <String, bool> sourcesToLoad = new Dictionary <string, bool>( ); if (sources != null && sources.Any( )) { foreach (var filename in sources) { sourcesToLoad.Add(filename, true); } } else { #if DEBUG_LOG _logger.LogInfo("No list of DeviceAdapters in configuration file, continuing..."); #endif foreach (string directory in directories) { //Dinar: dont want to try all windows/system32 directory for now if (!directory.ToLowerInvariant( ).Contains("system32")) { foreach (string filename in Directory.GetFiles(directory)) { //false flag - file was not specified at config sourcesToLoad.Add(filename, false); } } } } // try and load assemblies from path var nameTypeDict = new Dictionary <string, Type>( ); string notLoadedSpecifiedSources = ""; string notLoadedNotSpecifiedSources = ""; foreach (KeyValuePair <string, bool> source in sourcesToLoad) { string fileName = source.Key; try { Assembly assm = null; // try path from config first if (File.Exists(fileName)) { assm = Assembly.LoadFrom(fileName); // remember this directory as a potential source var lastDir = Path.GetDirectoryName(fileName); if (!directories.Contains(lastDir)) { directories.Add(lastDir); } } else { // try the other directories foreach (var d in directories) { var assmName = Path.GetFileName(fileName); // try again string assmPath = Path.Combine(d, assmName); if (File.Exists(assmPath)) { assm = Assembly.LoadFrom(assmPath); } } if (assm == null) { // Log that we did not load our data sources correctly if (source.Value) { notLoadedSpecifiedSources += fileName; } else { notLoadedNotSpecifiedSources += fileName; } notLoadedSpecifiedSources += "; "; continue; } } Debug.Assert(assm != null); foreach (Type t in assm.GetExportedTypes( )) { //Get all classes that implement the required interface if (t.GetInterface("IDeviceAdapter", false) != null) { #if DEBUG_LOG _logger.LogInfo("IDeviceAdapter assembly loaded: " + t.Name); #endif nameTypeDict.Add(t.Name, t); //Add to Dictonary } } } catch (Exception) { //dont want to stop loading another modules if one fails if (source.Value) { notLoadedSpecifiedSources += fileName; } else { notLoadedNotSpecifiedSources += fileName; } notLoadedNotSpecifiedSources += "; "; } } if (notLoadedSpecifiedSources.Length > 0) { _logger.LogError(String.Format("Following Data Intakes were specificied, but could not be loaded: {0}", notLoadedSpecifiedSources)); } if (notLoadedNotSpecifiedSources.Length > 0) { _logger.LogError(String.Format("Following files are not specificied, and could not be loaded as Data Intakes: {0}", notLoadedNotSpecifiedSources)); } foreach (KeyValuePair <string, Type> t in nameTypeDict) { try { DeviceAdapterAbstract di = ( DeviceAdapterAbstract )Activator.CreateInstance(t.Value, new object[] { _logger }); if (di != null) { #if DEBUG_LOG _logger.LogInfo("IDeviceAdapter instance created: " + t.Key); #endif //adding instance without endpoint if acceptable if (di.SetEndpoint( )) { _dataIntakes.Add(di); } foreach (SensorEndpoint sensorEndpoint in _SensorEndpoints) { DeviceAdapterAbstract diWithEndpoint = ( DeviceAdapterAbstract )Activator.CreateInstance(t.Value, new object[] { _logger }); if (diWithEndpoint.SetEndpoint(sensorEndpoint)) { _dataIntakes.Add(diWithEndpoint); } } } } catch (Exception ex) { // dont want to stop creating another instances if one fails _logger.LogError(String.Format("Exception on Creating DeviceAdapter Instance \"{0}\": {1}", t.Key, ex.Message)); } } }
protected void Application_End(object sender, EventArgs e) { SafeLogger.Trace("Shutdown"); }
protected void Application_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); SafeLogger.Error($"Application error: {ex}"); }
//--// protected AbstractMonitor(ILogger logger) { Logger = SafeLogger.FromLogger(logger); }
//--// protected DeviceAdapterAbstract(ILogger logger) { _logger = SafeLogger.FromLogger(logger); }