diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 208023f2..a58adaa0 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/SendNSWMessageService.sln b/nsw/Source/SendNSWMessageService.sln new file mode 100644 index 00000000..c169f75d --- /dev/null +++ b/nsw/Source/SendNSWMessageService.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendNSWMessageService", "SendNSWMessageService\SendNSWMessageService.csproj", "{E6F8F110-77E7-4348-9875-CAD095BF8E24}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.dbh", "bsmd.dbh\bsmd.dbh.csproj", "{DF625FF0-2265-4686-9CB6-2A8511CB3B9D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.database", "bsmd.database\bsmd.database.csproj", "{19945AF2-379B-46A5-B27A-303B5EC1D557}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.dakosy", "bsmd.dakosy\bsmd.dakosy.csproj", "{6255F8C4-B0B5-4E77-860E-10EBCD7B368F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E6F8F110-77E7-4348-9875-CAD095BF8E24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6F8F110-77E7-4348-9875-CAD095BF8E24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6F8F110-77E7-4348-9875-CAD095BF8E24}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6F8F110-77E7-4348-9875-CAD095BF8E24}.Release|Any CPU.Build.0 = Release|Any CPU + {DF625FF0-2265-4686-9CB6-2A8511CB3B9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF625FF0-2265-4686-9CB6-2A8511CB3B9D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF625FF0-2265-4686-9CB6-2A8511CB3B9D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF625FF0-2265-4686-9CB6-2A8511CB3B9D}.Release|Any CPU.Build.0 = Release|Any CPU + {19945AF2-379B-46A5-B27A-303B5EC1D557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19945AF2-379B-46A5-B27A-303B5EC1D557}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19945AF2-379B-46A5-B27A-303B5EC1D557}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19945AF2-379B-46A5-B27A-303B5EC1D557}.Release|Any CPU.Build.0 = Release|Any CPU + {6255F8C4-B0B5-4E77-860E-10EBCD7B368F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6255F8C4-B0B5-4E77-860E-10EBCD7B368F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6255F8C4-B0B5-4E77-860E-10EBCD7B368F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6255F8C4-B0B5-4E77-860E-10EBCD7B368F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/nsw/Source/SendNSWMessageService/NSWSendService.cs b/nsw/Source/SendNSWMessageService/NSWSendService.cs index f60f75ce..00054eff 100644 --- a/nsw/Source/SendNSWMessageService/NSWSendService.cs +++ b/nsw/Source/SendNSWMessageService/NSWSendService.cs @@ -65,44 +65,47 @@ namespace SendNSWMessageService if (DBManager.Instance.Connect(Properties.Settings.Default.ConnectionString)) { - // Datenbank auf zu sendende Objekte überprüfen und laden + // Datenbank auf zu sendende Objekte überprüfen und laden + + List messagesToSendList = DBManager.Instance.GetToSendMessageList(); - // "Core"-Messages sind Erst-Anmeldungen (für VISIT/TRANSIT Id) am NSW - List toSendList = DBManager.Instance.GetToSendMessageCoreList(); - - - foreach (MessageCore aMessageCore in toSendList) + foreach (Message message in messagesToSendList) { - string message = string.Format("Sending CORE message for {0} application to {1}", - aMessageCore.IsTransit ? "TRANSIT" : "VISIT", aMessageCore.InitialHIS.ToString()); - _log.Info(message); - - // switch über passendes HIS / Schnittstelle - switch (aMessageCore.InitialHIS) + try { - case Message.NSWProvider.DBH: - //bsmd.dbh.Request.SendMessage() + _log.InfoFormat("Sending CORE message for {0} application to {1}", + message.MessageCore.IsTransit ? "TRANSIT" : "VISIT", message.MessageCore.InitialHIS.ToString()); - break; - case Message.NSWProvider.DAKOSY: + // switch über passendes HIS / Schnittstelle + switch (message.MessageCore.InitialHIS) + { + case Message.NSWProvider.DBH: + bsmd.dbh.Request.SendMessage(message); - break; + break; + case Message.NSWProvider.DAKOSY: - case Message.NSWProvider.DUDR: + break; - break; - default: + case Message.NSWProvider.DUDR: - break; + break; + default: + break; + + + } + + // senden + + // .. } - - // senden - - // .. - - + catch (Exception ex) + { + _log.ErrorFormat("SENDING message {0}: {1}", message.ToString(), ex.Message); + } } DBManager.Instance.Disconnect(); diff --git a/nsw/Source/SendNSWMessageService/packages.config b/nsw/Source/SendNSWMessageService/packages.config new file mode 100644 index 00000000..981a91a1 --- /dev/null +++ b/nsw/Source/SendNSWMessageService/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/nsw/Source/bsmd.dakosy/packages.config b/nsw/Source/bsmd.dakosy/packages.config new file mode 100644 index 00000000..981a91a1 --- /dev/null +++ b/nsw/Source/bsmd.dakosy/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/nsw/Source/bsmd.database/DBManager.cs b/nsw/Source/bsmd.database/DBManager.cs new file mode 100644 index 00000000..cb29dc35 --- /dev/null +++ b/nsw/Source/bsmd.database/DBManager.cs @@ -0,0 +1,197 @@ +// +// Class: DBManager +// Current CLR: 4.0.30319.34209 +// System: Microsoft Visual Studio 10.0 +// Author: dani +// Created: 3/10/2015 7:25:55 AM +// +// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using log4net; + +namespace bsmd.database +{ + public class DBManager + { + private SqlConnection _con; + private static DBManager _instance; + private ILog _log = LogManager.GetLogger(typeof(DBManager)); + + #region Properties + + public static DBManager Instance + { + get + { + if (_instance == null) + _instance = new DBManager(); + return _instance; + } + } + + public string ConnectionString { get; set; } + + #endregion + + #region public DB funcs + + public bool Connect(string dbConnectionString) + { + try + { + _con = new SqlConnection(dbConnectionString); + _con.Open(); + return true; + } + catch (Exception ex) + { + _log.Error("DBManager cannot connect", ex); + return false; + } + } + + public void Disconnect() + { + if ((this._con != null) && (this._con.State == ConnectionState.Open)) + this._con.Close(); + } + + #endregion + + #region public helper funcs + + public Dictionary GetToSendMessageCoreList() + { + MessageCore aMessageCore = new MessageCore(); + SqlCommand cmd = new SqlCommand(); + Message.LoadFilter filter = Message.LoadFilter.BSMDSTATUS; + aMessageCore.PrepareLoadCommand(cmd, filter, Message.BSMDStatus.TOSEND); + + SqlDataReader reader = this.PerformCommand(cmd); + List cores = aMessageCore.LoadList(reader); + Dictionary result = new Dictionary(); + foreach (MessageCore core in cores) + result.Add(core.Id.Value, core); + return result; + } + + public List GetToSendMessageList() + { + Message aMessage = new Message(); + SqlCommand cmd = new SqlCommand(); + Message.LoadFilter filter = Message.LoadFilter.BSMDSTATUS; + aMessage.PrepareLoadCommand(cmd, filter, Message.BSMDStatus.TOSEND); + + SqlDataReader reader = this.PerformCommand(cmd); + List messages = aMessage.LoadList(reader); + List result = new List(); + foreach (Message message in messages) + result.Add(message); + + this.LoadMessageDependencies(result); + + return result; + } + + public Dictionary GetReportingPartyDict() + { + ReportingParty aRep = new ReportingParty(); + SqlCommand cmd = new SqlCommand(); + aRep.PrepareLoadCommand(cmd, Message.LoadFilter.ALL); + + SqlDataReader reader = this.PerformCommand(cmd); + List reportingParties = aRep.LoadList(reader); + Dictionary result = new Dictionary(); + foreach (ReportingParty rp in reportingParties) + result.Add(rp.Id.Value, rp); + + return result; + } + + #endregion + + #region internal/private funcs + + internal void LoadMessageDependencies(List messageList) + { + Dictionary messageCoreDict = this.GetToSendMessageCoreList(); + Dictionary reportingPartyDict = this.GetReportingPartyDict(); + + // Zuordnung MessageCore,Zuordnung Reporting party + Message.AssignReportingParties(messageList, reportingPartyDict); + Message.AssignMessageCores(messageList, messageCoreDict); + + foreach (Message message in messageList) + { + this.LoadErrorList(message); + this.LoadViolationList(message); + + SqlCommand cmd = new SqlCommand(); + + switch(message.MessageNotificationClass) + { + case Message.NotificationClass.STAT: + STAT stat = new STAT(); + stat.PrepareLoadCommand(cmd, Message.LoadFilter.MESSAGEHEADER, message.Id); + SqlDataReader reader = this.PerformCommand(cmd); + List statList = stat.LoadList(reader); + if (statList.Count > 0) + message.DerivedMessage = statList[0]; + ((STAT)statList[0]).MessageHeader = message; + break; + default: + break; + + } + + } + + } + + internal void LoadErrorList(Message message) + { + MessageError aMessageError = new MessageError(); + SqlCommand cmd = new SqlCommand(); + aMessageError.PrepareLoadCommand(cmd, Message.LoadFilter.MESSAGEHEADER, message.Id); + SqlDataReader reader = this.PerformCommand(cmd); + List errorList = aMessageError.LoadList(reader); + foreach (MessageError error in errorList) + message.ErrorList.Add(error); + } + + internal void LoadViolationList(Message message) + { + MessageViolation aMessageViolation = new MessageViolation(); + SqlCommand cmd = new SqlCommand(); + aMessageViolation.PrepareLoadCommand(cmd, Message.LoadFilter.MESSAGEHEADER, message.Id); + SqlDataReader reader = this.PerformCommand(cmd); + List violationList = aMessageViolation.LoadList(reader); + foreach (MessageViolation violation in violationList) + message.ViolationList.Add(violation); + } + + + internal SqlDataReader PerformCommand(SqlCommand cmd) + { + try + { + cmd.Connection = this._con; + SqlDataReader reader = cmd.ExecuteReader(); + return reader; + } + catch (SqlException ex) + { + System.Diagnostics.Trace.WriteLine("SQL Exception:" + ex.Message); + _log.Error("Error performing command", ex); + return null; + } + } + + #endregion + + } +} diff --git a/nsw/Source/bsmd.database/DatabaseEntity.cs b/nsw/Source/bsmd.database/DatabaseEntity.cs new file mode 100644 index 00000000..ba23c187 --- /dev/null +++ b/nsw/Source/bsmd.database/DatabaseEntity.cs @@ -0,0 +1,52 @@ +// +// Class: IDatabaseEntity +// Current CLR: 4.0.30319.34209 +// System: Microsoft Visual Studio 10.0 +// Author: dani +// Created: 3/2/2015 9:08:47 PM +// +// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. + +using System; +using System.Data; +using System.Data.SqlClient; +using System.Collections.Generic; + +namespace bsmd.database +{ + + public abstract class DatabaseEntity + { + protected Guid? id; + + protected string tablename; + + /// + /// SQL Table name to construct queries + /// + public string Tablename { get { return this.tablename; } } + + /// + /// primary key + /// + public Guid? Id { get { return this.id; } } + + /// + /// IsNew Flag + /// + public bool IsNew { get { return !this.id.HasValue; } } + + public virtual void PrepareSave(IDbCommand cmd) { } + + public virtual void PrepareDelete(IDbCommand cmd) + { + SqlCommand scmd = cmd as SqlCommand; + scmd.CommandText = string.Format("DELETE FROM {0} WHERE Id = @ID", Tablename); + scmd.Parameters.AddWithValue("@ID", this.Id); + } + + public abstract void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria); + + public abstract List LoadList(IDataReader reader); + } +} diff --git a/nsw/Source/bsmd.database/Message.cs b/nsw/Source/bsmd.database/Message.cs index b11c1e8a..9de76727 100644 --- a/nsw/Source/bsmd.database/Message.cs +++ b/nsw/Source/bsmd.database/Message.cs @@ -11,15 +11,16 @@ namespace bsmd.database /// /// Basisklasse aller Nachrichtentypen, zentrale Klasse für die NSW App /// - public class Message : IDatabaseEntity - { - private Guid? id; + public class Message : DatabaseEntity + { private Guid messageHeaderId; private Guid? messageCoreId; private MessageCore messageCore; private Guid? reportingPartyId; private ReportingParty reportingParty; private DateTime? created; + private List errorList = new List(); + private List violationList = new List(); #region Enumerations @@ -76,12 +77,12 @@ namespace bsmd.database #endregion - #region Properties + public Message() + { + this.tablename = "[dbo].[MessageHeader]"; + } - /// - /// Primärschlüssel - /// - public Guid? Id { get { return this.id; } } + #region Properties /// /// Dieser Wert wird vom NSW / HIS vergeben @@ -129,21 +130,26 @@ namespace bsmd.database /// public NSWProvider HIS { get; set; } - #endregion + /// + /// Fehlerliste (Rückgabe vom NSW) + /// + public List ErrorList { get { return this.errorList; } } - #region public virtual methods + /// + /// Violation-Liste (Rückgabe vom NSW) + /// + public List ViolationList { get { return this.violationList; } } + /// + /// Vorwärtsreferenz auf spezielle Message (damit wir über Message loopen können) + /// + public DatabaseEntity DerivedMessage { get; set; } - #endregion + #endregion - #region IDatabaseEntity implementation + #region IDatabaseEntity implementation - public bool IsNew - { - get { return !this.id.HasValue; } - } - - public void PrepareSave(IDbCommand cmdParam) + public override void PrepareSave(IDbCommand cmdParam) { SqlCommand cmd = cmdParam as SqlCommand; @@ -181,30 +187,25 @@ namespace bsmd.database if (this.IsNew) { - string query = "INSERT INTO [MessageHeader] (ClientRequestId, MessageCoreId, MessageId, SentAt, ReceivedAt, RequestedAt, NotificationClass, Reset, Cancel, Status, ReportingPartyId, BSMDStatus, HIS) " + - "VALUES (@CLIENTREQUESTID, @MESSAGECOREID, @MESSAGEID, @SENTAT, @RECEIVEDAT, @REQUESTEDAT, @NOTIFICATIONCLASS, @RESET, @CANCEL, @STATUS, @REPORTINGPARTYID, @BSMDSTATUS, @HIS)"; + string query = string.Format("INSERT INTO {0} (ClientRequestId, MessageCoreId, MessageId, SentAt, ReceivedAt, RequestedAt, NotificationClass, Reset, Cancel, Status, ReportingPartyId, BSMDStatus, HIS) " + + "VALUES (@CLIENTREQUESTID, @MESSAGECOREID, @MESSAGEID, @SENTAT, @RECEIVEDAT, @REQUESTEDAT, @NOTIFICATIONCLASS, @RESET, @CANCEL, @STATUS, @REPORTINGPARTYID, @BSMDSTATUS, @HIS)", + this.Tablename); cmd.CommandText = query; } else { - cmd.CommandText = "UPDATE [MessageHeader] SET ClientRequestId = @CLIENTREQUESTID, MessageId = @MESSAGEID, SentAt = @SENTAT, ReceivedAt = @RECEIVEDAT, RequestedAt = @REQUESTEDAT, " + + cmd.CommandText = string.Format("UPDATE {0} SET ClientRequestId = @CLIENTREQUESTID, MessageId = @MESSAGEID, SentAt = @SENTAT, ReceivedAt = @RECEIVEDAT, RequestedAt = @REQUESTEDAT, " + "NotificationClass = @NOTIFICATIONCLASS, Reset = @RESET, Cancel = @CANCEL, Status = @STATUS, ReportingPartyId = @REPORTINGPARTYID, BSMDStatus = @BSMDSTATUS, HIS = @HIS " + - "WHERE Id = @ID"; + "WHERE Id = @ID", this.Tablename); cmd.Parameters.AddWithValue("@ID", this.messageHeaderId); } } + - public void PrepareDelete(IDbCommand cmdParam) + public override void PrepareLoadCommand(IDbCommand cmd, LoadFilter filter, params object[] criteria ) { - SqlCommand cmd = cmdParam as SqlCommand; - cmd.CommandText = "DELETE FROM [MessageHeader] WHERE Id = @ID"; - cmd.Parameters.AddWithValue("@ID", this.messageHeaderId); - } - - public void PrepareLoadCommand(IDbCommand cmd, LoadFilter filter, params object[] criteria ) - { - string query = "SELECT Id, ClientRequestId, MessageCoreId, MessageId, SentAt, ReceivedAt, RequestedAt, NotificationClass, " + - "Reset, Cancel, Status, ReportingPartyId, BSMDStatus, HIS, Created FROM MessageHeader "; + string query = string.Format("SELECT Id, ClientRequestId, MessageCoreId, MessageId, SentAt, ReceivedAt, RequestedAt, NotificationClass, " + + "Reset, Cancel, Status, ReportingPartyId, BSMDStatus, HIS, Created FROM {0} ", this.Tablename); switch (filter) { @@ -214,6 +215,12 @@ namespace bsmd.database ((SqlCommand)cmd).Parameters.AddWithValue("RPID", criteria[0]); break; } + case LoadFilter.BSMDSTATUS: + { + query += "WHERE BSMDStatus = @BSMDSTATUS"; + ((SqlCommand)cmd).Parameters.AddWithValue("@BSMDSTATUS", criteria[0]); + break; + } case LoadFilter.ALL: default: break; @@ -222,9 +229,9 @@ namespace bsmd.database cmd.CommandText = query; } - public List LoadList(IDataReader reader) + public override List LoadList(IDataReader reader) { - List result = new List(); + List result = new List(); while (reader.Read()) { Message msg = new Message(); @@ -245,10 +252,33 @@ namespace bsmd.database if (!reader.IsDBNull(14)) msg.created = reader.GetDateTime(14); result.Add(msg); } + reader.Close(); return result; } #endregion + #region public static helpers + + public static void AssignReportingParties(List messages, Dictionary reportingParties) + { + foreach (Message message in messages) + { + if (message.reportingPartyId.HasValue && reportingParties.ContainsKey(message.reportingPartyId.Value)) + message.reportingParty = reportingParties[message.reportingPartyId.Value]; + } + } + + public static void AssignMessageCores(List messages, Dictionary messageCores) + { + foreach (Message message in messages) + { + if (message.messageCoreId.HasValue && messageCores.ContainsKey(message.messageCoreId.Value)) + message.messageCore = messageCores[message.messageCoreId.Value]; + } + } + + #endregion + } } diff --git a/nsw/Source/bsmd.database/MessageCore.cs b/nsw/Source/bsmd.database/MessageCore.cs index 87c6d0be..1d250d31 100644 --- a/nsw/Source/bsmd.database/MessageCore.cs +++ b/nsw/Source/bsmd.database/MessageCore.cs @@ -8,18 +8,20 @@ using System.Threading.Tasks; namespace bsmd.database { - public class MessageCore : IDatabaseEntity - { - private Guid id; + public class MessageCore : DatabaseEntity + { private Guid? previous; private Guid? next; private Guid? customerId; private int? wetris_zz_56_datensatz_id; - #region Properties + public MessageCore() + { + this.tablename = "[dbo].[MessageCore]"; + } - public Guid? Id { get { return this.id; } } + #region Properties public string VisitId { get; set; } @@ -33,7 +35,7 @@ namespace bsmd.database public string Portname { get; set; } - public DateTime ETA { get; set; } + public DateTime? ETA { get; set; } public bool IsTransit { get; set; } @@ -41,38 +43,60 @@ namespace bsmd.database public Message.NSWProvider InitialHIS { get; set; } - #endregion + #endregion - - public bool IsNew + public override void PrepareSave(IDbCommand cmd) { - get { return !this.Id.HasValue; } - } + SqlCommand scmd = cmd as SqlCommand; + + if (this.VisitId != null) scmd.Parameters.AddWithValue("@P1", this.VisitId); + else scmd.Parameters.AddWithValue("@P1", DBNull.Value); + if (this.TransitId != null) scmd.Parameters.AddWithValue("@P2", this.TransitId); + else scmd.Parameters.AddWithValue("@P2", DBNull.Value); + if (this.IMO != null) scmd.Parameters.AddWithValue("@P3", this.IMO); + else scmd.Parameters.AddWithValue("@P3", DBNull.Value); + if (this.ENI != null) scmd.Parameters.AddWithValue("@P4", this.ENI); + else scmd.Parameters.AddWithValue("@P4", DBNull.Value); + if (this.PoC != null) scmd.Parameters.AddWithValue("@P5", this.PoC); + else scmd.Parameters.AddWithValue("@P5", DBNull.Value); + if (this.Portname != null) scmd.Parameters.AddWithValue("@P6", this.Portname); + else scmd.Parameters.AddWithValue("@P6", DBNull.Value); + if (this.ETA.HasValue) scmd.Parameters.AddWithValue("@P7", this.ETA); + else scmd.Parameters.AddWithValue("@P7", DBNull.Value); + if (this.customerId.HasValue) scmd.Parameters.AddWithValue("@P8", this.customerId); + else scmd.Parameters.AddWithValue("@P8", DBNull.Value); + if (this.previous.HasValue) scmd.Parameters.AddWithValue("@P9", this.previous); + else scmd.Parameters.AddWithValue("@P9", DBNull.Value); + if (this.next.HasValue) scmd.Parameters.AddWithValue("@P10", this.next); + else scmd.Parameters.AddWithValue("@P10", DBNull.Value); + scmd.Parameters.AddWithValue("@P11", this.IsTransit ? 1 : 0); + if (this.wetris_zz_56_datensatz_id.HasValue) scmd.Parameters.AddWithValue("@P12", this.wetris_zz_56_datensatz_id); + else scmd.Parameters.AddWithValue("@P12", DBNull.Value); + scmd.Parameters.AddWithValue("@P13", this.BSMDStatus); + scmd.Parameters.AddWithValue("@P14", this.InitialHIS); - public void PrepareSave(IDbCommand cmd) - { if (this.IsNew) { - string query = "INSERT INTO [MessageCore] (VisitId, TransitId, IMO, ENI, PoC, Portname, ETA, CustomerId, " + + string query = string.Format("INSERT INTO {0} (VisitId, TransitId, IMO, ENI, PoC, Portname, ETA, CustomerId, " + "Previous, Next, IsTransit, Wetris_zz_56_datensatz_id, BSMDStatus, InitialHIS) VALUES " + - "(@P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14)"; - + "(@P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14)", this.Tablename); + scmd.CommandText = query; } else { + scmd.Parameters.AddWithValue("@ID", this.Id); + string query = string.Format("UPDATE {0} SET VisitId = @P1, TransitId = @P2, IMO = @P3, ENI = @P4, Poc = @P5, " + + "Portname = @P6, ETA = @P7, CustomerId = @P8, Previous = @P9, Next = @P10, IsTransit = @P11, " + + "Wetris_zz_56_datensatz_id = @P12, BSMDStatus = @P13, InitialHIS = @P14 WHERE Id = @ID", this.Tablename); } - } + } - public void PrepareDelete(IDbCommand cmd) + public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) { - throw new NotImplementedException(); - } - - public void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) - { - string query = "SELECT Id, VisitId, TransitId, IMO, ENI, PoC, Portname, " + - "ETA, CustomerId, Previous, Next, IsTransit, Wetris_zz_56_datensatz_id, BSMDStatus, InitialHIS FROM [MessageCore] "; + string query = string.Format("SELECT Id, VisitId, TransitId, IMO, ENI, PoC, Portname, " + + "ETA, CustomerId, Previous, Next, IsTransit, Wetris_zz_56_datensatz_id, BSMDStatus, InitialHIS FROM {0} ", + this.Tablename); switch (filter) { @@ -90,9 +114,9 @@ namespace bsmd.database cmd.CommandText = query; } - public List LoadList(IDataReader reader) + public override List LoadList(IDataReader reader) { - List result = new List(); + List result = new List(); while(reader.Read()) { MessageCore core = new MessageCore(); diff --git a/nsw/Source/bsmd.database/MessageError.cs b/nsw/Source/bsmd.database/MessageError.cs new file mode 100644 index 00000000..10611d76 --- /dev/null +++ b/nsw/Source/bsmd.database/MessageError.cs @@ -0,0 +1,92 @@ +// +// Class: MessageError +// Current CLR: 4.0.30319.34209 +// System: Microsoft Visual Studio 10.0 +// Author: dani +// Created: 3/19/2015 7:54:06 AM +// +// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. + +using System; +using System.Data; +using System.Data.SqlClient; +using System.Collections.Generic; + +namespace bsmd.database +{ + public class MessageError : DatabaseEntity + { + + public MessageError() + { + this.tablename = "[dbo].[Error]"; + } + + #region Properties + + public int ErrorCode { get; set; } + + public string ErrorText { get; set; } + + public Guid MessageHeaderId { get; set; } + + #endregion + + #region IDatabaseEntity implementation + + public override void PrepareSave(System.Data.IDbCommand cmd) + { + SqlCommand scmd = cmd as SqlCommand; + + scmd.Parameters.AddWithValue("@MHID", this.MessageHeaderId); + scmd.Parameters.AddWithValue("@VC", this.ErrorCode); + scmd.Parameters.AddWithValue("@VT", this.ErrorText); + + if (this.IsNew) + { + scmd.CommandText = string.Format("INSERT INTO {0} (MessageHeaderId, ErrorCode, ErrorText) VALUES (@MHID, @VC, @VT)", this.Tablename); + } + else + { + scmd.Parameters.AddWithValue("@ID", this.Id); + scmd.CommandText = string.Format("UPDATE {0} SET MessageHeaderId = @MHID, ErrorCode = @VC, ErrorText = @VT WHERE Id = @ID", this.Tablename); + } + } + + public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) + { + string query = string.Format("SELECT Id, ErrorCode, ErrorText FROM {0} ", this.Tablename); + + switch (filter) + { + case Message.LoadFilter.MESSAGEHEADER: + query += "WHERE MessageHeaderId = @MHID"; + ((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]); + break; + case Message.LoadFilter.ALL: + default: + break; + } + + cmd.CommandText = query; + } + + public override List LoadList(System.Data.IDataReader reader) + { + List result = new List(); + while (reader.Read()) + { + MessageError me = new MessageError(); + me.id = reader.GetGuid(0); + if (!reader.IsDBNull(1)) me.ErrorCode = reader.GetInt32(1); + if (!reader.IsDBNull(2)) me.ErrorText = reader.GetString(2); + result.Add(me); + } + reader.Close(); + return result; + } + + #endregion + + } +} diff --git a/nsw/Source/bsmd.database/MessageViolation.cs b/nsw/Source/bsmd.database/MessageViolation.cs new file mode 100644 index 00000000..3d65e710 --- /dev/null +++ b/nsw/Source/bsmd.database/MessageViolation.cs @@ -0,0 +1,93 @@ +// +// Class: MessageViolation +// Current CLR: 4.0.30319.34209 +// System: Microsoft Visual Studio 10.0 +// Author: dani +// Created: 3/19/2015 7:54:25 AM +// +// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. + +using System; +using System.Data; +using System.Data.SqlClient; +using System.Collections.Generic; + +namespace bsmd.database +{ + public class MessageViolation : DatabaseEntity + { + + public MessageViolation() + { + this.tablename = "[dbo].[Violation]"; + } + + #region Properties + + public int ViolationCode { get; set; } + + public string ViolationText { get; set; } + + public Guid MessageHeaderId { get; set; } + + #endregion + + #region DatabaseEntity implementation + + public override void PrepareSave(System.Data.IDbCommand cmd) + { + SqlCommand scmd = cmd as SqlCommand; + + scmd.Parameters.AddWithValue("@MHID", this.MessageHeaderId); + scmd.Parameters.AddWithValue("@VC", this.ViolationCode); + scmd.Parameters.AddWithValue("@VT", this.ViolationText); + + if (this.IsNew) + { + scmd.CommandText = string.Format("INSERT INTO {0} (MessageHeaderId, ViolationCode, ViolationText) VALUES (@MHID, @VC, @VT)", this.Tablename); + } + else + { + scmd.Parameters.AddWithValue("@ID", this.Id); + scmd.CommandText = string.Format("UPDATE {0} SET MessageHeaderId = @MHID, ViolationCode = @VC, ViolationText = @VT WHERE Id = @ID", this.Tablename); + } + } + + public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) + { + + string query = string.Format("SELECT Id, ViolationCode, ViolationText FROM {0} ", this.Tablename); + + switch (filter) + { + case Message.LoadFilter.MESSAGEHEADER: + query += "WHERE MessageHeaderId = @MHID"; + ((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]); + break; + case Message.LoadFilter.ALL: + default: + break; + } + + cmd.CommandText = query; + } + + public override List LoadList(System.Data.IDataReader reader) + { + List result = new List(); + while (reader.Read()) + { + MessageViolation mv = new MessageViolation(); + mv.id = reader.GetGuid(0); + if (!reader.IsDBNull(1)) mv.ViolationCode = reader.GetInt32(1); + if (!reader.IsDBNull(2)) mv.ViolationText = reader.GetString(2); + result.Add(mv); + } + reader.Close(); + return result; + } + + #endregion + + } +} diff --git a/nsw/Source/bsmd.database/ReportingParty.cs b/nsw/Source/bsmd.database/ReportingParty.cs index 0454f850..f6214f94 100644 --- a/nsw/Source/bsmd.database/ReportingParty.cs +++ b/nsw/Source/bsmd.database/ReportingParty.cs @@ -1,4 +1,6 @@ using System; +using System.Data; +using System.Data.SqlClient; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,9 +8,8 @@ using System.Threading.Tasks; namespace bsmd.database { - public class ReportingParty - { - private Guid id; + public class ReportingParty : DatabaseEntity + { #region enumerations @@ -17,9 +18,12 @@ namespace bsmd.database #endregion - #region Properties + public ReportingParty() + { + this.tablename = "[dbo].[ReportingParty]"; + } - public Guid Id { get { return this.id; } } + #region Properties public string Name { get; set; } @@ -54,5 +58,58 @@ namespace bsmd.database #endregion + #region IDatabaseEntity implementation + + public override void PrepareSave(System.Data.IDbCommand cmd) + { + throw new NotImplementedException(); + } + + public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) + { + + string query = string.Format("SELECT Id, RPName, RPStreetAndNumber, RPPostalCode, RPCity, RPCountry, RPLastName, " + + "RPFirstName, RPPhone, RPFax, RPEMail FROM {0} ", this.Tablename); + + switch (filter) + { + /// tbd + + case Message.LoadFilter.ALL: + default: + break; + } + + cmd.CommandText = query; + + } + + public override List LoadList(System.Data.IDataReader reader) + { + List result = new List(); + while (reader.Read()) + { + ReportingParty rp = new ReportingParty(); + + rp.id = reader.GetGuid(0); + if (!reader.IsDBNull(1)) rp.Name = reader.GetString(1); + if (!reader.IsDBNull(2)) rp.StreetAndNumber = reader.GetString(2); + if (!reader.IsDBNull(3)) rp.PostalCode = reader.GetString(3); + if (!reader.IsDBNull(4)) rp.City = reader.GetString(4); + if (!reader.IsDBNull(5)) rp.Country = reader.GetString(5); + if (!reader.IsDBNull(6)) rp.LastName = reader.GetString(6); + if (!reader.IsDBNull(7)) rp.FirstName = reader.GetString(7); + if (!reader.IsDBNull(8)) rp.Phone = reader.GetString(8); + if (!reader.IsDBNull(9)) rp.Fax = reader.GetString(9); + if (!reader.IsDBNull(10)) rp.EMail = reader.GetString(10); + + result.Add(rp); + } + reader.Close(); + return result; + } + + #endregion + } } diff --git a/nsw/Source/bsmd.database/STAT.cs b/nsw/Source/bsmd.database/STAT.cs new file mode 100644 index 00000000..5447ed5b --- /dev/null +++ b/nsw/Source/bsmd.database/STAT.cs @@ -0,0 +1,116 @@ +// +// Class: STAT +// Current CLR: 4.0.30319.34209 +// System: Microsoft Visual Studio 10.0 +// Author: dani +// Created: 3/19/2015 8:59:21 PM +// +// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. + +using System; +using System.Data; +using System.Data.SqlClient; +using System.Collections.Generic; + +namespace bsmd.database +{ + public class STAT : DatabaseEntity + { + + public STAT() + { + this.tablename = "[dbo].[STAT]"; + } + + #region Properties + + public Message MessageHeader { get; set; } + + public string ShipName { get; set; } + + public string CallSign { get; set; } + + public string MMSINumber { get; set; } + + public string Flag { get; set; } + + public float? LengthOverall_MTR { get; set; } + + public float? Beam_MTR { get; set; } + + public int? GrossTonnage { get; set; } + + public string PortOfRegistry { get; set; } + + public string InmarsatCallNumber { get; set; } + + public string ShipType { get; set; } + + public string ISMCompanyName { get; set; } + + public string ISMCompanyId { get; set; } + + public string ISMCompanyStreetAndNumber { get; set; } + + public string ISMCompanyPostalCode { get; set; } + + public string ISMCompanyCity { get; set; } + + public string ISMCompanyCountry { get; set; } + + #endregion + + public void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) + { + string query = string.Format("SELECT Id, ShipName, Callsign, MMSINumber, Flag, LengthOverall_MTR, Beam_MTR, " + + "GrossTonnage, PortOfRegistry, InmarsatCallNumber, ShipType, ISMCompanyName, ISMCompanyId, ISMCompanyStreetAndNumber, " + + "ISMCompanyPostalAddress, ISMCompanyCity, ISMCompanyCountry FROM {0}", this.Tablename); + + switch (filter) + { + case Message.LoadFilter.MESSAGEHEADER: + query += "WHERE MessageHeaderId = @MHID"; + ((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]); + break; + case Message.LoadFilter.ALL: + default: + + break; + } + cmd.CommandText = query; + } + + public override List LoadList(System.Data.IDataReader reader) + { + List result = new List(); + + while(reader.Read()) + { + STAT stat = new STAT(); + + stat.id = reader.GetGuid(0); + + if (!reader.IsDBNull(1)) stat.ShipName = reader.GetString(1); + if (!reader.IsDBNull(2)) stat.CallSign = reader.GetString(2); + if (!reader.IsDBNull(3)) stat.MMSINumber = reader.GetString(3); + if (!reader.IsDBNull(4)) stat.Flag = reader.GetString(4); + if (!reader.IsDBNull(5)) stat.LengthOverall_MTR = reader.GetFloat(5); + if (!reader.IsDBNull(6)) stat.Beam_MTR = reader.GetFloat(6); + if (!reader.IsDBNull(7)) stat.GrossTonnage = reader.GetInt32(7); + if (!reader.IsDBNull(8)) stat.PortOfRegistry = reader.GetString(8); + if (!reader.IsDBNull(9)) stat.InmarsatCallNumber = reader.GetString(9); + if (!reader.IsDBNull(10)) stat.ShipType = reader.GetString(10); + if (!reader.IsDBNull(11)) stat.ISMCompanyName = reader.GetString(11); + if (!reader.IsDBNull(12)) stat.ISMCompanyId = reader.GetString(12); + if (!reader.IsDBNull(13)) stat.ISMCompanyStreetAndNumber = reader.GetString(13); + if (!reader.IsDBNull(14)) stat.ISMCompanyPostalCode = reader.GetString(14); + if (!reader.IsDBNull(15)) stat.ISMCompanyCity = reader.GetString(15); + if (!reader.IsDBNull(16)) stat.ISMCompanyCountry = reader.GetString(16); + + result.Add(stat); + } + reader.Close(); + return result; + } + } +} diff --git a/nsw/Source/bsmd.database/bsmd.database.csproj b/nsw/Source/bsmd.database/bsmd.database.csproj index cc797d5d..20a2404b 100644 --- a/nsw/Source/bsmd.database/bsmd.database.csproj +++ b/nsw/Source/bsmd.database/bsmd.database.csproj @@ -46,11 +46,14 @@ - + + + + diff --git a/nsw/Source/bsmd.database/packages.config b/nsw/Source/bsmd.database/packages.config new file mode 100644 index 00000000..981a91a1 --- /dev/null +++ b/nsw/Source/bsmd.database/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/nsw/Source/bsmd.dbh/Request.cs b/nsw/Source/bsmd.dbh/Request.cs index e28f8dd6..4b2a333f 100644 --- a/nsw/Source/bsmd.dbh/Request.cs +++ b/nsw/Source/bsmd.dbh/Request.cs @@ -60,7 +60,7 @@ namespace bsmd.dbh } ((RootVisit)root.Item).PortOfCall = aMessage.MessageCore.PoC; - ((RootVisit)root.Item).ETAPortOfCall = aMessage.MessageCore.ETA; + ((RootVisit)root.Item).ETAPortOfCall = aMessage.MessageCore.ETA.Value; break; @@ -79,7 +79,12 @@ namespace bsmd.dbh ((RootTransit)root.Item).Item = aMessage.MessageCore.ENI; } - ((RootTransit)root.Item).ETAKielCanal = aMessage.MessageCore.ETA; + ((RootTransit)root.Item).ETAKielCanal = aMessage.MessageCore.ETA.Value; + + break; + + case Message.NotificationClass.STAT: + break; diff --git a/nsw/Source/bsmd.dbh/packages.config b/nsw/Source/bsmd.dbh/packages.config new file mode 100644 index 00000000..981a91a1 --- /dev/null +++ b/nsw/Source/bsmd.dbh/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/nsw/Source/packages/log4net.2.0.3/log4net.2.0.3.nupkg b/nsw/Source/packages/log4net.2.0.3/log4net.2.0.3.nupkg new file mode 100644 index 00000000..14dc7db7 Binary files /dev/null and b/nsw/Source/packages/log4net.2.0.3/log4net.2.0.3.nupkg differ diff --git a/nsw/Source/packages/log4net.2.0.3/log4net.2.0.3.nuspec b/nsw/Source/packages/log4net.2.0.3/log4net.2.0.3.nuspec new file mode 100644 index 00000000..7ea51b55 --- /dev/null +++ b/nsw/Source/packages/log4net.2.0.3/log4net.2.0.3.nuspec @@ -0,0 +1,20 @@ + + + + log4net + 2.0.3 + log4net [1.2.13] + Apache Software Foundation + Apache Software Foundation + http://logging.apache.org/log4net/license.html + http://logging.apache.org/log4net/ + false + log4net is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary. The log4net package is designed so that log statements can remain in shipped code without incurring a high performance cost. It follows that the speed of logging (or rather not logging) is crucial. + +At the same time, log output can be so voluminous that it quickly becomes overwhelming. One of the distinctive features of log4net is the notion of hierarchical loggers. Using these loggers it is possible to selectively control which log statements are output at arbitrary granularity. + +log4net is designed with two distinct goals in mind: speed and flexibility + The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets. + logging log tracing logfiles + + \ No newline at end of file diff --git a/nsw/Source/packages/repositories.config b/nsw/Source/packages/repositories.config new file mode 100644 index 00000000..f16003ee --- /dev/null +++ b/nsw/Source/packages/repositories.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file