// Copyright (c) 2022 - schick Informatik // bsmd.AIS2Service [AISZoneMonitor.cs]: %UserDisplayName% // Description: Background Thread Controller class for comparing AIS Targets // to monitor zones // using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace bsmd.AIS2Service { internal class AISZoneMonitor : IAISThread { #region Fields ConcurrentDictionary _sitRepDict; private Thread _thread; private bool _stopFlag = false; #endregion #region Construction public AISZoneMonitor(ConcurrentDictionary sitRepDict) { _sitRepDict = sitRepDict; } #endregion #region private methods private void Monitor() { // load zones from storage // loop while(!_stopFlag) { // check all "current" AIS Targets against the zones int currentSaturationSecs = 0; // (DateTime.Now - alarm.FirstDetected).TotalSeconds; if(currentSaturationSecs > Properties.Settings.Default.MonitorTargetSaturationSecs) { // trigger alarm, this thing was "hot" long enough } Thread.Sleep(Properties.Settings.Default.MonitorTestIntervalSecs * 1000); } } #endregion #region IAISThread implementation public string Name { get { return "Zone monitor"; } } public event EventHandler FatalErrorOccurred; public void Start() { if (_thread != null) return; // may not run twice ThreadStart runReader = new ThreadStart(this.Monitor); _thread = new Thread(runReader); _thread.Start(); } public void Stop() { if (_thread == null) return; _stopFlag = true; _thread.Join(); _thread = null; } #endregion } }