AIS 2 CSV Tool completed

This commit is contained in:
Daniel Schick 2019-05-13 07:04:17 +00:00
parent 110a22d112
commit 549f78a6e9
8 changed files with 54 additions and 24 deletions

View File

@ -23,7 +23,7 @@ namespace bsmd.AISService.AIS
private int raim; private int raim;
private int commstate; private int commstate;
private static ILog _log = LogManager.GetLogger(typeof(AIS_PosReport)); private static readonly ILog _log = LogManager.GetLogger(typeof(AIS_PosReport));
#region Properties #region Properties

View File

@ -18,7 +18,7 @@ namespace bsmd.AISService
public partial class AISService : ServiceBase public partial class AISService : ServiceBase
{ {
private const string config_filename = "ais_config.xml"; private const string config_filename = "ais_config.xml";
private ILog _log = LogManager.GetLogger(typeof(AISService)); private readonly ILog _log = LogManager.GetLogger(typeof(AISService));
private AIS_QueueManager qManager; private AIS_QueueManager qManager;
public AISService() public AISService()
@ -45,7 +45,6 @@ namespace bsmd.AISService
{ {
_log.ErrorFormat("AIS Service start failed: {0}", errorMessage); _log.ErrorFormat("AIS Service start failed: {0}", errorMessage);
} }
} }
internal void DebugStart() internal void DebugStart()
@ -74,8 +73,7 @@ namespace bsmd.AISService
return; return;
} }
DBConnector dbConnector = new DBConnector(); DBConnector dbConnector = new DBConnector { ConnectionString = configuration.DBConnectionString };
dbConnector.ConnectionString = configuration.DBConnectionString;
if (!dbConnector.Open()) if (!dbConnector.Open())
{ {
_log.Error("Error connecting to database"); _log.Error("Error connecting to database");

View File

@ -11,7 +11,7 @@ namespace bsmd.AISService.DB
{ {
internal class AISPosReport : AISBaseEntity { internal class AISPosReport : AISBaseEntity {
private static ILog _log = LogManager.GetLogger(typeof(AISPosReport)); private static readonly ILog _log = LogManager.GetLogger(typeof(AISPosReport));
/// <summary> /// <summary>
/// Saves a (class A or B) position report /// Saves a (class A or B) position report

View File

@ -1,12 +1,12 @@
extensions: designer.cs generated.cs extensions: designer.cs generated.cs
extensions: .cs .cpp .h extensions: .cs .cpp .h
// Copyright (c) 2008-2018 schick Informatik // Copyright (c) 2008-2019 schick Informatik
// Description: // Description:
// //
extensions: .aspx .ascx extensions: .aspx .ascx
<%-- <%--
Copyright (c) 2008-2018 schick Informatik Copyright (c) 2008-2019 schick Informatik
--%> --%>
extensions: .vb extensions: .vb
'Sample license text. 'Sample license text.

View File

@ -1,8 +1,8 @@
using System; // Copyright (c) 2008-2019 schick Informatik
using System.Collections.Generic; // Description: Erzeugt eine CSV Datei aus dem Query
using System.Linq; //
using System.Text;
using System.Threading.Tasks; using System;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.IO; using System.IO;
@ -11,9 +11,11 @@ namespace puls200.AIS2Excel
{ {
public static class AISVessel public static class AISVessel
{ {
const string ExportQuery = "SELECT aisposreport.MMSI, aisposreport.timestamp, aisposreport.latitude, aisposreport.longitude, aisposreport.stationid, aisposreport.cog, aisposreport.heading, aisposreport.navstatus, aisstaticdata.callsign, aisstaticdata.name, aisstaticdata.shiptype, aisstaticdata.classb, aisstaticdata.shipdescription " + const string ExportQuery = "SELECT ap.MMSI, ap.timestamp, ap.latitude, ap.longitude, ap.ROT, ap.COG, ap.SOG, ap.Accuracy, ap.heading, ap.NavStatus, ap.CommState, ap.Raim, " +
"FROM aisstaticdata JOIN aisposreport ON aisposreport.mmsi = aisstaticdata.mmsi " + "sd.aisversion, sd.imoNumber, sd.callsign, sd.name, sd.shiptype, sd.dimension, sd.typeofdevice, sd.maxpresetstaticdraught, sd.dte, sd.classb, sd.breadth, sd.length " +
"WHERE lat lon timestamp ORDER BY posreport.timestamp"; "FROM aisstaticdata sd JOIN aisposreport ap ON ap.mmsi = sd.mmsi " +
"WHERE ap.Latitude > @LRLAT AND ap.Latitude < @ULLAT AND ap.Longitude > @ULLON AND ap.Longitude < @LRLON AND ap.Timestamp > @FROM AND ap.Timestamp < @TO " +
"ORDER BY ap.Timestamp";
public static void Export(DateTime from, DateTime to, double ulLat, double ulLon, double lrLat, double lrLon, string filename) public static void Export(DateTime from, DateTime to, double ulLat, double ulLon, double lrLat, double lrLon, string filename)
@ -25,6 +27,13 @@ namespace puls200.AIS2Excel
con.Open(); con.Open();
SqlCommand cmd = new SqlCommand(ExportQuery, con); SqlCommand cmd = new SqlCommand(ExportQuery, con);
cmd.Parameters.AddWithValue("FROM", from);
cmd.Parameters.AddWithValue("TO", to);
cmd.Parameters.AddWithValue("ULLAT", ulLat * 600000);
cmd.Parameters.AddWithValue("ULLON", ulLon * 600000);
cmd.Parameters.AddWithValue("LRLAT", lrLat * 600000);
cmd.Parameters.AddWithValue("LRLON", lrLon * 600000);
IDataReader reader = cmd.ExecuteReader(); IDataReader reader = cmd.ExecuteReader();
createCsvFile(reader, sw); createCsvFile(reader, sw);
reader.Close(); reader.Close();
@ -35,7 +44,7 @@ namespace puls200.AIS2Excel
public static void createCsvFile(IDataReader reader, StreamWriter writer) public static void createCsvFile(IDataReader reader, StreamWriter writer)
{ {
const string Delimiter = "\""; const string Delimiter = "\"";
const string Separator = ","; const string Separator = ";";
// write header row // write header row
for (int columnCounter = 0; columnCounter < reader.FieldCount; columnCounter++) for (int columnCounter = 0; columnCounter < reader.FieldCount; columnCounter++)

View File

@ -11,7 +11,7 @@
<applicationSettings> <applicationSettings>
<puls200.AIS2Excel.Properties.Settings> <puls200.AIS2Excel.Properties.Settings>
<setting name="ConnectionString" serializeAs="String"> <setting name="ConnectionString" serializeAs="String">
<value /> <value>Data Source=192.168.2.12;Initial Catalog=ais;Uid=aisuser;Pwd=aispasswd;Connect Timeout=30;Encrypt=False;</value>
</setting> </setting>
</puls200.AIS2Excel.Properties.Settings> </puls200.AIS2Excel.Properties.Settings>
</applicationSettings> </applicationSettings>

View File

@ -102,6 +102,11 @@
this.numericUpDownULLongitude.Name = "numericUpDownULLongitude"; this.numericUpDownULLongitude.Name = "numericUpDownULLongitude";
this.numericUpDownULLongitude.Size = new System.Drawing.Size(83, 20); this.numericUpDownULLongitude.Size = new System.Drawing.Size(83, 20);
this.numericUpDownULLongitude.TabIndex = 3; this.numericUpDownULLongitude.TabIndex = 3;
this.numericUpDownULLongitude.Value = new decimal(new int[] {
907,
0,
0,
131072});
// //
// numericUpDownULLatitude // numericUpDownULLatitude
// //
@ -120,6 +125,11 @@
this.numericUpDownULLatitude.Name = "numericUpDownULLatitude"; this.numericUpDownULLatitude.Name = "numericUpDownULLatitude";
this.numericUpDownULLatitude.Size = new System.Drawing.Size(83, 20); this.numericUpDownULLatitude.Size = new System.Drawing.Size(83, 20);
this.numericUpDownULLatitude.TabIndex = 2; this.numericUpDownULLatitude.TabIndex = 2;
this.numericUpDownULLatitude.Value = new decimal(new int[] {
5391,
0,
0,
131072});
// //
// groupBox2 // groupBox2
// //
@ -150,7 +160,12 @@
-2147483648}); -2147483648});
this.numericUpDownLRLongitude.Name = "numericUpDownLRLongitude"; this.numericUpDownLRLongitude.Name = "numericUpDownLRLongitude";
this.numericUpDownLRLongitude.Size = new System.Drawing.Size(83, 20); this.numericUpDownLRLongitude.Size = new System.Drawing.Size(83, 20);
this.numericUpDownLRLongitude.TabIndex = 4; this.numericUpDownLRLongitude.TabIndex = 5;
this.numericUpDownLRLongitude.Value = new decimal(new int[] {
921,
0,
0,
131072});
// //
// numericUpDownLRLatitude // numericUpDownLRLatitude
// //
@ -168,7 +183,12 @@
-2147483648}); -2147483648});
this.numericUpDownLRLatitude.Name = "numericUpDownLRLatitude"; this.numericUpDownLRLatitude.Name = "numericUpDownLRLatitude";
this.numericUpDownLRLatitude.Size = new System.Drawing.Size(83, 20); this.numericUpDownLRLatitude.Size = new System.Drawing.Size(83, 20);
this.numericUpDownLRLatitude.TabIndex = 5; this.numericUpDownLRLatitude.TabIndex = 4;
this.numericUpDownLRLatitude.Value = new decimal(new int[] {
5385,
0,
0,
131072});
// //
// label4 // label4
// //
@ -202,7 +222,7 @@
this.textBoxExportFile.Location = new System.Drawing.Point(101, 163); this.textBoxExportFile.Location = new System.Drawing.Point(101, 163);
this.textBoxExportFile.Name = "textBoxExportFile"; this.textBoxExportFile.Name = "textBoxExportFile";
this.textBoxExportFile.Size = new System.Drawing.Size(254, 20); this.textBoxExportFile.Size = new System.Drawing.Size(254, 20);
this.textBoxExportFile.TabIndex = 5; this.textBoxExportFile.TabIndex = 8;
// //
// buttonFileBrowse // buttonFileBrowse
// //
@ -221,7 +241,7 @@
this.buttonExport.Location = new System.Drawing.Point(101, 189); this.buttonExport.Location = new System.Drawing.Point(101, 189);
this.buttonExport.Name = "buttonExport"; this.buttonExport.Name = "buttonExport";
this.buttonExport.Size = new System.Drawing.Size(83, 23); this.buttonExport.Size = new System.Drawing.Size(83, 23);
this.buttonExport.TabIndex = 7; this.buttonExport.TabIndex = 9;
this.buttonExport.Text = "Export"; this.buttonExport.Text = "Export";
this.buttonExport.UseVisualStyleBackColor = false; this.buttonExport.UseVisualStyleBackColor = false;
this.buttonExport.Click += new System.EventHandler(this.ButtonExport_Click); this.buttonExport.Click += new System.EventHandler(this.ButtonExport_Click);
@ -251,7 +271,7 @@
this.dateTimePickerFrom.Location = new System.Drawing.Point(101, 102); this.dateTimePickerFrom.Location = new System.Drawing.Point(101, 102);
this.dateTimePickerFrom.Name = "dateTimePickerFrom"; this.dateTimePickerFrom.Name = "dateTimePickerFrom";
this.dateTimePickerFrom.Size = new System.Drawing.Size(254, 20); this.dateTimePickerFrom.Size = new System.Drawing.Size(254, 20);
this.dateTimePickerFrom.TabIndex = 10; this.dateTimePickerFrom.TabIndex = 6;
// //
// dateTimePickerTo // dateTimePickerTo
// //
@ -260,7 +280,7 @@
this.dateTimePickerTo.Location = new System.Drawing.Point(101, 128); this.dateTimePickerTo.Location = new System.Drawing.Point(101, 128);
this.dateTimePickerTo.Name = "dateTimePickerTo"; this.dateTimePickerTo.Name = "dateTimePickerTo";
this.dateTimePickerTo.Size = new System.Drawing.Size(254, 20); this.dateTimePickerTo.Size = new System.Drawing.Size(254, 20);
this.dateTimePickerTo.TabIndex = 11; this.dateTimePickerTo.TabIndex = 7;
// //
// Main // Main
// //

View File

@ -67,6 +67,9 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="..\bsmd.AISService\bsmd.AISService.licenseheader">
<Link>bsmd.AISService.licenseheader</Link>
</None>
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>