diff --git a/AIS/SQL/CreateTables.sql b/AIS/SQL/CreateTables.sql new file mode 100644 index 00000000..6ba8d1d5 --- /dev/null +++ b/AIS/SQL/CreateTables.sql @@ -0,0 +1,110 @@ +PRINT N'Creating [dbo].[aisposreport]...'; + +GO +CREATE TABLE [dbo].[aisposreport] ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [MMSI] INT NOT NULL, + [NavStatus] INT NULL, + [ROT] INT NULL, + [COG] INT NULL, + [SOG] INT NULL, + [Accuracy] INT NULL, + [Longitude] INT NULL, + [Latitude] INT NULL, + [Heading] INT NULL, + [Timestamp] DATETIME NULL, + [Reserved] INT NULL, + [Spare] INT NULL, + [Raim] INT NULL, + [CommState] INT NULL, + [AISStationId] UNIQUEIDENTIFIER NOT NULL, + PRIMARY KEY CLUSTERED ([Id] ASC) +); + +GO + +ALTER TABLE [dbo].[aisposreport] + ADD DEFAULT newid() FOR [Id]; + +GO + +PRINT N'Creating [dbo].[aisstation]...'; + +GO +CREATE TABLE [dbo].[aisstation] ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [lat] INT NULL, + [lon] INT NULL, + [telnetHost] NVARCHAR (255) NULL, + [telnetPort] INT NULL, + [comPort] NVARCHAR (10) NULL, + [name] NVARCHAR (255) NULL, + [baudrate] INT NULL, + PRIMARY KEY CLUSTERED ([Id] ASC) +); + +GO + +PRINT N'Creating unnamed constraint on [dbo].[aisstation]...'; + +GO +ALTER TABLE [dbo].[aisstation] + ADD DEFAULT newid() FOR [Id]; + +PRINT N'Creating [dbo].[aisstaticdata]...'; + + +GO +CREATE TABLE [dbo].[aisstaticdata] ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [aisversion] INT NULL, + [imoNumber] INT NULL, + [callsign] NVARCHAR (10) NULL, + [name] NVARCHAR (100) NULL, + [shiptype] INT NULL, + [dimension] INT NULL, + [a] INT NULL, + [b] INT NULL, + [c] INT NULL, + [d] INT NULL, + [typeofdevice] INT NULL, + [etamonth] INT NULL, + [etaday] INT NULL, + [etahour] INT NULL, + [etaminute] INT NULL, + [maxpresetstaticdraught] INT NULL, + [destination] NVARCHAR (255) NULL, + [dte] INT NULL, + [spare] INT NULL, + PRIMARY KEY CLUSTERED ([Id] ASC) +); + +GO +PRINT N'Creating unnamed constraint on [dbo].[aisstaticdata]...'; + +GO +ALTER TABLE [dbo].[aisstaticdata] + ADD DEFAULT newid() FOR [Id]; + +GO + +PRINT N'Creating [dbo].[hotposition]...'; + +GO +CREATE TABLE [dbo].[hotposition] ( + [Id] UNIQUEIDENTIFIER NOT NULL, + [mmsi] INT NULL, + [pid] UNIQUEIDENTIFIER NOT NULL, + PRIMARY KEY CLUSTERED ([Id] ASC) +); + + +GO + +PRINT N'Creating unnamed constraint on [dbo].[aisstaticdata]...'; + +GO +ALTER TABLE [dbo].[aisstaticdata] + ADD DEFAULT newid() FOR [Id]; + +GO \ No newline at end of file diff --git a/AIS/bsmd.AISService/AIS/AIS_ClassB.cs b/AIS/bsmd.AISService/AIS/AIS_ClassB.cs index afe47a95..d77d2077 100644 --- a/AIS/bsmd.AISService/AIS/AIS_ClassB.cs +++ b/AIS/bsmd.AISService/AIS/AIS_ClassB.cs @@ -9,6 +9,7 @@ namespace bsmd.AISService.AIS { #region private members + private Guid? id; private int repeatIndicator; private int reserved; private int sog; @@ -30,6 +31,8 @@ namespace bsmd.AISService.AIS #region Properties + public Guid Id { get { if (!this.id.HasValue) this.id = Guid.NewGuid(); return this.id.Value; } } + public int CogVal { get { return this.cog; } } public int SogVal { get { return this.sog; } } public int LatitudeVal { get { return this.latitude; } } @@ -81,6 +84,26 @@ namespace bsmd.AISService.AIS } } + public int Reserved + { + get { return reserved; } + } + + public int Spare + { + get { return this.spare; } + } + + public int Raim + { + get { return this.raimFlag; } + } + + public int CommState + { + get { return this.commState; } + } + #endregion protected override AIS.Status Decode() diff --git a/AIS/bsmd.AISService/AIS/AIS_PosReport.cs b/AIS/bsmd.AISService/AIS/AIS_PosReport.cs index 949e5203..26a2b4fd 100644 --- a/AIS/bsmd.AISService/AIS/AIS_PosReport.cs +++ b/AIS/bsmd.AISService/AIS/AIS_PosReport.cs @@ -6,7 +6,8 @@ using System.Text; namespace bsmd.AISService.AIS { public class AIS_PosReport : AIS - { + { + private Guid? id; private int navstatus; private int rot; private int sog; @@ -24,6 +25,8 @@ namespace bsmd.AISService.AIS #region Properties + public Guid Id { get { if (!this.id.HasValue) this.id = Guid.NewGuid(); return this.id.Value; } } + public int NavStatusVal { get { return this.navstatus; } } public int ROTVal { get { return this.rot; } } public int SOGVal { get { return this.sog; } } @@ -101,6 +104,15 @@ namespace bsmd.AISService.AIS } } + public int Reserved { get { return this.reserved; } } + + public int Spare { get { return this.spare; } } + + public int Raim { get { return this.raim; } } + + public int CommState { get { return this.commstate; } } + + #endregion #region static methods diff --git a/AIS/bsmd.AISService/DB/AISBaseEntity.cs b/AIS/bsmd.AISService/DB/AISBaseEntity.cs new file mode 100644 index 00000000..8ce4075c --- /dev/null +++ b/AIS/bsmd.AISService/DB/AISBaseEntity.cs @@ -0,0 +1,30 @@ +// Copyright (c) 2008-2018 schick Informatik +// Description: Basisklasse der Entitäten +// + +using System; + +namespace bsmd.AISService.DB +{ + public abstract class AISBaseEntity + { + protected Guid? id; + + private bool isNew = true; + + public AISBaseEntity() { } + + public Guid? Id + { + get { return this.id; } + set { this.id = value; } + } + + public bool IsNew + { + get { return this.isNew; } + set { this.isNew = value; } + } + + } +} diff --git a/AIS/bsmd.AISService/DB/AISPosReport.cs b/AIS/bsmd.AISService/DB/AISPosReport.cs index ab6e6bc7..aee2b125 100644 --- a/AIS/bsmd.AISService/DB/AISPosReport.cs +++ b/AIS/bsmd.AISService/DB/AISPosReport.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) 2008-2018 schick Informatik +// Description: +// + +using System; using System.Diagnostics; using System.Collections.Generic; using System.Text; @@ -8,14 +12,14 @@ using bsmd.AISService.AIS; namespace bsmd.AISService.DB { - internal class AISPosReport + internal class AISPosReport : AISBaseEntity { /// /// Saves a (class A or B) position report /// /// target to save /// id of insert operation (to update hotposition table) - public static int? Save(AIS_Target target, DBConnector con, AISStation aisStation) + public static Guid? Save(AIS_Target target, DBConnector con, AISStation aisStation) { if (target.LastPosReport == null) return null; @@ -31,17 +35,14 @@ namespace bsmd.AISService.DB aisStation.OnAir = true; } - string query = string.Format("INSERT INTO aisposreport (mmsi, navstatus, rot, cog, sog, accur, longitude, latitude, heading, timestamp, stationid) VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, '{9}', {10})", - pr.MMSI, pr.NavStatusVal, pr.ROTVal, pr.COGVal, pr.SOGVal, pr.Accuracy, - pr.LongitudeVal, pr.LatitudeVal, pr.TrueHeading ?? 511, pr.DBTimestamp, - (aisStation != null) ? aisStation.Id : 0); + string query = string.Format("INSERT INTO aisposreport (Id, MMSI, NavStatus, ROT, COG, SOG, Accuracy, Longitude, Latitude, Heading, Timestamp, Reserved, Spare, Raim, CommState, AISStationId) VALUES ('{0}', {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, '{10}', {11},{12},{13},{14},'{15}')", + pr.Id, pr.MMSI, pr.NavStatusVal, pr.ROTVal, pr.COGVal, pr.SOGVal, pr.Accuracy, + pr.LongitudeVal, pr.LatitudeVal, pr.TrueHeading ?? 511, pr.DBTimestamp, pr.Reserved, pr.Spare, pr.Raim, pr.CommState, + (aisStation != null) ? aisStation.Id : Guid.Empty); con.ExecuteNonQuery(query); - object result = con.ExecuteScalar("SELECT LAST_INSERT_ID()"); - if (result == null) return null; - int pid = Convert.ToInt32(result); - return pid; + return pr.Id; } if (target.LastPosReport is AIS_ClassB) @@ -50,16 +51,13 @@ namespace bsmd.AISService.DB AIS_ClassB pr = target.LastPosReport as AIS_ClassB; aisStation.UpdateWithPositionReport(pr.MMSI, pr.Latitude, pr.Longitude, pr.Timestamp); - string query = string.Format("INSERT INTO aisposreport (mmsi, navstatus, rot, cog, sog, accur, longitude, latitude, heading, timestamp, stationid) VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, '{9}', {10})", + string query = string.Format("INSERT INTO aisposreport (Id, MMSI, NavStatus, ROT, COG, SOG, Accuracy, Longitude, Latitude, Heading, Timestamp, Reserved, Spare, Raim, CommState, Stationid) VALUES ('{0}', {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, '{10}', {11},{12},{13},{14},'{15}')", pr.MMSI, 0, 0, pr.CogVal, pr.SogVal, 0, pr.LongitudeVal, pr.LatitudeVal, - pr.TrueHeading ?? 511, pr.DBTimestamp, (aisStation != null) ? aisStation.Id : 0); + pr.TrueHeading ?? 511, pr.DBTimestamp, pr.Reserved, pr.Spare, pr.Raim, pr.CommState, (aisStation != null) ? aisStation.Id : Guid.Empty); con.ExecuteNonQuery(query); - - object result = con.ExecuteScalar("SELECT LAST_INSERT_ID()"); - if (result == null) return null; - int pid = Convert.ToInt32(result); - return pid; + + return pr.Id; } if (target.LastPosReport is AIS_ClassBExt) diff --git a/AIS/bsmd.AISService/DB/AISStaticData.cs b/AIS/bsmd.AISService/DB/AISStaticData.cs index 7bcc3cce..051dfcd8 100644 --- a/AIS/bsmd.AISService/DB/AISStaticData.cs +++ b/AIS/bsmd.AISService/DB/AISStaticData.cs @@ -10,7 +10,7 @@ using bsmd.AISService.AIS; namespace bsmd.AISService.DB { - public class AISStaticData + public class AISStaticData : AISBaseEntity { public enum DisplayStringType diff --git a/AIS/bsmd.AISService/DB/AISStation.cs b/AIS/bsmd.AISService/DB/AISStation.cs index b3d159ea..bb264494 100644 --- a/AIS/bsmd.AISService/DB/AISStation.cs +++ b/AIS/bsmd.AISService/DB/AISStation.cs @@ -9,7 +9,7 @@ using bsmd.AISService.AIS; namespace bsmd.AISService.DB { - public class AISStation + public class AISStation : AISBaseEntity { #region private members @@ -35,8 +35,7 @@ namespace bsmd.AISService.DB #region Properties - public string Name { get { return this.name; } set { this.name = value; } } - public int Id { get { return this.station_Id; } } + public string Name { get { return this.name; } set { this.name = value; } } public bool Active { get { return this.active; } set { this.active = value; } } public string COMPort { get { return this.comport; } set { this.comport = value; } } public int Baudrate { get { return this.baudrate; } set { this.baudrate = value; } } diff --git a/AIS/bsmd.AISService/DB/DBConnector.cs b/AIS/bsmd.AISService/DB/DBConnector.cs index d0faf89e..88252259 100644 --- a/AIS/bsmd.AISService/DB/DBConnector.cs +++ b/AIS/bsmd.AISService/DB/DBConnector.cs @@ -131,7 +131,7 @@ namespace bsmd.AISService.DB if (target.LastPosReport != null) { Hotposition hotposition = Hotposition.LoadForMMSI(target.MMSI, this); - int? pid = AISPosReport.Save(target, this, updateStations.ContainsKey(target.Station) ? updateStations[target.Station] : null); + Guid? pid = AISPosReport.Save(target, this, updateStations.ContainsKey(target.Station) ? updateStations[target.Station] : null); if (pid.HasValue) { hotposition.PosReportId = pid.Value; diff --git a/AIS/bsmd.AISService/DB/Hotposition.cs b/AIS/bsmd.AISService/DB/Hotposition.cs index 25d85d7c..9aa37256 100644 --- a/AIS/bsmd.AISService/DB/Hotposition.cs +++ b/AIS/bsmd.AISService/DB/Hotposition.cs @@ -7,18 +7,17 @@ using bsmd.AISService.AIS; namespace bsmd.AISService.DB { - internal class Hotposition - { - private int id; + internal class Hotposition : AISBaseEntity + { private int mmsi; - private int pid; + private Guid pid; public int MMSI { get { return this.mmsi; } } - public int PosReportId + public Guid PosReportId { get { return this.pid; } set { this.pid = value; } @@ -26,7 +25,7 @@ namespace bsmd.AISService.DB public void Save(DBConnector con) { - string query = string.Format("UPDATE hotposition SET mmsi={0}, pid={1} WHERE id={2}", + string query = string.Format("UPDATE hotposition SET mmsi={0}, pid='{1}' WHERE id='{2}'", this.mmsi, this.pid, this.id); con.ExecuteNonQuery(query); } @@ -41,10 +40,10 @@ namespace bsmd.AISService.DB while (reader.Read()) { Hotposition hp = new Hotposition(); - hp.id = reader.GetInt32(0); + hp.id = reader.GetGuid(0); hp.mmsi = mmsi; if (!reader.IsDBNull(1)) - hp.pid = reader.GetInt32(1); + hp.pid = reader.GetGuid(1); results.Add(hp); } reader.Close(); @@ -54,12 +53,11 @@ namespace bsmd.AISService.DB { // neuen Eintrag erzeugen Hotposition hp = new Hotposition(); - string insertQuery = string.Format("INSERT INTO hotposition SET mmsi={0}", mmsi); - con.ExecuteNonQuery(insertQuery); - - object ob = con.ExecuteScalar("SELECT LAST_INSERT_ID()"); - hp.id = Convert.ToInt32(ob); + hp.Id = Guid.NewGuid(); hp.mmsi = mmsi; + hp.IsNew = false; + string insertQuery = string.Format("INSERT INTO hotposition (id, mmsi) VALUES ('{0}', {1})", hp.Id, mmsi); + con.ExecuteNonQuery(insertQuery); return hp; } else if (results.Count == 1) diff --git a/AIS/bsmd.AISService/ProjectInstaller.Designer.cs b/AIS/bsmd.AISService/ProjectInstaller.Designer.cs new file mode 100644 index 00000000..88477230 --- /dev/null +++ b/AIS/bsmd.AISService/ProjectInstaller.Designer.cs @@ -0,0 +1,58 @@ +namespace bsmd.AISService +{ + partial class ProjectInstaller + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.serviceProcessInstallerAIS = new System.ServiceProcess.ServiceProcessInstaller(); + this.serviceInstallerAIS = new System.ServiceProcess.ServiceInstaller(); + // + // serviceProcessInstallerAIS + // + this.serviceProcessInstallerAIS.Password = null; + this.serviceProcessInstallerAIS.Username = null; + // + // serviceInstallerAIS + // + this.serviceInstallerAIS.Description = "Service to read AIS data into a database"; + this.serviceInstallerAIS.DisplayName = "BSMD AIS Service"; + this.serviceInstallerAIS.ServiceName = "AISService"; + // + // ProjectInstaller + // + this.Installers.AddRange(new System.Configuration.Install.Installer[] { + this.serviceProcessInstallerAIS, + this.serviceInstallerAIS}); + + } + + #endregion + + private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstallerAIS; + private System.ServiceProcess.ServiceInstaller serviceInstallerAIS; + } +} \ No newline at end of file diff --git a/AIS/bsmd.AISService/ProjectInstaller.cs b/AIS/bsmd.AISService/ProjectInstaller.cs new file mode 100644 index 00000000..fb9abb9e --- /dev/null +++ b/AIS/bsmd.AISService/ProjectInstaller.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration.Install; +using System.Linq; +using System.Threading.Tasks; + +namespace bsmd.AISService +{ + [RunInstaller(true)] + public partial class ProjectInstaller : System.Configuration.Install.Installer + { + public ProjectInstaller() + { + InitializeComponent(); + } + } +} diff --git a/AIS/bsmd.AISService/ProjectInstaller.resx b/AIS/bsmd.AISService/ProjectInstaller.resx new file mode 100644 index 00000000..7fb3a7a1 --- /dev/null +++ b/AIS/bsmd.AISService/ProjectInstaller.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 196, 17 + + + False + + \ No newline at end of file diff --git a/AIS/bsmd.AISService/bsmd.AISService.csproj b/AIS/bsmd.AISService/bsmd.AISService.csproj index 158fffcc..a42a1192 100644 --- a/AIS/bsmd.AISService/bsmd.AISService.csproj +++ b/AIS/bsmd.AISService/bsmd.AISService.csproj @@ -80,6 +80,7 @@ + diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index fc3530a8..fc2b598e 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.database/NOA_NOD.cs b/nsw/Source/bsmd.database/NOA_NOD.cs index 90445592..e79ef313 100644 --- a/nsw/Source/bsmd.database/NOA_NOD.cs +++ b/nsw/Source/bsmd.database/NOA_NOD.cs @@ -232,6 +232,8 @@ namespace bsmd.database { if (cp.CallPurposeCode == 0) errors.Add(RuleEngine.CreateError(ValidationCode.INT_GT_ZERO, "CallPurposeCode", "0", this.Title, cp.Identifier, this.Tablename)); + if(!cp.CallPurposeDescription.IsNullOrEmpty() && (cp.CallPurposeDescription.Length > 94)) + violations.Add(RuleEngine.CreateViolation(ValidationCode.TRUNCATE, "CallPurposeDescription", cp.CallPurposeDescription, this.Title, cp.Identifier, this.Tablename)); } } }