Änderungen im neuen AIS Projekt

This commit is contained in:
Daniel Schick 2018-02-09 05:57:04 +00:00
parent 061f3e1213
commit 836ce716aa
15 changed files with 416 additions and 37 deletions

110
AIS/SQL/CreateTables.sql Normal file
View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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; }
}
}
}

View File

@ -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
{
/// <summary>
/// Saves a (class A or B) position report
/// </summary>
/// <param name="target">target to save</param>
/// <returns>id of insert operation (to update hotposition table)</returns>
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)

View File

@ -10,7 +10,7 @@ using bsmd.AISService.AIS;
namespace bsmd.AISService.DB
{
public class AISStaticData
public class AISStaticData : AISBaseEntity
{
public enum DisplayStringType

View File

@ -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; } }

View File

@ -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;

View File

@ -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)

View File

@ -0,0 +1,58 @@
namespace bsmd.AISService
{
partial class ProjectInstaller
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="serviceProcessInstallerAIS.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="serviceInstallerAIS.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>196, 17</value>
</metadata>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

View File

@ -80,6 +80,7 @@
<Compile Include="AIS\SerialDataHandler.cs" />
<Compile Include="AIS\Serial_IO.cs" />
<Compile Include="AIS\TelnetDataHandler.cs" />
<Compile Include="DB\AISBaseEntity.cs" />
<Compile Include="DB\AISPosReport.cs" />
<Compile Include="DB\AISStaticData.cs" />
<Compile Include="DB\AISStation.cs" />

Binary file not shown.

View File

@ -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));
}
}
}