Serialisierung von Visit, Transit und STAT für DBH

This commit is contained in:
Daniel Schick 2022-10-31 12:16:25 +01:00
parent d0be323df2
commit fe2db2fa6b
9 changed files with 8302 additions and 13 deletions

View File

@ -183,7 +183,7 @@ namespace SendNSWMessageService
{
case Message.NSWProvider.DBH:
sendSucceeded = bsmd.dbh.Request.SendMessage(message);
sendSucceeded = bsmd.dbh.MessageController.SendMessage(core, message);
if (!sendSucceeded)
message.InternalStatus = Message.BSMDStatus.SEND_FAILED;
else
@ -245,7 +245,7 @@ namespace SendNSWMessageService
didSendSomething = true;
break;
case Message.NSWProvider.DBH:
coreSendSucceeded = bsmd.dbh.Request.SendCancelCore(core);
coreSendSucceeded = bsmd.dbh.MessageController.SendCancelCore(core);
break;
default:
_log.WarnFormat("Cancelling for HIS {0} is not supported", core.InitialHIS);
@ -267,9 +267,10 @@ namespace SendNSWMessageService
}
// external processing for HIS-Nord
bsmd.hisnord.transmitter.CallTransmitter();
// ob test oder nicht ist in stat. dict gespeichert
bsmd.hisnord.Request.ReadResponseFiles();
bsmd.hisnord.Response.ReadAnswers();

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using bsmd.database;
namespace bsmd.dbh
{
public static class MessageController
{
private static readonly ILog _log = LogManager.GetLogger(typeof(MessageController));
public static bool SendMessage(MessageCore core, Message message)
{
bool result = true;
try
{
if (message == null) return false;
if (message.ReportingParty == null)
{
_log.ErrorFormat("Reporting party not set on message {0}", message.Id);
return false;
}
if ((message.MessageNotificationClass != Message.NotificationClass.VISIT) &&
(message.MessageNotificationClass != Message.NotificationClass.TRANSIT) &&
(message.Elements.Count == 0))
{
_log.ErrorFormat("trying to send message {0} class {1} but there are no depending record elements",
message.Id, message.MessageNotificationClass);
return false;
}
string messageFile = RequestUtil.CreateMessageFile(core, message);
if (messageFile != null)
{
// move file to output directory
}
else
{
result = false;
}
}
catch (Exception ex)
{
_log.Error(ex.ToString());
result = false;
}
return result;
}
public static bool SendCancelCore(MessageCore core)
{
bool result = true;
return result;
}
public static void SendAndReceive()
{
// sent unsent messages in output folder
// remove files from output folder to archive folder
// receive files from remote host
// process result files
}
}
}

View File

@ -22,9 +22,9 @@ namespace bsmd.dbh
/// It has been superseded by a file-based approach that transmits classes via SFTP.
/// </summary>
[Obsolete]
public class Request
public class RequestWeb
{
private static readonly ILog _log = LogManager.GetLogger(typeof(Request));
private static readonly ILog _log = LogManager.GetLogger(typeof(RequestWeb));
public static bool SendCancelCore(MessageCore core)
{

File diff suppressed because it is too large Load Diff

155
bsmd.dbh/RequestUtil.cs Normal file
View File

@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using bsmd.database;
using log4net;
using bsmd.dbh.Request;
namespace bsmd.dbh
{
internal static class RequestUtil
{
private static readonly ILog _log = LogManager.GetLogger(typeof(RequestUtil));
public static string CreateMessageFile(MessageCore core, Message message)
{
// create output structure
try
{
Root root = new Root();
root.Version = RootVersion.Item70;
root.SourceDocumentVersion = "7.0";
root.Timestamp = DateTime.Now;
root.Sender = Properties.Settings.Default.Sender;
root.SenderReference = "N";
bsmd.database.ReportingParty reportingParty = DBManager.Instance.GetReportingPartyDict()[core.DefaultReportingPartyId.Value];
Request.ReportingParty rp = new Request.ReportingParty();
rp.RPCity = reportingParty.City;
rp.RPCountry = reportingParty.Country;
rp.RPEMail = reportingParty.EMail;
rp.RPFax = reportingParty.Fax;
rp.RPFirstName = reportingParty.FirstName;
rp.RPLastName = reportingParty.LastName;
rp.RPName = reportingParty.Name;
rp.RPPhone = reportingParty.Phone;
rp.RPPostalCode = reportingParty.PostalCode;
rp.RPStreetAndNumber = reportingParty.StreetAndNumber;
rp.RPTypeSpecified = reportingParty.ReportingPartyType.HasValue;
if (rp.RPTypeSpecified)
rp.RPType = (ReportingPartyRPType)reportingParty.ReportingPartyType.Value;
root.ReportingParty = rp;
switch (message.MessageNotificationClass)
{
case Message.NotificationClass.VISIT:
root.Type = RootType.VISIT;
RootVisit rootVisit = new RootVisit();
rootVisit.PortOfCall = core.PoC;
if (core.ETA.HasValue)
rootVisit.ETAPortOfCall = core.ETA.Value;
rootVisit.ETAPortOfCall = core.ETA.Value;
if(!core.IMO.IsNullOrEmpty())
{
rootVisit.ItemElementName = ItemChoiceType.IMONumber;
rootVisit.Item = core.IMO;
}
else
{
rootVisit.ItemElementName = ItemChoiceType.ENINumber;
rootVisit.Item = core.ENI;
}
root.Item = rootVisit;
root.ItemElementName = ItemChoiceType2.Visit;
break;
case Message.NotificationClass.TRANSIT:
root.Type = RootType.TRANSIT;
RootTransit rootTransit = new RootTransit();
if (!core.IMO.IsNullOrEmpty())
{
rootTransit.ItemElementName = ItemChoiceType1.IMONumber;
rootTransit.Item = core.IMO;
}
else
{
rootTransit.ItemElementName = ItemChoiceType1.ENINumber;
rootTransit.Item = core.ENI;
}
if (core.ETAKielCanal.HasValue)
rootTransit.ETAKielCanal = core.ETAKielCanal.Value;
root.Item = rootTransit;
root.ItemElementName = ItemChoiceType2.Transit;
break;
case Message.NotificationClass.STAT:
root.Type = RootType.DATA;
RootSTAT rootStat = new RootSTAT();
STAT stat = message.Elements[0] as STAT;
rootStat.ShipName = stat.ShipName;
rootStat.CallSign = stat.CallSign;
rootStat.MMSINumber = stat.MMSINumber;
rootStat.Flag = stat.Flag;
if (stat.LengthOverall_MTR.HasValue) rootStat.LengthOverall_MTR = Decimal.Round((decimal)(stat.LengthOverall_MTR.Value), 2);
if (stat.Beam_MTR.HasValue) rootStat.Beam_MTR = Decimal.Round((decimal)(stat.Beam_MTR.Value), 2);
if (stat.GrossTonnage.HasValue) rootStat.GrossTonnage = stat.GrossTonnage.Value;
rootStat.PortOfRegistry = stat.PortOfRegistry;
rootStat.ShipType = stat.ShipType;
if (!stat.InmarsatCallNumber.IsNullOrEmpty())
{
rootStat.InmarsatCallNumbers = stat.InmarsatCallNumber.Trim().Split('\n');
for (int i = 0; i < Math.Min(rootStat.InmarsatCallNumbers.Length, 5); i++)
rootStat.InmarsatCallNumbers[i] = rootStat.InmarsatCallNumbers[i].Trim();
}
rootStat.TransportMode = RootSTATTransportMode.Item1; // default is maritime transport!
if (!stat.TransportMode.IsNullOrEmpty() && stat.TransportMode.Equals("8"))
rootStat.TransportMode = RootSTATTransportMode.Item8;
if (!stat.ISMCompanyName.IsNullOrEmpty())
{
rootStat.ISMCompany = new RootSTATISMCompany();
rootStat.ISMCompany.ISMCompanyName = stat.ISMCompanyName;
rootStat.ISMCompany.ISMCompanyId = stat.ISMCompanyId;
rootStat.ISMCompany.ISMCompanyStreetAndNumber = stat.ISMCompanyStreetAndNumber;
rootStat.ISMCompany.ISMCompanyPostalCode = stat.ISMCompanyPostalCode;
rootStat.ISMCompany.ISMCompanyCity = stat.ISMCompanyCity;
rootStat.ISMCompany.ISMCompanyCountry = stat.ISMCompanyCountry;
}
root.Items = new object[1];
root.Items[0] = rootStat;
break;
default:
_log.WarnFormat("Message type {0} not (yet) supported for dbh", message.MessageNotificationClassDisplay);
break;
}
// serialize output structure to file
string filename = string.Format("BSMD_{1}-{2}-{0}.xml", (message == null) ? "CANCEL" : message.MessageNotificationClassDisplay, DateTime.Now.ToString("yyyyMMddHHmmss"), core.Id.Value);
_log.InfoFormat("saving {0} to output directory", filename);
string filePath = Path.Combine(Path.GetTempPath(), filename);
XmlSerializer serializer = new XmlSerializer(typeof(Root));
using (TextWriter tw = new StreamWriter(filePath))
{
serializer.Serialize(tw, root);
}
return filename;
}
catch(Exception ex)
{
_log.Error(ex.ToString());
return null;
}
}
}
}

View File

@ -16,7 +16,7 @@ using System.Xml.Serialization;
namespace bsmd.dbh
{
public class Response
public static class ResponseWeb
{
private static readonly ILog _log = LogManager.GetLogger("dbh Response");

View File

@ -0,0 +1,604 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:2.0.50727.9151
//
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
// der Code erneut generiert wird.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=2.0.50727.312.
//
namespace bsmd.dbh.Response
{
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class Root
{
private RootVersion versionField;
private bool versionFieldSpecified;
private string messageIdField;
private string visitIdField;
private string transitIdField;
private string[] sisNumbersField;
private System.DateTime timestampField;
private string senderReferenceField;
private RootType typeField;
private RootReportingClassesFull reportingClassesFullField;
private RootReportingClassesPartial reportingClassesPartialField;
private RootReportingClassesError reportingClassesErrorField;
private RootReportingClassesResetted reportingClassesResettedField;
private RootReportingClassesNoChanges reportingClassesNoChangesField;
private RootMessage[] messagesField;
/// <remarks/>
public RootVersion Version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool VersionSpecified
{
get
{
return this.versionFieldSpecified;
}
set
{
this.versionFieldSpecified = value;
}
}
/// <remarks/>
public string MessageId
{
get
{
return this.messageIdField;
}
set
{
this.messageIdField = value;
}
}
/// <remarks/>
public string VisitId
{
get
{
return this.visitIdField;
}
set
{
this.visitIdField = value;
}
}
/// <remarks/>
public string TransitId
{
get
{
return this.transitIdField;
}
set
{
this.transitIdField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SisNumber", IsNullable = false)]
public string[] SisNumbers
{
get
{
return this.sisNumbersField;
}
set
{
this.sisNumbersField = value;
}
}
/// <remarks/>
public System.DateTime Timestamp
{
get
{
return this.timestampField;
}
set
{
this.timestampField = value;
}
}
/// <remarks/>
public string SenderReference
{
get
{
return this.senderReferenceField;
}
set
{
this.senderReferenceField = value;
}
}
/// <remarks/>
public RootType Type
{
get
{
return this.typeField;
}
set
{
this.typeField = value;
}
}
/// <remarks/>
public RootReportingClassesFull ReportingClassesFull
{
get
{
return this.reportingClassesFullField;
}
set
{
this.reportingClassesFullField = value;
}
}
/// <remarks/>
public RootReportingClassesPartial ReportingClassesPartial
{
get
{
return this.reportingClassesPartialField;
}
set
{
this.reportingClassesPartialField = value;
}
}
/// <remarks/>
public RootReportingClassesError ReportingClassesError
{
get
{
return this.reportingClassesErrorField;
}
set
{
this.reportingClassesErrorField = value;
}
}
/// <remarks/>
public RootReportingClassesResetted ReportingClassesResetted
{
get
{
return this.reportingClassesResettedField;
}
set
{
this.reportingClassesResettedField = value;
}
}
/// <remarks/>
public RootReportingClassesNoChanges ReportingClassesNoChanges
{
get
{
return this.reportingClassesNoChangesField;
}
set
{
this.reportingClassesNoChangesField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Message", IsNullable = false)]
public RootMessage[] Messages
{
get
{
return this.messagesField;
}
set
{
this.messagesField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum RootVersion
{
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("7.0")]
Item70,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum RootType
{
/// <remarks/>
VISIT,
/// <remarks/>
TRANSIT,
/// <remarks/>
DATA,
/// <remarks/>
RESET,
/// <remarks/>
CANCEL,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class RootReportingClassesFull
{
private ReportingClassCode[] reportingClassField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ReportingClass")]
public ReportingClassCode[] ReportingClass
{
get
{
return this.reportingClassField;
}
set
{
this.reportingClassField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
public enum ReportingClassCode
{
/// <remarks/>
NOA_NOD,
/// <remarks/>
ATA,
/// <remarks/>
ATD,
/// <remarks/>
SEC,
/// <remarks/>
AGNT,
/// <remarks/>
POBA,
/// <remarks/>
POBD,
/// <remarks/>
NAME,
/// <remarks/>
TIEFA,
/// <remarks/>
TIEFD,
/// <remarks/>
BKRA,
/// <remarks/>
BKRD,
/// <remarks/>
STAT,
/// <remarks/>
LADG,
/// <remarks/>
INFO,
/// <remarks/>
SERV,
/// <remarks/>
PRE72H,
/// <remarks/>
MDH,
/// <remarks/>
WAS,
/// <remarks/>
WAS_RCPT,
/// <remarks/>
CREW,
/// <remarks/>
PAS,
/// <remarks/>
BPOL,
/// <remarks/>
TOWA,
/// <remarks/>
TOWD,
/// <remarks/>
HAZA,
/// <remarks/>
HAZD,
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class RootReportingClassesPartial
{
private ReportingClassCode[] reportingClassField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ReportingClass")]
public ReportingClassCode[] ReportingClass
{
get
{
return this.reportingClassField;
}
set
{
this.reportingClassField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class RootReportingClassesError
{
private ReportingClassCode[] reportingClassField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ReportingClass")]
public ReportingClassCode[] ReportingClass
{
get
{
return this.reportingClassField;
}
set
{
this.reportingClassField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class RootReportingClassesResetted
{
private ReportingClassCode[] reportingClassField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ReportingClass")]
public ReportingClassCode[] ReportingClass
{
get
{
return this.reportingClassField;
}
set
{
this.reportingClassField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class RootReportingClassesNoChanges
{
private ReportingClassCode[] reportingClassField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ReportingClass")]
public ReportingClassCode[] ReportingClass
{
get
{
return this.reportingClassField;
}
set
{
this.reportingClassField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class RootMessage
{
private string idField;
private RootMessageType typeField;
private string locationField;
private string textField;
/// <remarks/>
public string ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
/// <remarks/>
public RootMessageType Type
{
get
{
return this.typeField;
}
set
{
this.typeField = value;
}
}
/// <remarks/>
public string Location
{
get
{
return this.locationField;
}
set
{
this.locationField = value;
}
}
/// <remarks/>
public string Text
{
get
{
return this.textField;
}
set
{
this.textField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.312")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public enum RootMessageType
{
/// <remarks/>
INFO,
/// <remarks/>
WARNING,
/// <remarks/>
VIOLATION,
/// <remarks/>
ERROR,
/// <remarks/>
XSD_ERROR,
}
}

12
bsmd.dbh/ResponseUtil.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bsmd.dbh
{
internal static class ResponseUtil
{
}
}

View File

@ -66,14 +66,17 @@
<Compile Include="..\bsmd.database\Properties\AssemblyProjectKeyInfo.cs">
<Link>Properties\AssemblyProjectKeyInfo.cs</Link>
</Compile>
<Compile Include="MessageController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Request.cs" />
<Compile Include="Response.cs" />
<Compile Include="RequestUtil.cs" />
<Compile Include="Request\NSWRequest.cs" />
<Compile Include="ResponseUtil.cs" />
<Compile Include="Response\NSWResponse.cs" />
<Compile Include="Web References\DBHWebReference\Reference.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -125,10 +128,7 @@
<ItemGroup>
<Content Include="readme.txt" />
</ItemGroup>
<ItemGroup>
<Folder Include="Request\" />
<Folder Include="Response\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.