private void CheckMonitors(Object stateInfo) { foreach (Monitor monitor in Monitors) { try { TemperatureReading reading = monitor.Check(); TemperatureReadingEventArgs eventArgs = new TemperatureReadingEventArgs(); eventArgs.Reading = reading; RaiseMonitorReadEvent(eventArgs); } catch (Exception e) { //This is not ideal. Should raise separate event that something failed //Don't want to let unhandled exception occur as some level of fail tolerance is required //Beyond the scope of this work. Console.WriteLine("Unhandled exception occurred. Will continue monitoring. Details {0}", e.Message); } } }
public TemperatureReading Check() { double temperature = _thermometer.Temperature(); TemperatureStatus temperatureStatus; if (temperature > _containerType.TempMax) { temperatureStatus = TemperatureStatus.Over; } else if (temperature < _containerType.TempMin) { temperatureStatus = TemperatureStatus.Under; } else { temperatureStatus = TemperatureStatus.Good; } TemperatureReading temperatureReading = new TemperatureReading(temperature, temperatureStatus, _containerType); return(temperatureReading); }