Einstellungen, ATA ATD SEC

This commit is contained in:
Daniel Schick 2022-11-01 13:35:21 +01:00
parent ba2bf9833e
commit d16e7a42d6
5 changed files with 224 additions and 8 deletions

View File

@ -80,7 +80,7 @@ namespace bsmd.dbh.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")] [global::System.Configuration.DefaultSettingValueAttribute("test/bsmd_2_dbh")]
public string RemoteIncomingFolder { public string RemoteIncomingFolder {
get { get {
return ((string)(this["RemoteIncomingFolder"])); return ((string)(this["RemoteIncomingFolder"]));
@ -89,7 +89,7 @@ namespace bsmd.dbh.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")] [global::System.Configuration.DefaultSettingValueAttribute("test/dbh_2_bsmd")]
public string RemoteOutgoingFolder { public string RemoteOutgoingFolder {
get { get {
return ((string)(this["RemoteOutgoingFolder"])); return ((string)(this["RemoteOutgoingFolder"]));

View File

@ -21,10 +21,10 @@
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="RemoteIncomingFolder" Type="System.String" Scope="Application"> <Setting Name="RemoteIncomingFolder" Type="System.String" Scope="Application">
<Value Profile="(Default)" /> <Value Profile="(Default)">test/bsmd_2_dbh</Value>
</Setting> </Setting>
<Setting Name="RemoteOutgoingFolder" Type="System.String" Scope="Application"> <Setting Name="RemoteOutgoingFolder" Type="System.String" Scope="Application">
<Value Profile="(Default)" /> <Value Profile="(Default)">test/dbh_2_bsmd</Value>
</Setting> </Setting>
<Setting Name="SFTPSessionName" Type="System.String" Scope="Application"> <Setting Name="SFTPSessionName" Type="System.String" Scope="Application">
<Value Profile="(Default)" /> <Value Profile="(Default)" />

View File

@ -219,6 +219,164 @@ namespace bsmd.dbh
break; break;
#endregion #endregion
#region ATA
case Message.NotificationClass.ATA:
if (message.Elements[0] is ATA ata)
{
RootATA rootATA = new RootATA();
if (ata.ATAPortOfCall.HasValue)
rootATA.ATAPortOfCall = ata.ATAPortOfCall.Value;
root.Items = new object[1];
root.Items[0] = rootATA;
}
break;
#endregion
#region ATD
case Message.NotificationClass.ATD:
{
if (message.Elements[0] is ATD atd)
{
RootATD rootATD = new RootATD();
if(atd.ATDPortOfCall.HasValue)
rootATD.ATDPortOfCall = atd.ATDPortOfCall.Value;
root.Items = new object[1];
root.Items[0] = rootATD;
}
break;
}
#endregion
#region SEC
case Message.NotificationClass.SEC:
{
RootSEC rootSEC = new RootSEC();
SEC sec = message.Elements[0] as SEC;
List<object> secItems = new List<object>();
List<ItemsChoiceType1> choiceType1s = new List<ItemsChoiceType1>();
if (!message.MessageCore.IsTransit && (sec.KielCanalPassagePlanned ?? false))
{
rootSEC.KielCanalPassage = new RootSECKielCanalPassage();
rootSEC.KielCanalPassage.KielCanalPassagePlanned = "Y";
if (sec.KielCanalPassagePlannedIncomming.HasValue)
rootSEC.KielCanalPassage.KielCanalPassagePlannedIncoming = sec.KielCanalPassagePlannedIncomming.Value;
if (sec.KielCanalPassagePlannedOutgoing.HasValue)
rootSEC.KielCanalPassage.KielCanalPassagePlannedOutgoing = sec.KielCanalPassagePlannedOutgoing.Value;
}
rootSEC.CurrentShipSecurityLevel = (int)sec.CurrentShipSecurityLevel.Value;
if (sec.SECSimplification ?? false)
{
choiceType1s.Add(ItemsChoiceType1.SECSimplification);
secItems.Add("Y");
choiceType1s.Add(ItemsChoiceType1.PortOfCallWhereCompleteSECNotified);
secItems.Add(sec.PortOfCallWhereCompleteSECNotified);
}
else
{ // ACHTUNG Reihenfolge muss exakt dem .xsd entsprechen!
choiceType1s.Add(ItemsChoiceType1.CSOLastName);
secItems.Add(sec.CSOLastName);
choiceType1s.Add(ItemsChoiceType1.CSOFirstName);
secItems.Add(sec.CSOFirstName);
choiceType1s.Add(ItemsChoiceType1.CSOPhone);
secItems.Add(sec.CSOPhone);
choiceType1s.Add(ItemsChoiceType1.CSOFax);
secItems.Add(sec.CSOFax);
choiceType1s.Add(ItemsChoiceType1.CSOEMail);
secItems.Add(sec.CSOEMail);
choiceType1s.Add(ItemsChoiceType1.ValidISSCOnBoard);
secItems.Add(sec.ValidISSCOnBoard ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
if (!(sec.ValidISSCOnBoard ?? false) && !sec.ReasonsForNoValidISSC.IsNullOrEmpty())
{
choiceType1s.Add(ItemsChoiceType1.ReasonsForNoValidISSC);
secItems.Add(sec.ReasonsForNoValidISSC);
}
choiceType1s.Add(ItemsChoiceType1.ISSCType);
secItems.Add((ISSCType)(sec.ISSCType ?? 0));
choiceType1s.Add(ItemsChoiceType1.ISSCIssuerType);
secItems.Add((ISSCIssuerType)(sec.ISSCIssuerType ?? 0));
choiceType1s.Add(ItemsChoiceType1.ISSCIssuerName);
secItems.Add(sec.ISSCIssuerName);
if (sec.ISSCDateOfExpiration.HasValue)
{
choiceType1s.Add(ItemsChoiceType1.ISSCDateOfExpiration);
secItems.Add(sec.ISSCDateOfExpiration.Value);
}
choiceType1s.Add(ItemsChoiceType1.ApprovedSecurityPlanOnBoard);
secItems.Add(sec.ApprovedSecurityPlanOnBoard ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceType1s.Add(ItemsChoiceType1.PortFacilityOfArrival);
secItems.Add(sec.PortFacilityOfArrival);
if (sec.GeneralDescriptionOfCargo.HasValue)
{
choiceType1s.Add(ItemsChoiceType1.GeneralDescriptionOfCargo);
secItems.Add((CargoDescription)sec.GeneralDescriptionOfCargo.Value);
}
for (int i = 0; i < sec.LastTenPortFacilitesCalled.Count; i++)
{
choiceType1s.Add(ItemsChoiceType1.LastTenPortFacilitiesCalled);
RootSECLastTenPortFacilitiesCalled lastTen = new RootSECLastTenPortFacilitiesCalled();
secItems.Add(lastTen);
LastTenPortFacilitiesCalled lastTenPortFacilitiesCalled = sec.LastTenPortFacilitesCalled[i] as LastTenPortFacilitiesCalled;
lastTen.PortFacilityPortName = lastTenPortFacilitiesCalled.PortFacilityPortName;
lastTen.PortFacilityPortCountry = lastTenPortFacilitiesCalled.PortFacilityPortCountry;
lastTen.PortFacilityPortLoCode = lastTenPortFacilitiesCalled.PortFacilityPortLoCode;
if (lastTenPortFacilitiesCalled.PortFacilityDateOfArrival.HasValue)
lastTen.PortFacilityDateOfArrival = lastTenPortFacilitiesCalled.PortFacilityDateOfArrival.Value;
if (lastTenPortFacilitiesCalled.PortFacilityDateOfDeparture.HasValue)
lastTen.PortFacilityDateOfDeparture = lastTenPortFacilitiesCalled.PortFacilityDateOfDeparture.Value;
if (lastTenPortFacilitiesCalled.PortFacilityShipSecurityLevel.HasValue)
lastTen.PortFacilityShipSecurityLevel = lastTenPortFacilitiesCalled.PortFacilityShipSecurityLevel.Value;
lastTen.PortFacilitySecurityMattersToReport = lastTenPortFacilitiesCalled.PortFacilitySecurityMattersToReport;
lastTen.PortFacilityGISISCode = lastTenPortFacilitiesCalled.PortFacilityGISISCode;
if (!lastTenPortFacilitiesCalled.PortFacilityGISISCodeLocode.IsNullOrEmpty())
lastTen.PortFacilityGISISCodeLoCode = lastTenPortFacilitiesCalled.PortFacilityGISISCodeLocode;
}
for (int i = 0; i < sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Count; i++)
{
choiceType1s.Add(ItemsChoiceType1.ShipToShipActivities);
RootSECShipToShipActivities s2s = new RootSECShipToShipActivities();
secItems.Add(s2s);
ShipToShipActivitiesDuringLastTenPortFacilitiesCalled shipToShip = sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled[i] as ShipToShipActivitiesDuringLastTenPortFacilitiesCalled;
s2s.ShipToShipActivityLocation = new RootSECShipToShipActivitiesShipToShipActivityLocation();
s2s.ShipToShipActivityLocation.ShipToShipActivityLocationName = shipToShip.ShipToShipActivityLocationName;
s2s.ShipToShipActivityLocation.ShipToShipActivityLocationLoCode = shipToShip.ShipToShipActivityLocationLoCode;
s2s.ShipToShipActivityLocation.ShipToShipActivityLocationCoordinates = new RootSECShipToShipActivitiesShipToShipActivityLocationShipToShipActivityLocationCoordinates();
if (shipToShip.ShipToShipActivityLocationCoordinatesLatitude.HasValue)
s2s.ShipToShipActivityLocation.ShipToShipActivityLocationCoordinates.ShipToShipActivityLocationCoordinatesLatitude = shipToShip.ShipToShipActivityLocationCoordinatesLatitude.Value;
if (shipToShip.ShipToShipActivityLocationCoordinatesLongitude.HasValue)
s2s.ShipToShipActivityLocation.ShipToShipActivityLocationCoordinates.ShipToShipActivityLocationCoordinatesLongitude = shipToShip.ShipToShipActivityLocationCoordinatesLongitude.Value;
if (shipToShip.ShipToShipActivityDateFrom.HasValue)
s2s.ShipToShipActivityDateFrom = shipToShip.ShipToShipActivityDateFrom.Value;
if (shipToShip.ShipToShipActivityDateTo.HasValue)
s2s.ShipToShipActivityDateTo = shipToShip.ShipToShipActivityDateTo.Value;
//int activityType;
//if (!Int32.TryParse(shipToShip.ShipToShipActivityType, out activityType))
//activityType = NOA_NOD.getCallPurposeCodeFromDescription(shipToShip.ShipToShipActivityType) ?? 0;
//s2s.ShipToShipActivityType = activityType;
if (shipToShip.ShipToShipActivityTypeCode.HasValue)
s2s.ShipToShipActivityType = shipToShip.ShipToShipActivityTypeCode.Value;
s2s.ShipToShipActivitySecurityMattersToReport = shipToShip.ShipToShipActivitySecurityMattersToReport;
}
}
rootSEC.Items = secItems.ToArray();
rootSEC.ItemsElementName = choiceType1s.ToArray();
root.Items = new object[1];
root.Items[0] = rootSEC;
}
break;
#endregion
default: default:
_log.WarnFormat("Message type {0} not (yet) supported for dbh", message.MessageNotificationClassDisplay); _log.WarnFormat("Message type {0} not (yet) supported for dbh", message.MessageNotificationClassDisplay);
break; break;
@ -226,7 +384,7 @@ namespace bsmd.dbh
// serialize output structure to file // 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); string filename = string.Format("NSW.BSMD.DBH.{1}.{0}.xml", (message == null) ? "CANCEL" : message.MessageNotificationClassDisplay, core.Id.Value);
_log.InfoFormat("saving {0} to output directory", filename); _log.InfoFormat("saving {0} to output directory", filename);
string filePath = Path.Combine(Path.GetTempPath(), filename); string filePath = Path.Combine(Path.GetTempPath(), filename);

View File

@ -3,17 +3,75 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Serialization;
using log4net;
using bsmd.database;
namespace bsmd.dbh namespace bsmd.dbh
{ {
internal static class ResponseUtil internal static class ResponseUtil
{ {
private static readonly ILog _log = LogManager.GetLogger(typeof(ResponseUtil));
private static readonly Regex _regexFilename = new Regex(@".*NSW\.DBH\.BSMD\.(.*)\.(.*)\.xml");
internal static bool Read(string inputFile) internal static bool Read(string inputFile)
{ {
throw new NotImplementedException(); bool result = false;
if(!inputFile.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
{
_log.ErrorFormat("no xml file: {0}", inputFile);
return result;
}
Match m = _regexFilename.Match(inputFile);
if(!m.Success) {
_log.WarnFormat("returned file doesn't follow naming convention NSW.DBH.BSMD.*:{0}", inputFile);
return result;
}
string guidString = m.Groups[0].Value;
if(!Guid.TryParse(guidString, out Guid coreId))
{
_log.ErrorFormat("matched Guid couldn't be parsed: {0}", guidString);
return result;
}
string notificationClassString = m.Groups[1].Value;
if(!Enum.TryParse<Message.NotificationClass>(notificationClassString, out Message.NotificationClass notificationClass))
{
_log.WarnFormat("Notification class couldn't be parsed: {0}", notificationClassString);
return result;
}
MessageCore aCore = DBManager.Instance.GetMessageCoreById(coreId);
if(aCore == null)
{
_log.ErrorFormat("There is no core with id {0}", coreId);
return result;
}
bsmd.dbh.Response.Root root;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(bsmd.dbh.Response.Root));
using (Stream s = new FileStream(inputFile, FileMode.Open))
{
root = (bsmd.dbh.Response.Root) serializer.Deserialize(s);
}
}
catch(Exception ex)
{
_log.ErrorFormat("Failed to deserialize: {0}", ex.Message);
return result;
}
return result;
} }
} }
} }

View File

@ -26,10 +26,10 @@
<value /> <value />
</setting> </setting>
<setting name="RemoteIncomingFolder" serializeAs="String"> <setting name="RemoteIncomingFolder" serializeAs="String">
<value /> <value>test/bsmd_2_dbh</value>
</setting> </setting>
<setting name="RemoteOutgoingFolder" serializeAs="String"> <setting name="RemoteOutgoingFolder" serializeAs="String">
<value /> <value>test/dbh_2_bsmd</value>
</setting> </setting>
<setting name="SFTPSessionName" serializeAs="String"> <setting name="SFTPSessionName" serializeAs="String">
<value /> <value />