private void PopulateAppSettingsFromDataStore() { var asType = typeof(AppSetting); using (var repo = new AppSettingRepository()) { foreach (var appSettingDto in repo.GetAll()) { var prop = asType.GetProperty(appSettingDto.SettingName); if (prop == null) { throw new MissingMemberException(String.Format(CultureInfo.CurrentCulture, "Invalid application setting. An application setting named '{0}' was found in the data store, but no property by that name exists in the class '{1}'. Check the application settings in the data store to ensure they are correct.", appSettingDto.SettingName, asType)); } else if (prop.PropertyType == typeof(bool)) { prop.SetValue(this, Convert.ToBoolean(appSettingDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null); } else if (prop.PropertyType == typeof(string)) { prop.SetValue(this, Convert.ToString(appSettingDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null); } else if (prop.PropertyType == typeof(int)) { prop.SetValue(this, Convert.ToInt32(appSettingDto.SettingValue.Trim(), CultureInfo.InvariantCulture), null); } else { throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, "AppSetting.PopulateAppSettingsFromDataStore is not designed to process a property of type {0} (encountered in AppSetting.{1})", prop.PropertyType, prop.Name)); } } } }
private void DoAlarmScan() { appSetting = appSettingRepository.GetAll().First(); devices = deviceRepository.GetAll().ToList(); IEnumerable <DtuData> unProcessedDtuData = dtuDataService.GetLatestData(TimeSpan.FromMinutes(JobScheduler.ScanIntervalMinutes)); foreach (DtuData dtuData in unProcessedDtuData) { Device device = FindDevice(dtuData.IMEI); if (device == null) { return; } float value = dtuData.Value; if (dtuData.IsTemperature && dtuData.Channel < 2) { ProcessData(device, () => value > appSetting.TemperatureUpper || value < appSetting.TemperatureLower, AlarmType.Temperature); } else if (dtuData.IsHumidity && dtuData.Channel < 2) { ProcessData(device, () => value <appSetting.TemperatureLower || value> appSetting.HumidityUpper, AlarmType.Humidity); } } foreach (Device device in devices) { float battary = device.Battery; if (battary > 0) { ProcessData(device, () => battary <= appSetting.Battery, AlarmType.Battery); } } }