From fc947a301f332218d587b287e07782cb1fb9cb49 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 3 Jan 2023 14:36:45 +0100 Subject: [PATCH] Hausmeisterei Teil 3 --- AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj | 9 +- .../webservice/ShipLocationReport.cs | 4 - AIS/bsmd.AIS2Service/zone_alarm/Alarm.cs | 30 +++ AIS/bsmd.AIS2Service/zone_alarm/DBEntity.cs | 25 +++ AIS/bsmd.AIS2Service/zone_alarm/GeoPoint.cs | 23 ++ .../zone_alarm/MonitorAssignment.cs | 44 ++++ .../zone_alarm/MonitorGroup.cs | 112 ++++++++++ .../zone_alarm/MonitorZone.cs | 198 +----------------- 8 files changed, 244 insertions(+), 201 deletions(-) create mode 100644 AIS/bsmd.AIS2Service/zone_alarm/Alarm.cs create mode 100644 AIS/bsmd.AIS2Service/zone_alarm/DBEntity.cs create mode 100644 AIS/bsmd.AIS2Service/zone_alarm/GeoPoint.cs create mode 100644 AIS/bsmd.AIS2Service/zone_alarm/MonitorAssignment.cs create mode 100644 AIS/bsmd.AIS2Service/zone_alarm/MonitorGroup.cs diff --git a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj index c944cd1e..f32903ea 100644 --- a/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj +++ b/AIS/bsmd.AIS2Service/bsmd.AIS2Service.csproj @@ -109,7 +109,12 @@ - + + + + + + @@ -127,7 +132,7 @@ Settings.settings - + diff --git a/AIS/bsmd.AIS2Service/webservice/ShipLocationReport.cs b/AIS/bsmd.AIS2Service/webservice/ShipLocationReport.cs index 5e947577..25d813f6 100644 --- a/AIS/bsmd.AIS2Service/webservice/ShipLocationReport.cs +++ b/AIS/bsmd.AIS2Service/webservice/ShipLocationReport.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace bsmd.AIS2Service { diff --git a/AIS/bsmd.AIS2Service/zone_alarm/Alarm.cs b/AIS/bsmd.AIS2Service/zone_alarm/Alarm.cs new file mode 100644 index 00000000..33d718c6 --- /dev/null +++ b/AIS/bsmd.AIS2Service/zone_alarm/Alarm.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2023 - schick Informatik +// bsmd.AIS2Service [Alarm.cs]: Daniel Schick +// Description: alarm created if vessel interacts with zone +// +using System; + +namespace bsmd.AIS2Service +{ + #region class Alarm + + public class Alarm : DBEntity + { + private readonly MonitorAssignment _assignment; + + public Alarm(long id, MonitorAssignment assignment) : base(id) { _assignment = assignment; } + + public MonitorAssignment Assignment { get { return _assignment; } } + + public DateTime Timestamp_First { get; set; } + + public DateTime? Timestamp_Last { get; set; } + + public DateTime? Acknowledged { get; set; } + + public MonitorAssignment.ZoneMonitorType ZoneMonitorType { get; set; } + + } + + #endregion +} diff --git a/AIS/bsmd.AIS2Service/zone_alarm/DBEntity.cs b/AIS/bsmd.AIS2Service/zone_alarm/DBEntity.cs new file mode 100644 index 00000000..a7080bd5 --- /dev/null +++ b/AIS/bsmd.AIS2Service/zone_alarm/DBEntity.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2023 - schick Informatik +// bsmd.AIS2Service [DBEntity.cs]: Daniel Schick +// Description: Root class for SQlite database entities +// + + +namespace bsmd.AIS2Service +{ + #region DBEntity + + public class DBEntity + { + protected long _id; // PK from database + + public DBEntity(long id) + { + _id = id; + } + + public long Id { get { return _id; } set { _id = value; } } + + } + + #endregion +} diff --git a/AIS/bsmd.AIS2Service/zone_alarm/GeoPoint.cs b/AIS/bsmd.AIS2Service/zone_alarm/GeoPoint.cs new file mode 100644 index 00000000..13f605ca --- /dev/null +++ b/AIS/bsmd.AIS2Service/zone_alarm/GeoPoint.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2023 - schick Informatik +// bsmd.AIS2Service.zone_alarm [GeoPoint.cs]: Daniel Schick +// Description: Single vertex of a zone +// + +namespace bsmd.AIS2Service +{ + #region class GeoPoint + + public class GeoPoint : DBEntity + { + + public GeoPoint(long id) : base(id) + { } + + public double Lat { get; set; } + public double Lon { get; set; } + + public long MonitorZoneId { get; set; } + } + + #endregion +} diff --git a/AIS/bsmd.AIS2Service/zone_alarm/MonitorAssignment.cs b/AIS/bsmd.AIS2Service/zone_alarm/MonitorAssignment.cs new file mode 100644 index 00000000..83b375ba --- /dev/null +++ b/AIS/bsmd.AIS2Service/zone_alarm/MonitorAssignment.cs @@ -0,0 +1,44 @@ +// Copyright (c) 2023 - schick Informatik +// bsmd.AIS2Service.zone_alarm [MonitorAssignment.cs]: Daniel Schick +// Description: Mapping between targets (MMSI) and zones +// +using System; +using System.Collections.Generic; + +namespace bsmd.AIS2Service +{ + #region class MonitorAssignment + + public class MonitorAssignment : DBEntity + { + + public MonitorAssignment(long id) : base(id) + { } + + [Flags] + public enum ZoneMonitorType + { + INACTIVE = 0, + ENTER = 1, + EXIT = 2, + PASSTHROUGH = 4, // outside - enter - inside - exit - outside + LEAVE_AND_RETURN = 8 // inside - exit - outside - enter - inside + } + + public int MMSI { get; set; } + + public ZoneMonitorType MonitorType { get; set; } = ZoneMonitorType.INACTIVE; + + public long MonitorZoneId { get; set; } + + public List Alarms { get; } = new List(); + + public override string ToString() + { + return String.Format("{0} {1}", MMSI, MonitorType); + } + + } + + #endregion +} diff --git a/AIS/bsmd.AIS2Service/zone_alarm/MonitorGroup.cs b/AIS/bsmd.AIS2Service/zone_alarm/MonitorGroup.cs new file mode 100644 index 00000000..79dd73f7 --- /dev/null +++ b/AIS/bsmd.AIS2Service/zone_alarm/MonitorGroup.cs @@ -0,0 +1,112 @@ +// Copyright (c) 2023 - schick Informatik +// bsmd.AIS2Service [MonitorGroup.cs]: Daniel Schick +// Description: Group container for zones +// +using log4net; +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml.Linq; + +namespace bsmd.AIS2Service +{ + #region class MonitorGroup + + public class MonitorGroup : DBEntity + { + + private static readonly ILog _log = LogManager.GetLogger(typeof(MonitorGroup)); + + #region fields + + private string _name; + private readonly List _zones = new List(); + + #endregion + + #region Construction + + public MonitorGroup(long id, string name) : base(id) + { + _name = name; + } + + #endregion + + #region Properties + + public List Zones { get { return _zones; } } + + public string Name { get { return _name; } set { _name = value; } } + + #endregion + + #region public static methods + + /// + /// Da Basti nun eine Datei mit allen Elementen exportiert gibt es eine einzelne Funktion, die alles + /// importiert + /// + /// + /// + public static List LoadGroups(string filename) + { + List groups = new List(); + try + { + if (File.Exists(filename)) + { + XDocument kml = XDocument.Load(filename); + XNamespace ns = "http://www.opengis.net/kml/2.2"; + + foreach (XElement rootFolderNode in kml.Root.Element(ns + "Document").Element(ns + "Folder").Elements(ns + "Folder")) + { + MonitorGroup mg = new MonitorGroup(-1, rootFolderNode.Element(ns + "name").Value); + int sequence = 1; + foreach (XElement placemark in rootFolderNode.Elements(ns + "Placemark")) + { + MonitorZone mz = new MonitorZone(-1, placemark.Element(ns + "name").Value); + mz.Active = true; + mz.Sequence = sequence; + // now add all vertices + string[] vertices = placemark.Element(ns + "Polygon").Element(ns + "outerBoundaryIs").Element(ns + "LinearRing").Element(ns + "coordinates").Value.Split(' '); + for (int i = 0; i < vertices.Length - 1; i++) + { + string[] pointElems = vertices[i].Trim().Split(','); + if (pointElems.Length != 3) continue; + GeoPoint gp = new GeoPoint(-1); + gp.Lon = Double.Parse(pointElems[0], System.Globalization.NumberFormatInfo.InvariantInfo); + gp.Lat = Double.Parse(pointElems[1], System.Globalization.NumberFormatInfo.InvariantInfo); + mz.Vertices.Add(gp); + } + + mg.Zones.Add(mz); + sequence++; + } + + groups.Add(mg); + } + } + } + catch (Exception ex) + { + _log.Error(ex.ToString()); + } + return groups; + } + + #endregion + + #region public methods + + public override string ToString() + { + return this.Name; + } + + #endregion + + } + + #endregion +} diff --git a/AIS/bsmd.AIS2Service/zone_alarm/MonitorZone.cs b/AIS/bsmd.AIS2Service/zone_alarm/MonitorZone.cs index 778458fe..c400e25a 100644 --- a/AIS/bsmd.AIS2Service/zone_alarm/MonitorZone.cs +++ b/AIS/bsmd.AIS2Service/zone_alarm/MonitorZone.cs @@ -3,8 +3,6 @@ // Description: Represents a geographical area that should be checked against // ship positions -using log4net; - using System; using System.Collections.Generic; using System.IO; @@ -12,124 +10,7 @@ using System.Linq; using System.Xml.Linq; namespace bsmd.AIS2Service -{ - - #region DBEntity - - public class DBEntity - { - protected long _id; // PK from database - - public DBEntity(long id) - { - _id = id; - } - - public long Id { get { return _id; } set { _id = value; } } - - } - - #endregion - - #region class MonitorGroup - - public class MonitorGroup : DBEntity - { - - private static readonly ILog _log = LogManager.GetLogger(typeof(MonitorGroup)); - - #region fields - - private string _name; - private readonly List _zones = new List(); - - #endregion - - #region Construction - - public MonitorGroup(long id, string name) : base( id ) - { - _name = name; - } - - #endregion - - #region Properties - - public List Zones { get { return _zones; } } - - public string Name { get { return _name; } set { _name = value; } } - - #endregion - - #region public static methods - - /// - /// Da Basti nun eine Datei mit allen Elementen exportiert gibt es eine einzelne Funktion, die alles - /// importiert - /// - /// - /// - public static List LoadGroups(string filename) - { - List groups = new List(); - try - { - if (File.Exists(filename)) - { - XDocument kml = XDocument.Load(filename); - XNamespace ns = "http://www.opengis.net/kml/2.2"; - - foreach(XElement rootFolderNode in kml.Root.Element(ns + "Document").Element(ns + "Folder").Elements(ns + "Folder")) - { - MonitorGroup mg = new MonitorGroup(-1, rootFolderNode.Element(ns + "name").Value); - int sequence = 1; - foreach(XElement placemark in rootFolderNode.Elements(ns + "Placemark")) - { - MonitorZone mz = new MonitorZone(-1, placemark.Element(ns + "name").Value); - mz.Active = true; - mz.Sequence = sequence; - // now add all vertices - string[] vertices = placemark.Element(ns + "Polygon").Element(ns + "outerBoundaryIs").Element(ns + "LinearRing").Element(ns + "coordinates").Value.Split(' '); - for (int i = 0; i < vertices.Length - 1; i++) - { - string[] pointElems = vertices[i].Trim().Split(','); - if (pointElems.Length != 3) continue; - GeoPoint gp = new GeoPoint(-1); - gp.Lon = Double.Parse(pointElems[0], System.Globalization.NumberFormatInfo.InvariantInfo); - gp.Lat = Double.Parse(pointElems[1], System.Globalization.NumberFormatInfo.InvariantInfo); - mz.Vertices.Add(gp); - } - - mg.Zones.Add(mz); - sequence++; - } - - groups.Add(mg); - } - } - } - catch(Exception ex) - { - _log.Error(ex.ToString()); - } - return groups; - } - - #endregion - - #region public methods - - public override string ToString() - { - return this.Name; - } - - #endregion - - } - - #endregion +{ #region class MonitorZone @@ -235,79 +116,6 @@ namespace bsmd.AIS2Service } - #endregion - - #region class GeoPoint - - public class GeoPoint : DBEntity - { - - public GeoPoint(long id) : base (id) - {} - - public double Lat { get; set; } - public double Lon { get; set; } - - public long MonitorZoneId { get; set; } - } - - #endregion - - #region class MonitorAssignment - - public class MonitorAssignment : DBEntity - { - - public MonitorAssignment(long id) : base(id) - {} - - [Flags] - public enum ZoneMonitorType - { - INACTIVE = 0, - ENTER = 1, - EXIT = 2, - PASSTHROUGH = 4, // outside - enter - inside - exit - outside - LEAVE_AND_RETURN = 8 // inside - exit - outside - enter - inside - } - - public int MMSI { get; set; } - - public ZoneMonitorType MonitorType { get; set; } = ZoneMonitorType.INACTIVE; - - public long MonitorZoneId { get; set; } - - public List Alarms { get; } = new List(); - - public override string ToString() - { - return String.Format("{0} {1}", MMSI, MonitorType); - } - - } - - #endregion - - #region class Alarm - - public class Alarm : DBEntity - { - private readonly MonitorAssignment _assignment; - - public Alarm(long id, MonitorAssignment assignment) : base(id) { _assignment = assignment; } - - public MonitorAssignment Assignment { get { return _assignment; } } - - public DateTime Timestamp_First { get; set; } - - public DateTime? Timestamp_Last { get; set; } - - public DateTime? Acknowledged { get; set; } - - public MonitorAssignment.ZoneMonitorType ZoneMonitorType { get; set; } - - } - - #endregion - + #endregion + }