git_bsmd/AIS/bsmd.AIS2Service/AISZoneMonitor.cs
Daniel Schick 47adcbacf1 ZONE MONITORING WIP 1
added classes for vertices, polygons (zones) and a monitoring vlass
2025-09-01 10:05:55 +02:00

88 lines
2.1 KiB
C#

// 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<int, AIS_Target> _sitRepDict;
private Thread _thread;
private bool _stopFlag = false;
#endregion
#region Construction
public AISZoneMonitor(ConcurrentDictionary<int, AIS_Target> 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
}
}