private void SetAlarm(AdsRuleSetting setting, double firedValue)
        {
            var counterKey = GetCounterKey(setting);
            var now        = DateTimeProvider.Singleton.Time();

            Func <string, PendingAlarm> addAlarmFunc = s => new PendingAlarm(now.Add(setting.Duration));

            PendingAlarm alarm = _alarmThresholds.GetOrAdd(counterKey, addAlarmFunc);

            if (alarm.ThresholdTime <= now)
            {
                // sound the alarm
                string message = GetAlarmMessage(setting);
                setting.IsInFiredCondition = true;
                Log.To.Main.Add("ALARM - " + message);
                setting.AdsLastFired = new AdsRuleSetting.AdsRuleFiredDto {
                    Fired = now, Value = firedValue
                };
                _adsAlarmTrigger.Invoke(setting);

                // reset the alarm
                ResetAlarm(setting);

                // re-add the alarm; this counter measurement acts as new trigger
                _alarmThresholds.TryAdd(counterKey, addAlarmFunc(counterKey));
            }
        }
        private void ResetAlarm(AdsRuleSetting setting)
        {
            var counterKey = GetCounterKey(setting);

            _alarmThresholds.TryRemove(counterKey, out var oldValue);
            Debug.WriteLine(oldValue);
        }
        private void ResetValidation(AdsRuleSetting setting, string key, PendingAlarm alarm)
        {
            // reset the alarm
            ResetAlarm(setting);

            // re-add the alarm; this counter measurement acts as new trigger
            _alarmThresholds.TryAdd(key, alarm);
        }
 private string GetCounterKey(AdsRuleSetting setting)
 {
     return(setting.MachineName + '_' + setting.AdsRuleName);
 }
 private string GetAlarmMessage(AdsRuleSetting setting)
 {
     return($"The Rule '{setting.AdsRuleName}' has triggered on machine {setting.MachineName}.");
 }
 public AdsRuleMonitor(AdsRuleSetting settings, Action <AdsRuleSetting> adsAlarmTrigger, Action <AdsRuleSetting> adsResetTriggerAlarm)
 {
     Settings              = settings;
     _adsAlarmTrigger      = adsAlarmTrigger;
     _adsResetTriggerAlarm = adsResetTriggerAlarm;
 }