public async Task ProcessEventAsync(ProcessEventArgs args) { var message = args.GetSerializedMessage(); foreach (Reading reading in message.Readings) { if (this._cache.TryGetValue(reading.SensorId, out SensorAlarmRules sensorAlarmRules)) { // Get sensor alarm rule statuses against sensor reading IEnumerable <AlarmRuleStatus> transientStatuses = SensorAlarmRules.GetAlarmRuleStatuses(reading.SensorId, sensorAlarmRules.AlarmRules, reading.Value.Value); // Get cached alarm rule statuses IEnumerable <AlarmRuleStatus> persistedStatuses = transientStatuses.Select(x => this._cache.GetValue <AlarmRuleStatus>(x.ToString())); var changedStatuses = SensorAlarmRules.GetAlarmRuleStatusChanges(persistedStatuses, transientStatuses, this._logger); if (changedStatuses.Count() > 0) { await this._alarmNotificationService .SendAlarmRuleStatusNotificationsAsync(changedStatuses, reading.Value.Value, message.Timestamp, message.DeviceId); foreach (var status in changedStatuses) { this._cache.SetValue(status.ToString(), status); } } } } }
public void active_when_reading_value_less_than_alarm_rule_condition_value() { var alarmRules = new List <AlarmRule> { new AlarmRule(Guid.NewGuid(), "Equals", new List <Condition>() { new Condition("<", string.Empty, 100), }) }; var status = SensorAlarmRules.GetAlarmRuleStatuses(1, alarmRules, 99); Assert.True(status.All(x => x.AlarmActive)); }