git_bsmd/bsmd.dbh/RequestUtil.cs
Daniel Schick 04907e2104 SFTPSession entfernt
stattdessen wird ein open command gesendet. Gleichzeitig wird die Ausgabe nicht mehr
zum Ende gelesen sondern per Events abgefragt. Die Hoffnung ist hier, dass der Prozess nicht
mehr auf dem ReadToEnd() blockiert, wobei das nie bestätigt werden konnte.
2023-07-08 12:20:40 +02:00

1746 lines
119 KiB
C#

// Copyright (c) 2020-present schick Informatik
// Description: Tooling zum Erzeugen von Nachrichten für dbh Interface
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.Item71;
root.SourceDocumentVersion = "7.1";
root.Timestamp = DateTime.Now;
string filenameComponent;
if(core.InitialHIS == Message.NSWProvider.DBH_MAERSK)
{
filenameComponent = "BSMDMAERSK";
root.Sender = Properties.Settings.Default.SenderMaersk;
}
else
{
filenameComponent = "BSMD";
root.Sender = Properties.Settings.Default.Sender;
}
if(message != null)
root.SenderReference = message.Id.Value.ToString("N");
_log.InfoFormat("DBH: setting sender to {0}", root.Sender);
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;
if(!core.VisitId.IsNullOrEmpty())
{
root.Item = core.VisitId;
root.ItemElementName = ItemChoiceType2.VisitId;
}
if(!core.TransitId.IsNullOrEmpty())
{
root.Item = core.TransitId;
root.ItemElementName = ItemChoiceType2.TransitId;
}
if(core.Cancelled ?? false)
{
root.Type = RootType.CANCEL;
}
else if (message.Reset)
{
RootReportingClassesToReset rrctr = new RootReportingClassesToReset();
rrctr.ReportingClassToReset = new string[1];
rrctr.ReportingClassToReset[0] = message.MessageNotificationClassDisplay;
root.Items = new object[1];
root.Items[0] = rrctr;
root.Type = RootType.RESET;
}
else
{
root.Type = RootType.DATA;
switch (message.MessageNotificationClass)
{
#region VISIT
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;
#endregion
#region TRANSIT
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;
#endregion
#region STAT
case Message.NotificationClass.STAT:
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;
}
// rootStat.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootStat;
break;
#endregion
#region NOA_NOD
case Message.NotificationClass.NOA_NOD:
NOA_NOD noa_nod = message.Elements[0] as NOA_NOD;
RootNOA_NOD rootNOA_NOD = new RootNOA_NOD();
rootNOA_NOD.ETAToNextPortSpecified = noa_nod.ETAToNextPort.HasValue;
if (noa_nod.ETAToNextPort.HasValue)
rootNOA_NOD.ETAToNextPort = noa_nod.ETAToNextPort.Value.ToUTCSerializableDateTime();
rootNOA_NOD.ETDFromLastPortSpecified = noa_nod.ETDFromLastPort.HasValue;
if (noa_nod.ETDFromLastPort.HasValue)
rootNOA_NOD.ETDFromLastPort = noa_nod.ETDFromLastPort.Value.ToUTCSerializableDateTime();
rootNOA_NOD.LastPort = noa_nod.LastPort;
rootNOA_NOD.NextPort = noa_nod.NextPort;
List<ItemsChoiceType> choiceList = new List<ItemsChoiceType>();
List<object> choices = new List<object>();
if (message.MessageCore.IsTransit)
{
if (noa_nod.ETAToKielCanal.HasValue)
{
choiceList.Add(ItemsChoiceType.ETAToKielCanal);
choices.Add(noa_nod.ETAToKielCanal.Value.ToUTCSerializableDateTime());
}
if (noa_nod.ETDFromKielCanal.HasValue)
{
choiceList.Add(ItemsChoiceType.ETDFromKielCanal);
choices.Add(noa_nod.ETDFromKielCanal.Value.ToUTCSerializableDateTime());
}
}
else
{
if (noa_nod.ETAToPortOfCall.HasValue)
{
choiceList.Add(ItemsChoiceType.ETAToPortOfCall);
choices.Add(noa_nod.ETAToPortOfCall.Value.ToUTCSerializableDateTime());
}
if (noa_nod.ETDFromPortOfCall.HasValue)
{
choiceList.Add(ItemsChoiceType.ETDFromPortOfCall);
choices.Add(noa_nod.ETDFromPortOfCall.Value.ToUTCSerializableDateTime());
}
for (int i = 0; i < noa_nod.CallPurposes.Count; i++)
{
choiceList.Add(ItemsChoiceType.CallPurpose);
RootNOA_NODCallPurpose rnncp = new RootNOA_NODCallPurpose();
CallPurpose callPurpose = noa_nod.CallPurposes[i];
rnncp.CallPurposeCode = callPurpose.CallPurposeCode;
if (callPurpose.CallPurposeDescription != string.Empty)
rnncp.CallPurposeDescription = callPurpose.CallPurposeDescription;
choices.Add(rnncp);
}
}
rootNOA_NOD.Items = choices.ToArray();
rootNOA_NOD.ItemsElementName = choiceList.ToArray();
// rootNOA_NOD.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootNOA_NOD;
break;
#endregion
#region AGNT
case Message.NotificationClass.AGNT:
AGNT agnt = message.Elements[0] as AGNT;
RootAGNT rootAGNT = new RootAGNT();
rootAGNT.AgentCity = agnt.AgentCity;
rootAGNT.AgentCompanyName = agnt.AgentCompanyName;
rootAGNT.AgentCountry = agnt.AgentCountry;
rootAGNT.AgentEMail = agnt.AgentEMail;
rootAGNT.AgentFax = agnt.AgentFax;
rootAGNT.AgentFirstName = agnt.AgentFirstName;
rootAGNT.AgentLastName = agnt.AgentLastName;
rootAGNT.AgentPhone = agnt.AgentPhone;
rootAGNT.AgentPostalCode = agnt.AgentPostalCode;
rootAGNT.AgentStreetAndNumber = agnt.AgentStreetAndNumber;
// rootAGNT.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootAGNT;
break;
#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.ToUTCSerializableDateTime();
// rootATA.ReportingParty = rp;
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.ToUTCSerializableDateTime();
// rootATD.ReportingParty = rp;
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.ToUTCSerializableDateTime();
rootSEC.KielCanalPassage.KielCanalPassagePlannedIncomingSpecified = true;
}
if (sec.KielCanalPassagePlannedOutgoing.HasValue)
{
rootSEC.KielCanalPassage.KielCanalPassagePlannedOutgoing = sec.KielCanalPassagePlannedOutgoing.Value.ToUTCSerializableDateTime();
rootSEC.KielCanalPassage.KielCanalPassagePlannedOutgoingSpecified = true;
}
}
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();
// rootSEC.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootSEC;
}
break;
#endregion
#region BPOL
case Message.NotificationClass.BPOL:
{
if (message.Elements[0] is BPOL bpol)
{
RootBPOL rootBPOL = new RootBPOL();
RootBPOLPortOfItinerary[] poiArray = new RootBPOLPortOfItinerary[bpol.PortOfItineraries.Count];
rootBPOL.PortOfItinerary = poiArray;
for (int i = 0; i < bpol.PortOfItineraries.Count; i++)
{
RootBPOLPortOfItinerary port = new RootBPOLPortOfItinerary();
PortOfItinerary portOfItinerary = bpol.PortOfItineraries[i];
if (portOfItinerary.PortOfItineraryETA.HasValue)
port.PortOfItineraryETA = portOfItinerary.PortOfItineraryETA.Value.ToUTCSerializableDateTime();
port.PortOfItineraryName = portOfItinerary.PortOfItineraryName;
poiArray[i] = port;
}
if (bpol.StowawaysOnBoard.HasValue)
rootBPOL.StowawayOnBoard = bpol.StowawaysOnBoard.Value ?
RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
else
rootBPOL.StowawayOnBoard = RootSECValidISSCOnBoard.N;
// rootBPOL.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootBPOL;
}
break;
}
#endregion
#region CREW
case Message.NotificationClass.CREW:
{
RootCREW rootCREW = new RootCREW();
rootCREW.CrewMember = new RootCREWCrewMember[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
CREW crew = message.Elements[i] as CREW;
rootCREW.CrewMember[i] = new RootCREWCrewMember();
if (crew.CrewMemberDateOfBirth.HasValue)
rootCREW.CrewMember[i].CrewMemberDateOfBirth = crew.CrewMemberDateOfBirth.Value;
rootCREW.CrewMember[i].CrewMemberDuty = crew.CrewMemberDuty;
rootCREW.CrewMember[i].CrewMemberFirstName = crew.CrewMemberFirstName;
rootCREW.CrewMember[i].CrewMemberGenderSpecified = crew.CrewMemberGender.HasValue;
if (crew.CrewMemberGender.HasValue)
rootCREW.CrewMember[i].CrewMemberGender = SetGender(crew.CrewMemberGender.Value);
rootCREW.CrewMember[i].CrewMemberIdentityDocumentId = crew.CrewMemberIdentityDocumentId;
if (crew.CrewMemberIdentityDocumentType.HasValue)
rootCREW.CrewMember[i].CrewMemberIdentityDocumentType = (IdDocType)crew.CrewMemberIdentityDocumentType.Value;
rootCREW.CrewMember[i].CrewMemberLastName = crew.CrewMemberLastName;
rootCREW.CrewMember[i].CrewMemberNationality = crew.CrewMemberNationality;
rootCREW.CrewMember[i].CrewMemberPlaceOfBirth = crew.CrewMemberPlaceOfBirth;
rootCREW.CrewMember[i].CrewMemberVisaNumber = crew.CrewMemberVisaNumber;
if (crew.CrewMemberIdentityDocumentIssuingState.Trim().Length == 2)
rootCREW.CrewMember[i].CrewMemberIdentityDocumentIssuingState = crew.CrewMemberIdentityDocumentIssuingState;
if (crew.CrewMemberIdentityDocumentExpiryDate.HasValue)
rootCREW.CrewMember[i].CrewMemberIdentityDocumentExpiryDate = crew.CrewMemberIdentityDocumentExpiryDate.Value;
}
// rootCREW.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootCREW;
}
break;
#endregion
#region PAS
case Message.NotificationClass.PAS:
{
RootPAS rootPAS = new RootPAS();
rootPAS.Passenger = new RootPASPassenger[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
PAS pas = message.Elements[i] as PAS;
rootPAS.Passenger[i] = new RootPASPassenger();
rootPAS.Passenger[i].PassengerLastName = pas.PassengerLastName;
rootPAS.Passenger[i].PassengerFirstName = pas.PassengerFirstName;
rootPAS.Passenger[i].PassengerPlaceOfBirth = pas.PassengerPlaceOfBirth;
if (pas.PassengerDateOfBirth.HasValue)
rootPAS.Passenger[i].PassengerDateOfBirth = pas.PassengerDateOfBirth.Value;
rootPAS.Passenger[i].PassengerGenderSpecified = pas.PassengerGender.HasValue;
if (pas.PassengerGender.HasValue)
rootPAS.Passenger[i].PassengerGender = SetGender(pas.PassengerGender.Value);
rootPAS.Passenger[i].PassengerNationality = pas.PassengerNationality;
if (pas.PassengerIdentityDocumentType.HasValue)
rootPAS.Passenger[i].PassengerIdentityDocumentType = (IdDocType)pas.PassengerIdentityDocumentType.Value;
rootPAS.Passenger[i].PassengerIdentityDocumentId = pas.PassengerIdentityDocumentId;
rootPAS.Passenger[i].PassengerVisaNumber = pas.PassengerVisaNumber;
rootPAS.Passenger[i].PassengerPortOfEmbarkation = pas.PassengerPortOfEmbarkation;
rootPAS.Passenger[i].PassengerPortOfDisembarkation = pas.PassengerPortOfDisembarkation;
rootPAS.Passenger[i].PassengerInTransit = pas.PassengerInTransit ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (pas.PassengerIdentityDocumentIssuingState.Trim().Length == 2)
rootPAS.Passenger[i].PassengerIdentityDocumentIssuingState = pas.PassengerIdentityDocumentIssuingState;
if (pas.PassengerIdentityDocumentExpiryDate.HasValue)
rootPAS.Passenger[i].PassengerIdentityDocumentExpiryDate = pas.PassengerIdentityDocumentExpiryDate.Value;
}
// rootPAS.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootPAS;
}
break;
#endregion
#region BKRA
case Message.NotificationClass.BKRA:
{
RootBKRA rootBKRA = new RootBKRA();
rootBKRA.BunkerFuelArrival = new RootBKRABunkerFuelArrival[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
BRKA bkra = message.Elements[i] as BRKA;
rootBKRA.BunkerFuelArrival[i] = new RootBKRABunkerFuelArrival();
rootBKRA.BunkerFuelArrival[i].BunkerFuelQuantity_TNE = Decimal.Round((decimal)(bkra.BunkerFuelQuantity_TNE ?? 0), 3);
rootBKRA.BunkerFuelArrival[i].BunkerFuelType = bkra.BunkerFuelType;
}
// rootBKRA.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootBKRA;
}
break;
#endregion
#region BKRD
case Message.NotificationClass.BKRD:
{
RootBKRD rootBKRD = new RootBKRD();
rootBKRD.BunkerFuelDeparture = new RootBKRDBunkerFuelDeparture[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
BRKD bkrd = message.Elements[i] as BRKD;
rootBKRD.BunkerFuelDeparture[i] = new RootBKRDBunkerFuelDeparture();
rootBKRD.BunkerFuelDeparture[i].BunkerFuelQuantity_TNE = Decimal.Round((decimal)(bkrd.BunkerFuelQuantity_TNE ?? 0), 3);
rootBKRD.BunkerFuelDeparture[i].BunkerFuelType = bkrd.BunkerFuelType;
}
// rootBKRD.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootBKRD;
}
break;
#endregion
#region TIEFA
case Message.NotificationClass.TIEFA:
{
RootTIEFA rootTIEFA = new RootTIEFA();
TIEFA tiefa = message.Elements[0] as TIEFA;
rootTIEFA.DraughtUponArrival_DMT = Decimal.Round((decimal)(tiefa.DraughtUponArrival_DMT ?? 0), 1);
// rootTIEFA.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootTIEFA;
}
break;
#endregion
#region TIEFD
case Message.NotificationClass.TIEFD:
{
RootTIEFD rootTIEFD = new RootTIEFD();
TIEFD tiefd = message.Elements[0] as TIEFD;
rootTIEFD.DraughtUponDeparture_DMT = Decimal.Round((decimal)(tiefd.DraughtUponDeparture_DMT ?? 0));
// rootTIEFD.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootTIEFD;
}
break;
#endregion
#region NAME
case Message.NotificationClass.NAME:
{
RootNAME rootName = new RootNAME();
NAME name = message.Elements[0] as NAME;
rootName.NameOfMaster = name.NameOfMaster;
// rootName.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootName;
}
break;
#endregion
#region POBA
case Message.NotificationClass.POBA:
{
RootPOBA rootPoba = new RootPOBA();
POBA poba = message.Elements[0] as POBA;
rootPoba.TotalCrewMembersOnBoardUponArrival = poba.TotalCrewMembersOnBoardUponArrival ?? 0;
rootPoba.TotalPassengersOnBoardUponArrival = poba.TotalPassengersOnBoardUponArrival ?? 0;
rootPoba.TotalPersonsOnBoardUponArrival = poba.TotalPersonsOnBoardUponArrival ?? 0;
rootPoba.TotalStowawaysOnBoardUponArrival = poba.TotalStowawaysOnBoardUponArrival ?? 0;
// rootPoba.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootPoba;
}
break;
#endregion
#region POBD
case Message.NotificationClass.POBD:
{
RootPOBD rootPobd = new RootPOBD();
POBD pobd = message.Elements[0] as POBD;
rootPobd.TotalCrewMembersOnBoardUponDeparture = pobd.TotalCrewMembersOnBoardUponDeparture ?? 0;
rootPobd.TotalPassengersOnBoardUponDeparture = pobd.TotalPassengersOnBoardUponDeparture ?? 0;
rootPobd.TotalPersonsOnBoardUponDeparture = pobd.TotalPersonsOnBoardUponDeparture ?? 0;
rootPobd.TotalStowawaysOnBoardUponDeparture = pobd.TotalStowawaysOnBoardUponDeparture ?? 0;
// rootPobd.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootPobd;
}
break;
#endregion
#region LADG
case Message.NotificationClass.LADG:
{
RootLADG rootLADG = new RootLADG();
List<RootLADGCargo> cargoList = new List<RootLADGCargo>();
for (int i = 0; i < message.Elements.Count; i++)
{
LADG ladg = message.Elements[i] as LADG;
RootLADGCargo cargo = new RootLADGCargo();
if (ladg.CargoHandlingType.HasValue)
{
if (ladg.CargoHandlingType > 1) continue;
cargo.CargoHandlingType = (ladg.CargoHandlingType == 0) ? HandlingType.LOAD : HandlingType.DISCHARGE;
}
cargo.CargoCodeNST = ladg.CargoCodeNST;
if (!ladg.CargoCodeNST.IsNullOrEmpty())
{
if (cargo.CargoCodeNST.Length > 2)
{
cargo.CargoCodeNST = ladg.CargoCodeNST.Substring(0, 2);
}
}
if (!ladg.CargoCodeNST_3.IsNullOrEmpty())
cargo.CargoCodeNST_3 = ladg.CargoCodeNST_3.Substring(0, 1);
if (ladg.CargoLACode.HasValue)
cargo.CargoLACode = ladg.CargoLACode.Value;
cargo.CargoLACodeSpecified = ladg.CargoLACode.HasValue;
if (ladg.CargoGrossQuantity_TNE.HasValue)
cargo.CargoGrossQuantity_TNE = Decimal.Round((decimal)ladg.CargoGrossQuantity_TNE.Value, 3);
cargo.CargoNumberOfItemsSpecified = ladg.CargoNumberOfItems.HasValue;
if (ladg.CargoNumberOfItems.HasValue)
cargo.CargoNumberOfItems = ladg.CargoNumberOfItems.Value;
if (ladg.PortOfLoading.IsNullOrEmpty())
cargo.CargoPortOfLoading = "ZZUKN";
else
cargo.CargoPortOfLoading = ladg.PortOfLoading;
if (ladg.PortOfDischarge.IsNullOrEmpty())
cargo.CargoPortOfDischarge = "ZZUKN";
else
cargo.CargoPortOfDischarge = ladg.PortOfDischarge;
cargoList.Add(cargo);
}
rootLADG.Cargo = cargoList.ToArray();
// rootLADG.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootLADG;
}
break;
#endregion
#region INFO
case Message.NotificationClass.INFO:
{
RootINFO rootInfo = new RootINFO();
INFO info = message.Elements[0] as INFO;
if (info.ShippingArea.HasValue)
rootInfo.ShippingArea = (ShippingArea)info.ShippingArea.Value;
rootInfo.PortArea = info.PortArea;
rootInfo.RequestedPositionInPortOfCall = info.RequestedPositionInPortOfCall;
if (!info.SpecialRequirementsOfShipAtBerth.IsNullOrEmpty())
rootInfo.SpecialRequirementsOfShipAtBerth = info.SpecialRequirementsOfShipAtBerth;
if (info.SpecialRequirementsOfShipAtBerth.IsNullOrEmpty())
{
_log.Info("dbh INFO send: SpecialRequirementsOfShipAtBerth is empty.");
// Name des Agenten eintragen
}
rootInfo.ConstructionCharacteristicsOfShip = info.ConstructionCharacteristicsOfShip;
rootInfo.BowThrusterPower = info.BowThrusterPower;
rootInfo.SternThrusterPower = info.SternThrusterPower;
if (info.FumigatedBulkCargo.HasValue)
rootInfo.FumigatedBulkCargo = (info.FumigatedBulkCargo.Value == 0) ? RootINFOFumigatedBulkCargo.N : RootINFOFumigatedBulkCargo.Y;
else
rootInfo.FumigatedBulkCargo = RootINFOFumigatedBulkCargo.N;
rootInfo.DeadWeightSummer_TNESpecified = info.DeplacementSummerDraught_TNE.HasValue;
if (info.DeplacementSummerDraught_TNE.HasValue)
rootInfo.DeadWeightSummer_TNE = Decimal.Round((decimal)info.DeplacementSummerDraught_TNE.Value, 3);
// rootInfo.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootInfo;
}
break;
#endregion
#region SERV
case Message.NotificationClass.SERV:
{
RootSERV rootServ = new RootSERV();
rootServ.Service = new RootSERVService[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
rootServ.Service[i] = new RootSERVService();
SERV serv = message.Elements[i] as SERV;
rootServ.Service[i].ServiceName = serv.ServiceName;
rootServ.Service[i].ServiceBeneficiary = serv.ServiceBeneficiary;
rootServ.Service[i].ServiceInvoiceRecipient = serv.ServiceInvoiceRecipient;
}
// rootServ.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootServ;
}
break;
#endregion
#region PRE72H
case Message.NotificationClass.PRE72H:
{
RootPRE72H rootPre = new RootPRE72H();
PRE72H pre72h = message.Elements[0] as PRE72H;
rootPre.Tanker = pre72h.Tanker ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (pre72h.Tanker ?? false)
{
rootPre.TankerDetails = new RootPRE72HTankerDetails();
if (pre72h.TankerHullConfiguration.HasValue)
rootPre.TankerDetails.TankerHullConfiguration = (HullConfiguration)pre72h.TankerHullConfiguration.Value;
if (pre72h.ConditionCargoBallastTanks.HasValue)
rootPre.TankerDetails.ConditionCargoBallastTanks = (TankCondition)pre72h.ConditionCargoBallastTanks.Value;
if (pre72h.NatureOfCargo != string.Empty)
rootPre.TankerDetails.TypeOfCargo = pre72h.NatureOfCargo;
bool sendVolume = pre72h.VolumeOfCargo > 0;
rootPre.TankerDetails.VolumeOfCargo_TNESpecified = sendVolume;
if (sendVolume)
rootPre.TankerDetails.VolumeOfCargo_TNE = Decimal.Round((decimal)(pre72h.VolumeOfCargo.Value), 3);
}
rootPre.PlannedOperations = pre72h.PlannedOperations;
rootPre.PlannedWorks = pre72h.PlannedWorks;
rootPre.DateOfLastExpandedInspectionSpecified = pre72h.DateOfLastExpandedInspection.HasValue;
if (pre72h.DateOfLastExpandedInspection.HasValue)
rootPre.DateOfLastExpandedInspection = pre72h.DateOfLastExpandedInspection.Value;
if (pre72h.PlannedPeriodOfStay_HUR.HasValue)
rootPre.PlannedPeriodOfStay_HUR = Decimal.Round((decimal)(pre72h.PlannedPeriodOfStay_HUR.Value), 2);
// rootPre.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootPre;
}
break;
#endregion
#region MDH
case Message.NotificationClass.MDH:
{
RootMDH rootMDH = new RootMDH();
MDH mdh = message.Elements[0] as MDH;
if (!mdh.MDHSimplification.HasValue)
{
_log.ErrorFormat("MDH {0} doesnt have MDHSimplification field set, aborting message", mdh.Id);
return null; // das wird wahrscheinlich nie passieren
}
if (mdh.MDHSimplification.Value)
{
rootMDH.Items = new object[2];
rootMDH.ItemsElementName = new ItemsChoiceType2[2];
rootMDH.ItemsElementName[0] = ItemsChoiceType2.MDHSimplification;
rootMDH.Items[0] = "Y";
rootMDH.ItemsElementName[1] = ItemsChoiceType2.PortOfCallWhereCompleteMDHNotified;
rootMDH.Items[1] = mdh.PortOfCallWhereCompleteMDHNotified;
}
else
{
List<object> mdhItems = new List<object>();
List<ItemsChoiceType2> choiceTypes2 = new List<ItemsChoiceType2>
{
ItemsChoiceType2.NonAccidentialDeathsDuringVoyage
};
mdhItems.Add((mdh.NonAccidentalDeathsDuringVoyage ?? false) ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
if (mdh.NonAccidentalDeathsDuringVoyage ?? false)
{
choiceTypes2.Add(ItemsChoiceType2.NonAccidentialDeathsDuringVoyageCount);
mdhItems.Add(mdh.NonAccidentalDeathsDuringVoyageCount ?? 0);
}
choiceTypes2.Add(ItemsChoiceType2.SuspisionInfectiousNature);
mdhItems.Add(mdh.SuspisionInfectiousNature ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.NumberOfIllPersonsHigherThanExpected);
mdhItems.Add(mdh.NumberOfIllPersonsHigherThanExpected ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
if (mdh.NumberOfIllPersonsHigherThanExpected ?? false)
{
choiceTypes2.Add(ItemsChoiceType2.NumberOfIllPersons);
mdhItems.Add(mdh.NumberOfIllPersons ?? 0);
}
choiceTypes2.Add(ItemsChoiceType2.SickPersonsOnBoard);
mdhItems.Add(mdh.SickPersonsOnBoard ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.MedicalConsulted);
mdhItems.Add(mdh.MedicalConsulted ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.AwareOfConditionsForFurtherInfections);
mdhItems.Add(mdh.AwareOfFurtherInfections ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.SanitaryMeasuresApplied);
mdhItems.Add(mdh.SanitaryMeasuresApplied ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
if (mdh.SanitaryMeasuresApplied ?? false)
{
foreach (SanitaryMeasuresDetail smd in mdh.SanitaryMeasuresDetails)
{
choiceTypes2.Add(ItemsChoiceType2.SanitaryMeasuresDetails);
RootMDHSanitaryMeasuresDetails smDet = new RootMDHSanitaryMeasuresDetails();
if (mdh.SanitaryMeasuresDate.HasValue)
smDet.SanitaryMeasuresDate = smd.SanitaryMeasuresDate.Value;
smDet.SanitaryMeasuresType = smd.SanitaryMeasuresType;
smDet.SanitaryMeasuresLocation = smd.SanitaryMeasuresLocation;
mdhItems.Add(smDet);
}
}
choiceTypes2.Add(ItemsChoiceType2.StowawaysDetected);
mdhItems.Add(mdh.StowawaysDetected ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.StowawaysJoiningLocation);
string concatLocations = "";
foreach (StowawaysJoiningLocation sjl in mdh.StowawaysJoiningLocations)
{
if (!sjl.StowawayJoiningLocation.IsNullOrEmpty())
concatLocations = string.Format("{0} {1}", concatLocations, sjl.StowawayJoiningLocation);
}
mdhItems.Add(concatLocations);
choiceTypes2.Add(ItemsChoiceType2.SickAnimalOrPetOnBoard);
mdhItems.Add(mdh.SickAnimalOrPetOnBoard ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.ValidSanitaryControlExemptionOrCertificateOnBoard);
mdhItems.Add(mdh.ValidSanitaryControlExemptionOrCertificateOnBoard ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
if (mdh.ValidSanitaryControlExemptionOrCertificateOnBoard ?? false)
{
choiceTypes2.Add(ItemsChoiceType2.ValidSanitaryControlExemptionOrCertificate);
RootMDHValidSanitaryControlExemptionOrCertificate cert = new RootMDHValidSanitaryControlExemptionOrCertificate();
mdhItems.Add(cert);
cert.DateOfIssue = mdh.DateOfIssue.Value;
cert.PlaceOfIssue = mdh.PlaceOfIssue;
}
choiceTypes2.Add(ItemsChoiceType2.SanitaryControlReinspectionRequired);
mdhItems.Add(mdh.SanitaryControlReinspectionRequired ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
choiceTypes2.Add(ItemsChoiceType2.InfectedAreaVisited);
mdhItems.Add(mdh.InfectedAreaVisited ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N);
foreach (InfectedArea ia in mdh.InfectedAreas)
{
if (!mdh.InfectedAreaPort.IsNullOrEmpty() && mdh.InfectedAreaDate.HasValue)
{
choiceTypes2.Add(ItemsChoiceType2.InfectedArea);
RootMDHInfectedArea infected = new RootMDHInfectedArea();
mdhItems.Add(infected);
infected.InfectedAreaPort = ia.InfectedAreaPort;
infected.InfectedAreaDate = ia.InfectedAreaDate.Value;
}
}
if (mdh.PortOfCallLast30Days.Count > 0)
{
choiceTypes2.Add(ItemsChoiceType2.PortsOfCallLast30Days);
RootMDHPortsOfCallLast30Days l30d = new RootMDHPortsOfCallLast30Days();
mdhItems.Add(l30d);
l30d.PortOfCallLast30Days = new RootMDHPortsOfCallLast30DaysPortOfCallLast30Days[mdh.PortOfCallLast30Days.Count];
for (int i = 0; i < mdh.PortOfCallLast30Days.Count; i++)
{
l30d.PortOfCallLast30Days[i] = new RootMDHPortsOfCallLast30DaysPortOfCallLast30Days();
PortOfCallLast30Days portOfCallLast30Days = mdh.PortOfCallLast30Days[i] as PortOfCallLast30Days;
l30d.PortOfCallLast30Days[i].PortOfCallLast30DaysCrewJoinedShip = new RootMDHPortsOfCallLast30DaysPortOfCallLast30DaysPortOfCallLast30DaysCrewJoinedShip();
if (portOfCallLast30Days.CrewJoinedShip.Count > 0)
{
l30d.PortOfCallLast30Days[i].PortOfCallLast30DaysCrewJoinedShip.PortOfCallLast30DaysCrewJoinedShipName = new string[portOfCallLast30Days.CrewJoinedShip.Count];
for (int j = 0; j < portOfCallLast30Days.CrewJoinedShip.Count; j++)
{
l30d.PortOfCallLast30Days[i].PortOfCallLast30DaysCrewJoinedShip.PortOfCallLast30DaysCrewJoinedShipName[j] = ((PortOfCallLast30DaysCrewJoinedShip)portOfCallLast30Days.CrewJoinedShip[j]).PortOfCallLast30DaysCrewJoinedShipName;
}
}
l30d.PortOfCallLast30Days[i].PortOfCallLast30DaysCrewMembersJoined = portOfCallLast30Days.PortOfCallLast30DaysCrewMembersJoined ?? false ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (portOfCallLast30Days.PortOfCallLast30DaysDateOfDeparture.HasValue)
l30d.PortOfCallLast30Days[i].PortOfCallLast30DaysDateOfDeparture = portOfCallLast30Days.PortOfCallLast30DaysDateOfDeparture.Value;
l30d.PortOfCallLast30Days[i].PortOfCallLast30DaysLocode = portOfCallLast30Days.PortOfCallLast30DaysLocode;
}
}
rootMDH.Items = mdhItems.ToArray();
rootMDH.ItemsElementName = choiceTypes2.ToArray();
}
// rootMDH.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootMDH;
}
break;
#endregion
#region WAS
case Message.NotificationClass.WAS:
{
RootWAS rootWAS = new RootWAS();
WAS was = message.Elements[0] as WAS;
if (was.WasteDisposalValidExemption ?? false)
{
rootWAS.Items = new object[1];
rootWAS.ItemsElementName = new ItemsChoiceType3[1];
rootWAS.ItemsElementName[0] = ItemsChoiceType3.WasteDisposalValidExemption;
rootWAS.Items[0] = "Y";
}
else
{
// ACHTUNG hier ist die Reihenfolge entscheidend! (siehe XSD)
List<ItemsChoiceType3> choiceType3s = new List<ItemsChoiceType3>();
List<object> wasteItems = new List<object>();
choiceType3s.Add(ItemsChoiceType3.LastWasteDisposalPort);
wasteItems.Add(was.LastWasteDisposalPort);
if (was.LastWasteDisposalDate.HasValue)
{
choiceType3s.Add(ItemsChoiceType3.LastWasteDisposalDate);
wasteItems.Add(was.LastWasteDisposalDate);
}
for (int i = 0; i < was.WasteDisposalServiceProvider.Count; i++)
{
if ((was.WasteDisposalServiceProvider[i]).WasteDisposalServiceProviderName.Trim().IsNullOrEmpty()) continue;
choiceType3s.Add(ItemsChoiceType3.WasteDisposalServiceProviderName);
wasteItems.Add((was.WasteDisposalServiceProvider[i]).WasteDisposalServiceProviderName);
}
choiceType3s.Add(ItemsChoiceType3.NextWasteDisposalPort);
wasteItems.Add(was.NextWasteDisposalPort);
for (int j = 0; j < was.Waste.Count; j++)
{
choiceType3s.Add(ItemsChoiceType3.WasteItem);
RootWASWasteItem rww = new RootWASWasteItem();
Waste waste = was.Waste[j];
if ((waste.WasteType ?? 0) == 0) continue; // not a valid waste type
rww.WasteType = new RootWASWasteItemWasteType();
rww.WasteType.WasteCode = waste.WasteType.ToString();
rww.WasteType.WasteDescription = waste.WasteDescription;
rww.WasteDisposalAmount_MTQ = decimal.Round((decimal)(waste.WasteDisposalAmount_MTQ ?? 0), 3);
rww.WasteCapacity_MTQ = decimal.Round((decimal)(waste.WasteCapacity_MTQ ?? 0), 3);
rww.WasteAmountRetained_MTQ = decimal.Round((decimal)(waste.WasteAmountRetained_MTQ ?? 0), 3);
rww.WasteAmountGeneratedTillNextPort_MTQ = decimal.Round((decimal)(waste.WasteAmountGeneratedTillNextPort_MTQ ?? 0), 3);
rww.RemainingWasteDeliveryPort = waste.WasteDisposalPort;
wasteItems.Add(rww);
}
choiceType3s.Add(ItemsChoiceType3.ConfirmationOfCorrectnessAndSufficiency);
wasteItems.Add(was.ConfirmationOfCorrectness ?? false ? "Y" : "N");
rootWAS.ItemsElementName = choiceType3s.ToArray();
rootWAS.Items = wasteItems.ToArray();
}
// rootWAS.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootWAS;
}
break;
#endregion
#region TOWA
case Message.NotificationClass.TOWA:
{
RootTOWA rootTowa = new RootTOWA();
rootTowa.TowageOnArrival = new RootTOWATowageOnArrival[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
TOWA towa = message.Elements[i] as TOWA;
rootTowa.TowageOnArrival[i] = new RootTOWATowageOnArrival();
rootTowa.TowageOnArrival[i].TowageOnArrivalName = towa.TowageOnArrivalName;
rootTowa.TowageOnArrival[i].TowageOnArrivalFlag = towa.TowageOnArrivalFlag;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator = new RootTOWATowageOnArrivalTowageOnArrivalOperator();
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorCompanyName = towa.TowageOnArrivalOperatorCompanyName;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorStreetAndNumber = towa.TowageOnArrivalOperatorStreetNameAndNumber;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorPostalCode = towa.TowageOnArrivalOperatorPostalCode;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorCity = towa.TowageOnArrivalOperatorCity;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorCountry = towa.TowageOnArrivalOperatorCountry;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorPhone = towa.TowageOnArrivalOperatorPhone;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorFax = towa.TowageOnArrivalOperatorFax;
rootTowa.TowageOnArrival[i].TowageOnArrivalOperator.TowageOnArrivalOperatorEMail = towa.TowageOnArrivalOperatorEmail;
if (towa.TowageOnArrivalGrossTonnage.HasValue)
rootTowa.TowageOnArrival[i].TowageOnArrivalGrossTonnage = towa.TowageOnArrivalGrossTonnage.Value;
if (towa.TowageOnArrivalLengthOverall_MTR.HasValue)
rootTowa.TowageOnArrival[i].TowageOnArrivalLengthOverall_MTR = decimal.Round((decimal)towa.TowageOnArrivalLengthOverall_MTR.Value, 2);
if (towa.TowageOnArrivalBeam_MTR.HasValue)
rootTowa.TowageOnArrival[i].TowageOnArrivalBeam_MTR = decimal.Round((decimal)towa.TowageOnArrivalBeam_MTR.Value, 2);
rootTowa.TowageOnArrival[i].TowageOnArrivalPurposeOfCall = towa.TowageOnArrivalPurposeOfCall;
if (towa.TowageOnArrivalDraught_DMT.HasValue)
rootTowa.TowageOnArrival[i].TowageOnArrivalDraught_DMT = decimal.Round((decimal)towa.TowageOnArrivalDraught_DMT.Value, 1);
rootTowa.TowageOnArrival[i].TowageOnArrivalRemarks = towa.TowageOnArrivalRemarks;
}
// rootTowa.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootTowa;
}
break;
#endregion
#region TOWD
case Message.NotificationClass.TOWD:
{
RootTOWD rootTowd = new RootTOWD();
rootTowd.TowageOnDeparture = new RootTOWDTowageOnDeparture[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
TOWD towd = message.Elements[i] as TOWD;
rootTowd.TowageOnDeparture[i] = new RootTOWDTowageOnDeparture();
rootTowd.TowageOnDeparture[i].TowageOnDepartureName = towd.TowageOnDepartureName;
rootTowd.TowageOnDeparture[i].TowageOnDepartureFlag = towd.TowageOnDepartureFlag;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator = new RootTOWDTowageOnDepartureTowageOnDepartureOperator();
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorCompanyName = towd.TowageOnDepartureOperatorCompanyName;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorStreetAndNumber = towd.TowageOnDepartureOperatorStreetNameAndNumber;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorPostalCode = towd.TowageOnDepartureOperatorPostalCode;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorCity = towd.TowageOnDepartureOperatorCity;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorCountry = towd.TowageOnDepartureOperatorCountry;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorPhone = towd.TowageOnDepartureOperatorPhone;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorFax = towd.TowageOnDepartureOperatorFax;
rootTowd.TowageOnDeparture[i].TowageOnDepartureOperator.TowageOnDepartureOperatorEMail = towd.TowageOnDepartureOperatorEmail;
rootTowd.TowageOnDeparture[i].TowageOnDepartureLengthOverall_MTRSpecified = towd.TowageOnDepartureLengthOverall_MTR.HasValue;
if (towd.TowageOnDepartureLengthOverall_MTR.HasValue)
rootTowd.TowageOnDeparture[i].TowageOnDepartureLengthOverall_MTR = decimal.Round((decimal)towd.TowageOnDepartureLengthOverall_MTR.Value, 2);
rootTowd.TowageOnDeparture[i].TowageOnDepartureBeam_MTRSpecified = towd.TowageOnDepartureBeam_MTR.HasValue;
if (towd.TowageOnDepartureBeam_MTR.HasValue)
rootTowd.TowageOnDeparture[i].TowageOnDepartureBeam_MTR = decimal.Round((decimal)towd.TowageOnDepartureBeam_MTR.Value, 2);
if (towd.TowageOnDepartureDraught_DMT.HasValue)
rootTowd.TowageOnDeparture[i].TowageOnDepartureDraught_DMT = decimal.Round((decimal)towd.TowageOnDepartureDraught_DMT.Value, 1);
rootTowd.TowageOnDeparture[i].TowageOnDepartureRemarks = towd.TowageOnDepartureRemarks;
}
// rootTowd.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootTowd;
}
break;
#endregion
#region HAZA
//Felderreihenfolge wegen einfacher Test/Impl. entspricht genau dem XLS Sheet
case Message.NotificationClass.HAZA:
{
RootHAZA rootHAZA = new RootHAZA();
HAZ haz = message.Elements[0] as HAZ;
if (haz.NoDPGOnBoardOnArrival ?? false)
{
rootHAZA.Items = new object[1];
rootHAZA.Items[0] = "Y";
rootHAZA.ItemsElementName = new ItemsChoiceType5[1];
rootHAZA.ItemsElementName[0] = ItemsChoiceType5.NoDPGOnBoardOnArrival;
}
else
{
rootHAZA.Items = new object[4];
rootHAZA.ItemsElementName = new ItemsChoiceType5[4];
// if(haz.DPGManifestOnBoardOnArrival.HasValue)
rootHAZA.ItemsElementName[0] = ItemsChoiceType5.DPGManifestOnBoardOnArrival;
rootHAZA.Items[0] = (haz.DPGManifestOnBoardOnArrival ?? false) ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
rootHAZA.ItemsElementName[1] = ItemsChoiceType5.INFShipClass;
if (haz.INFShipClass.HasValue)
{
INFClassType infShipClass = (INFClassType)haz.INFShipClass.Value;
rootHAZA.Items[1] = infShipClass;
}
rootHAZA.ItemsElementName[2] = ItemsChoiceType5.MOUBaltic;
rootHAZA.Items[2] = (haz.MOUBaltic ?? false) ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
#region HAZ positions
rootHAZA.ItemsElementName[3] = ItemsChoiceType5.DPGOnArrival;
RootHAZADPGOnArrival dpgOnArrival = new RootHAZADPGOnArrival();
#region IMDG
if (haz.IMDGPositions.Count > 0)
{
dpgOnArrival.DPGItemIMDG = new Request.IMDGPosition[haz.IMDGPositions.Count];
for (int i = 0; i < haz.IMDGPositions.Count; i++)
{
bsmd.database.IMDGPosition imdgPos = haz.IMDGPositions[i] as bsmd.database.IMDGPosition;
Request.IMDGPosition rootIMDG = new Request.IMDGPosition();
rootIMDG.UNNumber = imdgPos.UNNumber;
rootIMDG.PackingGroupSpecified = imdgPos.PackingGroup.HasValue;
if (imdgPos.PackingGroup.HasValue)
rootIMDG.PackingGroup = (Request.PackingGroupType)imdgPos.PackingGroup.Value;
rootIMDG.ProperShippingName = imdgPos.ProperShippingName;
rootIMDG.IMOClass = imdgPos.IMOClass;
// rootIMDG.CompatibilityGroup = imdgPos.CompatibilityGroup;
if(!imdgPos.TechnicalName.IsNullOrEmpty())
rootIMDG.TechnicalName = imdgPos.TechnicalName;
rootIMDG.NetExplosiveMass_KGMSpecified = imdgPos.NetExplosiveMass_KGM.HasValue;
if (imdgPos.NetExplosiveMass_KGM.HasValue)
rootIMDG.NetExplosiveMass_KGM = decimal.Round((decimal)imdgPos.NetExplosiveMass_KGM.Value, 3);
if(!imdgPos.Flashpoint_CEL.IsNullOrEmpty())
rootIMDG.Flashpoint_CEL = imdgPos.Flashpoint_CEL;
if(!imdgPos.Class7NuclideName.IsNullOrEmpty())
rootIMDG.Class7NuclideName = imdgPos.Class7NuclideName;
if (imdgPos.Class7MaxActivity_BQL.HasValue)
{
rootIMDG.Class7MaxActivity = new IMDGPositionClass7MaxActivity();
rootIMDG.Class7MaxActivity.MaxActivityValue = decimal.Round((decimal)imdgPos.Class7MaxActivity_BQL.Value, 3);
rootIMDG.Class7MaxActivity.MaxActivityUnit = ActivityUnitType.BQL;
}
rootIMDG.Class7CategorySpecified = imdgPos.Class7Category.HasValue;
if (imdgPos.Class7Category.HasValue)
rootIMDG.Class7Category = imdgPos.Class7Category.Value;
rootIMDG.Class7TransportIndexSpecified = imdgPos.Class7TransportIndex.HasValue;
if (imdgPos.Class7TransportIndex.HasValue)
rootIMDG.Class7TransportIndex = decimal.Round((decimal)imdgPos.Class7TransportIndex.Value, 1);
rootIMDG.Class7CSISpecified = imdgPos.Class7CSI.HasValue;
if (imdgPos.Class7CSI.HasValue)
rootIMDG.Class7CSI = imdgPos.Class7CSI.Value;
rootIMDG.ControlTemperature_CELSpecified = imdgPos.ControlTemperature_CEL.HasValue;
if (imdgPos.ControlTemperature_CEL.HasValue)
rootIMDG.ControlTemperature_CEL = decimal.Round((decimal)imdgPos.ControlTemperature_CEL.Value, 2);
rootIMDG.EmergencyTemperature_CELSpecified = imdgPos.EmergencyTemperature_CEL.HasValue;
if (imdgPos.EmergencyTemperature_CEL.HasValue)
rootIMDG.EmergencyTemperature_CEL = decimal.Round((decimal)imdgPos.EmergencyTemperature_CEL.Value, 2);
if (imdgPos.SubsidiaryRiskList.Count > 0)
{
rootIMDG.SubsidiaryRisks = new string[imdgPos.SubsidiaryRiskList.Count];
for (int sCount = 0; sCount < imdgPos.SubsidiaryRiskList.Count; sCount++)
rootIMDG.SubsidiaryRisks[sCount] = imdgPos.SubsidiaryRiskList[sCount].SubsidiaryRisk;
}
if (imdgPos.MarinePollutant.HasValue)
rootIMDG.MarinePollutant = imdgPos.MarinePollutant.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (imdgPos.NumberOfPackages.HasValue)
rootIMDG.NumberOfPackages = imdgPos.NumberOfPackages.Value;
rootIMDG.PackageType = imdgPos.PackageType;
if (imdgPos.LimitedQuantities.HasValue)
rootIMDG.LimitedQuantities = imdgPos.LimitedQuantities.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (imdgPos.ExceptedQuantities.HasValue)
rootIMDG.ExceptedQuantities = imdgPos.ExceptedQuantities.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
rootIMDG.NetQuantity_KGMSpecified = imdgPos.NetQuantity_KGM.HasValue;
if (imdgPos.NetQuantity_KGM.HasValue)
rootIMDG.NetQuantity_KGM = decimal.Round((decimal)imdgPos.NetQuantity_KGM.Value, 3);
rootIMDG.GrossQuantity_KGMSpecified = imdgPos.GrossQuantity_KGM.HasValue;
if (imdgPos.GrossQuantity_KGM.HasValue)
rootIMDG.GrossQuantity_KGM = decimal.Round((decimal)imdgPos.GrossQuantity_KGM.Value, 3);
rootIMDG.Volume_MTQSpecified = imdgPos.Volume_MTQ.HasValue;
if (imdgPos.Volume_MTQ.HasValue)
rootIMDG.Volume_MTQ = decimal.Round((decimal)imdgPos.Volume_MTQ.Value, 3);
rootIMDG.GeneralCargoIBCSpecified = imdgPos.GeneralCargoIBC.HasValue;
if (imdgPos.GeneralCargoIBC.HasValue)
rootIMDG.GeneralCargoIBC = imdgPos.GeneralCargoIBC.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (!imdgPos.ContainerNumber.IsNullOrEmpty())
rootIMDG.ContainerNumber = imdgPos.ContainerNumber;
if (!imdgPos.VehicleLicenseNumber.IsNullOrEmpty())
rootIMDG.VehicleLicenseNumber = imdgPos.VehicleLicenseNumber;
if (imdgPos.StowagePosition.IsNullOrEmpty())
{
rootIMDG.Items = new string[3];
rootIMDG.ItemsElementName = new ItemsChoiceType4[3];
rootIMDG.Items[0] = imdgPos.Bay;
rootIMDG.ItemsElementName[0] = ItemsChoiceType4.Bay;
rootIMDG.Items[1] = imdgPos.Row;
rootIMDG.ItemsElementName[1] = ItemsChoiceType4.Row;
rootIMDG.Items[2] = imdgPos.Tier;
rootIMDG.ItemsElementName[2] = ItemsChoiceType4.Tier;
}
else
{
rootIMDG.Items = new string[1] { imdgPos.StowagePosition };
rootIMDG.ItemsElementName = new ItemsChoiceType4[1] { ItemsChoiceType4.StowagePosition };
}
rootIMDG.PortOfLoading = imdgPos.PortOfLoading;
rootIMDG.PortOfDischarge = imdgPos.PortOfDischarge;
if (!imdgPos.Remarks.IsNullOrEmpty())
rootIMDG.Remarks = imdgPos.Remarks;
dpgOnArrival.DPGItemIMDG[i] = rootIMDG;
}
}
#endregion
#region IBC
if (haz.IBCPositions.Count > 0)
{
dpgOnArrival.DPGItemIBC = new bsmd.dbh.Request.IBCPosition[haz.IBCPositions.Count];
for (int i = 0; i < haz.IBCPositions.Count; i++)
{
bsmd.dbh.Request.IBCPosition rootIBC = new bsmd.dbh.Request.IBCPosition();
bsmd.database.IBCPosition ibcPos = haz.IBCPositions[i] as bsmd.database.IBCPosition;
rootIBC.ProductName = ibcPos.ProductName;
if (ibcPos.PollutionCategory.HasValue)
rootIBC.PollutionCategory = (PollutionCategoryType)ibcPos.PollutionCategory.Value;
rootIBC.HazardsSpecified = ibcPos.Hazards.HasValue;
if (ibcPos.Hazards.HasValue)
rootIBC.Hazards = (HazardType)ibcPos.Hazards.Value;
if (ibcPos.FlashpointInformation.HasValue)
rootIBC.FlashpointInformation = (FlashpointInfoType)ibcPos.FlashpointInformation.Value;
rootIBC.Flashpoint_CEL = ibcPos.Flashpoint_CEL;
if (ibcPos.Quantity_KGM.HasValue)
rootIBC.Quantity_KGM = decimal.Round((decimal)ibcPos.Quantity_KGM.Value, 3);
rootIBC.StowagePosition = ibcPos.StowagePosition;
rootIBC.PortOfLoading = ibcPos.PortOfLoading;
rootIBC.PortOfDischarge = ibcPos.PortOfDischarge;
rootIBC.SpecRef15_19Specified = ibcPos.SpecRef15_19.HasValue;
if (ibcPos.SpecRef15_19.HasValue)
rootIBC.SpecRef15_19 = ibcPos.SpecRef15_19.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (!ibcPos.Remarks.IsNullOrEmpty())
rootIBC.Remarks = ibcPos.Remarks;
dpgOnArrival.DPGItemIBC[i] = rootIBC;
}
}
#endregion
#region IGC
if (haz.IGCPositions.Count > 0)
{
dpgOnArrival.DPGItemIGC = new bsmd.dbh.Request.IGCPosition[haz.IGCPositions.Count];
for (int i = 0; i < haz.IGCPositions.Count; i++)
{
bsmd.dbh.Request.IGCPosition rootIGC = new bsmd.dbh.Request.IGCPosition();
bsmd.database.IGCPosition igcPos = haz.IGCPositions[i] as bsmd.database.IGCPosition;
rootIGC.UNNumber = igcPos.UNNumber;
rootIGC.IMOClass = igcPos.IMOClass;
rootIGC.ProductName = igcPos.ProductName;
if (igcPos.Quantity_KGM.HasValue)
rootIGC.Quantity_KGM = decimal.Round((decimal)igcPos.Quantity_KGM.Value, 3);
rootIGC.StowagePosition = igcPos.StowagePosition;
rootIGC.PortOfLoading = igcPos.PortOfLoading;
rootIGC.PortOfDischarge = igcPos.PortOfDischarge;
if (!igcPos.Remarks.IsNullOrEmpty())
rootIGC.Remarks = igcPos.Remarks;
dpgOnArrival.DPGItemIGC[i] = rootIGC;
}
}
#endregion
#region IMSBC
if (haz.IMSBCPositions.Count > 0)
{
dpgOnArrival.DPGItemIMSBC = new bsmd.dbh.Request.IMSBCPosition[haz.IMSBCPositions.Count];
for (int i = 0; i < haz.IMSBCPositions.Count; i++)
{
bsmd.dbh.Request.IMSBCPosition rootIMSBC = new bsmd.dbh.Request.IMSBCPosition();
bsmd.database.IMSBCPosition imsbcPos = haz.IMSBCPositions[i] as bsmd.database.IMSBCPosition;
rootIMSBC.BulkCargoShippingName = imsbcPos.BulkCargoShippingName;
if (imsbcPos.MHB.HasValue)
rootIMSBC.MHB = imsbcPos.MHB.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
rootIMSBC.UNNumber = imsbcPos.UNNumber;
rootIMSBC.IMOClass = imsbcPos.IMOClass;
if (imsbcPos.Quantity_KGM.HasValue)
rootIMSBC.Quantity_KGM = decimal.Round((decimal)imsbcPos.Quantity_KGM.Value, 3);
rootIMSBC.StowagePosition = imsbcPos.StowagePosition;
rootIMSBC.PortOfLoading = imsbcPos.PortOfLoading;
rootIMSBC.PortOfDischarge = imsbcPos.PortOfDischarge;
if (!imsbcPos.Remarks.IsNullOrEmpty())
rootIMSBC.Remarks = imsbcPos.Remarks;
rootIMSBC.IMOHazardClassSpecified = imsbcPos.IMOHazardClass.HasValue;
if (imsbcPos.IMOHazardClass.HasValue)
rootIMSBC.IMOHazardClass = (IMOHazardClassType)imsbcPos.IMOHazardClass.Value
;
dpgOnArrival.DPGItemIMSBC[i] = rootIMSBC;
}
}
#endregion
#region MARPOL_ANNEX_I
if (haz.MARPOLPositions.Count > 0)
{
dpgOnArrival.DPGItemMARPOLAnnexI = new MARPOLPosition[haz.MARPOLPositions.Count];
for (int i = 0; i < haz.MARPOLPositions.Count; i++)
{
MARPOLPosition rootMarpol = new MARPOLPosition();
MARPOL_Annex_I_Position marpolPos = haz.MARPOLPositions[i];
rootMarpol.Name = marpolPos.Name;
if (marpolPos.FlashpointInformation.HasValue)
rootMarpol.FlashpointInformation = (FlashpointInfoType)marpolPos.FlashpointInformation.Value;
rootMarpol.Flashpoint_CEL = marpolPos.Flashpoint_CEL;
if (marpolPos.Quantity_KGM.HasValue)
rootMarpol.Quantity_KGM = decimal.Round((decimal)marpolPos.Quantity_KGM.Value, 3);
rootMarpol.StowagePosition = marpolPos.StowagePosition;
rootMarpol.PortOfLoading = marpolPos.PortOfLoading;
rootMarpol.PortOfDischarge = marpolPos.PortOfDischarge;
if (!marpolPos.Remarks.IsNullOrEmpty())
rootMarpol.Remarks = marpolPos.Remarks;
dpgOnArrival.DPGItemMARPOLAnnexI[i] = rootMarpol;
}
}
#endregion
rootHAZA.Items[3] = dpgOnArrival;
#endregion
}
// rootHAZA.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootHAZA;
}
break;
#endregion
#region HAZD
//Felderreihenfolge wegen einfacher Test/Impl. entspricht genau dem XLS Sheet
case Message.NotificationClass.HAZD:
{
RootHAZD rootHAZD = new RootHAZD();
HAZ haz = message.Elements[0] as HAZ;
if (haz.NoDPGOnBoardOnArrival ?? false)
{
rootHAZD.ItemsElementName = new ItemsChoiceType6[1];
rootHAZD.ItemsElementName[0] = ItemsChoiceType6.NoDPGOnBoardOnDeparture;
rootHAZD.Items = new object[1];
rootHAZD.Items[0] = "Y";
}
else
{
rootHAZD.Items = new object[4];
rootHAZD.ItemsElementName = new ItemsChoiceType6[4];
rootHAZD.ItemsElementName[0] = ItemsChoiceType6.DPGManifestOnBoardOnDeparture;
if (haz.DPGManifestOnBoardOnArrival.HasValue)
rootHAZD.Items[0] = haz.DPGManifestOnBoardOnArrival.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
rootHAZD.ItemsElementName[1] = ItemsChoiceType6.INFShipClass;
if (haz.INFShipClass.HasValue)
{
INFClassType infShipClass = (INFClassType)haz.INFShipClass.Value;
rootHAZD.Items[1] = infShipClass;
}
rootHAZD.ItemsElementName[2] = ItemsChoiceType6.MOUBaltic;
rootHAZD.Items[2] = (haz.MOUBaltic ?? false) ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
#region HAZ positions
RootHAZDDPGOnDeparture dpgOnDeparture = new RootHAZDDPGOnDeparture();
#region IMDG
if (haz.IMDGPositions.Count > 0)
{
dpgOnDeparture.DPGItemIMDG = new bsmd.dbh.Request.IMDGPosition[haz.IMDGPositions.Count];
for (int i = 0; i < haz.IMDGPositions.Count; i++)
{
bsmd.database.IMDGPosition imdgPos = haz.IMDGPositions[i] as bsmd.database.IMDGPosition;
bsmd.dbh.Request.IMDGPosition rootIMDG = new bsmd.dbh.Request.IMDGPosition();
rootIMDG.UNNumber = imdgPos.UNNumber;
rootIMDG.PackingGroupSpecified = imdgPos.PackingGroup.HasValue;
if (imdgPos.PackingGroup.HasValue)
rootIMDG.PackingGroup = (PackingGroupType)imdgPos.PackingGroup.Value;
rootIMDG.ProperShippingName = imdgPos.ProperShippingName;
rootIMDG.IMOClass = imdgPos.IMOClass;
// rootIMDG.CompatibilityGroup = imdgPos.CompatibilityGroup;
rootIMDG.TechnicalName = imdgPos.TechnicalName;
rootIMDG.NetExplosiveMass_KGMSpecified = imdgPos.NetExplosiveMass_KGM.HasValue;
if (imdgPos.NetExplosiveMass_KGM.HasValue)
rootIMDG.NetExplosiveMass_KGM = decimal.Round((decimal)imdgPos.NetExplosiveMass_KGM.Value, 3);
rootIMDG.Flashpoint_CEL = imdgPos.Flashpoint_CEL;
rootIMDG.Class7NuclideName = imdgPos.Class7NuclideName;
if (imdgPos.Class7MaxActivity_BQL.HasValue)
{
rootIMDG.Class7MaxActivity = new IMDGPositionClass7MaxActivity();
rootIMDG.Class7MaxActivity.MaxActivityValue = decimal.Round((decimal)imdgPos.Class7MaxActivity_BQL.Value, 6);
rootIMDG.Class7MaxActivity.MaxActivityUnit = ActivityUnitType.BQL;
}
rootIMDG.Class7CategorySpecified = imdgPos.Class7Category.HasValue;
if (imdgPos.Class7Category.HasValue)
rootIMDG.Class7Category = imdgPos.Class7Category.Value;
rootIMDG.Class7TransportIndexSpecified = imdgPos.Class7TransportIndex.HasValue;
if (imdgPos.Class7TransportIndex.HasValue)
rootIMDG.Class7TransportIndex = decimal.Round((decimal)imdgPos.Class7TransportIndex.Value, 1);
rootIMDG.Class7CSISpecified = imdgPos.Class7CSI.HasValue;
if (imdgPos.Class7CSI.HasValue)
rootIMDG.Class7CSI = imdgPos.Class7CSI.Value;
rootIMDG.ControlTemperature_CELSpecified = imdgPos.ControlTemperature_CEL.HasValue;
if (imdgPos.ControlTemperature_CEL.HasValue)
rootIMDG.ControlTemperature_CEL = decimal.Round((decimal)imdgPos.ControlTemperature_CEL.Value, 2);
rootIMDG.EmergencyTemperature_CELSpecified = imdgPos.EmergencyTemperature_CEL.HasValue;
if (imdgPos.EmergencyTemperature_CEL.HasValue)
rootIMDG.EmergencyTemperature_CEL = decimal.Round((decimal)imdgPos.EmergencyTemperature_CEL.Value, 2);
if (imdgPos.SubsidiaryRiskList.Count > 0)
{
rootIMDG.SubsidiaryRisks = new string[imdgPos.SubsidiaryRiskList.Count];
for (int sCount = 0; sCount < imdgPos.SubsidiaryRiskList.Count; sCount++)
rootIMDG.SubsidiaryRisks[sCount] = imdgPos.SubsidiaryRiskList[sCount].SubsidiaryRisk;
}
if (imdgPos.MarinePollutant.HasValue)
rootIMDG.MarinePollutant = imdgPos.MarinePollutant.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (imdgPos.NumberOfPackages.HasValue)
rootIMDG.NumberOfPackages = imdgPos.NumberOfPackages.Value;
rootIMDG.PackageType = imdgPos.PackageType;
if (imdgPos.LimitedQuantities.HasValue)
rootIMDG.LimitedQuantities = imdgPos.LimitedQuantities.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (imdgPos.ExceptedQuantities.HasValue)
rootIMDG.ExceptedQuantities = imdgPos.ExceptedQuantities.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
rootIMDG.NetQuantity_KGMSpecified = imdgPos.NetQuantity_KGM.HasValue;
if (imdgPos.NetQuantity_KGM.HasValue)
rootIMDG.NetQuantity_KGM = decimal.Round((decimal)imdgPos.NetQuantity_KGM.Value, 3);
rootIMDG.GrossQuantity_KGMSpecified = imdgPos.GrossQuantity_KGM.HasValue;
if (imdgPos.GrossQuantity_KGM.HasValue)
rootIMDG.GrossQuantity_KGM = decimal.Round((decimal)imdgPos.GrossQuantity_KGM.Value, 3);
rootIMDG.Volume_MTQSpecified = imdgPos.Volume_MTQ.HasValue;
if (imdgPos.Volume_MTQ.HasValue)
rootIMDG.Volume_MTQ = decimal.Round((decimal)imdgPos.Volume_MTQ.Value, 3);
rootIMDG.GeneralCargoIBCSpecified = imdgPos.GeneralCargoIBC.HasValue;
if (imdgPos.GeneralCargoIBC.HasValue)
rootIMDG.GeneralCargoIBC = imdgPos.GeneralCargoIBC.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (!imdgPos.ContainerNumber.IsNullOrEmpty())
rootIMDG.ContainerNumber = imdgPos.ContainerNumber;
if (!imdgPos.VehicleLicenseNumber.IsNullOrEmpty())
rootIMDG.VehicleLicenseNumber = imdgPos.VehicleLicenseNumber;
if (imdgPos.StowagePosition.IsNullOrEmpty())
{
rootIMDG.Items = new string[3];
rootIMDG.ItemsElementName = new ItemsChoiceType4[3];
rootIMDG.Items[0] = imdgPos.Bay;
rootIMDG.ItemsElementName[0] = ItemsChoiceType4.Bay;
rootIMDG.Items[1] = imdgPos.Row;
rootIMDG.ItemsElementName[1] = ItemsChoiceType4.Row;
rootIMDG.Items[2] = imdgPos.Tier;
rootIMDG.ItemsElementName[2] = ItemsChoiceType4.Tier;
}
else
{
rootIMDG.Items = new string[1] { imdgPos.StowagePosition };
rootIMDG.ItemsElementName = new ItemsChoiceType4[1] { ItemsChoiceType4.StowagePosition };
}
rootIMDG.PortOfLoading = imdgPos.PortOfLoading;
rootIMDG.PortOfDischarge = imdgPos.PortOfDischarge;
if (!imdgPos.Remarks.IsNullOrEmpty())
rootIMDG.Remarks = imdgPos.Remarks;
dpgOnDeparture.DPGItemIMDG[i] = rootIMDG;
}
}
#endregion
#region IBC
if (haz.IBCPositions.Count > 0)
{
dpgOnDeparture.DPGItemIBC = new bsmd.dbh.Request.IBCPosition[haz.IBCPositions.Count];
for (int i = 0; i < haz.IBCPositions.Count; i++)
{
bsmd.dbh.Request.IBCPosition rootIBC = new bsmd.dbh.Request.IBCPosition();
bsmd.database.IBCPosition ibcPos = haz.IBCPositions[i] as bsmd.database.IBCPosition;
rootIBC.ProductName = ibcPos.ProductName;
if (ibcPos.PollutionCategory.HasValue)
rootIBC.PollutionCategory = (PollutionCategoryType)ibcPos.PollutionCategory.Value;
rootIBC.HazardsSpecified = ibcPos.Hazards.HasValue;
if (ibcPos.Hazards.HasValue)
rootIBC.Hazards = (HazardType)ibcPos.Hazards.Value;
if (ibcPos.FlashpointInformation.HasValue)
rootIBC.FlashpointInformation = (FlashpointInfoType)ibcPos.FlashpointInformation.Value;
rootIBC.Flashpoint_CEL = ibcPos.Flashpoint_CEL;
if (ibcPos.Quantity_KGM.HasValue)
rootIBC.Quantity_KGM = decimal.Round((decimal)ibcPos.Quantity_KGM.Value, 3);
rootIBC.StowagePosition = ibcPos.StowagePosition;
rootIBC.PortOfLoading = ibcPos.PortOfLoading;
rootIBC.PortOfDischarge = ibcPos.PortOfDischarge;
rootIBC.SpecRef15_19Specified = ibcPos.SpecRef15_19.HasValue;
if (ibcPos.SpecRef15_19.HasValue)
rootIBC.SpecRef15_19 = ibcPos.SpecRef15_19.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
if (!ibcPos.Remarks.IsNullOrEmpty())
rootIBC.Remarks = ibcPos.Remarks;
dpgOnDeparture.DPGItemIBC[i] = rootIBC;
}
}
#endregion
#region IGC
if (haz.IGCPositions.Count > 0)
{
dpgOnDeparture.DPGItemIGC = new bsmd.dbh.Request.IGCPosition[haz.IGCPositions.Count];
for (int i = 0; i < haz.IGCPositions.Count; i++)
{
bsmd.dbh.Request.IGCPosition rootIGC = new bsmd.dbh.Request.IGCPosition();
bsmd.database.IGCPosition igcPos = haz.IGCPositions[i] as bsmd.database.IGCPosition;
rootIGC.UNNumber = igcPos.UNNumber;
rootIGC.IMOClass = igcPos.IMOClass;
rootIGC.ProductName = igcPos.ProductName;
if (igcPos.Quantity_KGM.HasValue)
rootIGC.Quantity_KGM = decimal.Round((decimal)igcPos.Quantity_KGM.Value, 3);
rootIGC.StowagePosition = igcPos.StowagePosition;
rootIGC.PortOfLoading = igcPos.PortOfLoading;
rootIGC.PortOfDischarge = igcPos.PortOfDischarge;
if (!igcPos.Remarks.IsNullOrEmpty())
rootIGC.Remarks = igcPos.Remarks;
dpgOnDeparture.DPGItemIGC[i] = rootIGC;
}
}
#endregion
#region IMSBC
if (haz.IMSBCPositions.Count > 0)
{
dpgOnDeparture.DPGItemIMSBC = new bsmd.dbh.Request.IMSBCPosition[haz.IMSBCPositions.Count];
for (int i = 0; i < haz.IMSBCPositions.Count; i++)
{
bsmd.dbh.Request.IMSBCPosition rootIMSBC = new bsmd.dbh.Request.IMSBCPosition();
bsmd.database.IMSBCPosition imsbcPos = haz.IMSBCPositions[i] as bsmd.database.IMSBCPosition;
rootIMSBC.BulkCargoShippingName = imsbcPos.BulkCargoShippingName;
if (imsbcPos.MHB.HasValue)
rootIMSBC.MHB = imsbcPos.MHB.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N;
rootIMSBC.UNNumber = imsbcPos.UNNumber;
rootIMSBC.IMOClass = imsbcPos.IMOClass;
if (imsbcPos.Quantity_KGM.HasValue)
rootIMSBC.Quantity_KGM = decimal.Round((decimal)imsbcPos.Quantity_KGM.Value, 3);
rootIMSBC.StowagePosition = imsbcPos.StowagePosition;
rootIMSBC.PortOfLoading = imsbcPos.PortOfLoading;
rootIMSBC.PortOfDischarge = imsbcPos.PortOfDischarge;
if (!imsbcPos.Remarks.IsNullOrEmpty())
rootIMSBC.Remarks = imsbcPos.Remarks;
rootIMSBC.IMOHazardClassSpecified = imsbcPos.IMOHazardClass.HasValue;
if (imsbcPos.IMOHazardClass.HasValue)
rootIMSBC.IMOHazardClass = (IMOHazardClassType)imsbcPos.IMOHazardClass.Value;
dpgOnDeparture.DPGItemIMSBC[i] = rootIMSBC;
}
}
#endregion
#region MARPOL_ANNEX_I
if (haz.MARPOLPositions.Count > 0)
{
dpgOnDeparture.DPGItemMARPOLAnnexI = new MARPOLPosition[haz.MARPOLPositions.Count];
for (int i = 0; i < haz.MARPOLPositions.Count; i++)
{
MARPOLPosition rootMarpol = new MARPOLPosition();
MARPOL_Annex_I_Position marpolPos = haz.MARPOLPositions[i];
rootMarpol.Name = marpolPos.Name;
if (marpolPos.FlashpointInformation.HasValue)
rootMarpol.FlashpointInformation = (FlashpointInfoType)marpolPos.FlashpointInformation.Value;
rootMarpol.Flashpoint_CEL = marpolPos.Flashpoint_CEL;
if (marpolPos.Quantity_KGM.HasValue)
rootMarpol.Quantity_KGM = decimal.Round((decimal)marpolPos.Quantity_KGM.Value, 3);
rootMarpol.StowagePosition = marpolPos.StowagePosition;
rootMarpol.PortOfLoading = marpolPos.PortOfLoading;
rootMarpol.PortOfDischarge = marpolPos.PortOfDischarge;
if (!marpolPos.Remarks.IsNullOrEmpty())
rootMarpol.Remarks = marpolPos.Remarks;
dpgOnDeparture.DPGItemMARPOLAnnexI[i] = rootMarpol;
}
}
#endregion
rootHAZD.ItemsElementName[3] = ItemsChoiceType6.DPGOnDeparture;
rootHAZD.Items[3] = dpgOnDeparture;
#endregion
}
// rootHAZD.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootHAZD;
}
break;
#endregion
#region WAS_RCPT
case Message.NotificationClass.WAS_RCPT:
{
RootWAS_RCPT rootWAS_RCPT = new RootWAS_RCPT();
rootWAS_RCPT.WasteDeliveryReceipt = new RootWAS_RCPTWasteDeliveryReceipt[message.Elements.Count];
for (int i = 0; i < message.Elements.Count; i++)
{
WAS_RCPT was_rcpt = message.Elements[i] as WAS_RCPT;
RootWAS_RCPTWasteDeliveryReceipt rwr = new RootWAS_RCPTWasteDeliveryReceipt();
rwr.IdentificationNumber = was_rcpt.IdentificationNumber;
rwr.PortReceptionFacilityName = was_rcpt.PortReceptionFacilityName;
rwr.PortReceptionFacilityProviderName = was_rcpt.PortReceptionFacilityProviderName;
if (was_rcpt.TreatmentFacilityProvider.Count > 0)
{
rwr.TreatmentFacilityProvider = new string[was_rcpt.TreatmentFacilityProvider.Count];
for (int j = 0; j < was_rcpt.TreatmentFacilityProvider.Count; j++)
{
rwr.TreatmentFacilityProvider[j] = was_rcpt.TreatmentFacilityProvider[j].TreatmentFacilityProviderName;
}
}
if (was_rcpt.WasteDeliveryDateFrom.HasValue)
rwr.WasteDeliveryDateFrom = was_rcpt.WasteDeliveryDateFrom.Value.ToUTCSerializableDateTime();
if (was_rcpt.WasteDeliveryDateTo.HasValue)
rwr.WasteDeliveryDateTo = was_rcpt.WasteDeliveryDateTo.Value.ToUTCSerializableDateTime();
rwr.WasteReceived = new RootWAS_RCPTWasteDeliveryReceiptWasteReceived[was_rcpt.WasteReceived.Count];
for (int j = 0; j < was_rcpt.WasteReceived.Count; j++)
{
rwr.WasteReceived[j] = new RootWAS_RCPTWasteDeliveryReceiptWasteReceived();
rwr.WasteReceived[j].AmountWasteReceived_MTQ = decimal.Round((decimal)was_rcpt.WasteReceived[j].AmountWasteReceived_MTQ.Value, 3);
rwr.WasteReceived[j].WasteType = new RootWAS_RCPTWasteDeliveryReceiptWasteReceivedWasteType();
rwr.WasteReceived[j].WasteType.WasteCode = was_rcpt.WasteReceived[j].WasteCode;
rwr.WasteReceived[j].WasteType.WasteDescription = was_rcpt.WasteReceived[j].WasteDescription;
}
rootWAS_RCPT.WasteDeliveryReceipt[i] = rwr;
}
// rootWAS_RCPT.ReportingParty = rp;
root.Items = new object[1];
root.Items[0] = rootWAS_RCPT;
}
break;
#endregion
default:
_log.WarnFormat("Message type {0} not (yet) supported for dbh", message.MessageNotificationClassDisplay);
break;
}
}
// serialize output structure to file
string filename = string.Format("NSW.DBH.{0}.{1}.xml", filenameComponent, message.FileSequenceNumber);
_log.InfoFormat("{0}: saving {1} to output directory", message.MessageNotificationClassDisplay, 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 filePath;
}
catch(Exception ex)
{
_log.Error(ex.ToString());
return null;
}
}
#region helper
private static Gender SetGender(byte genderVal)
{
switch (genderVal)
{
case 0:
return Gender.NOT_KNOWN;
case 1:
return Gender.MALE;
case 2:
return Gender.FEMALE;
case 9:
return Gender.NOT_APPLICABLE;
default:
return Gender.NOT_KNOWN;
}
}
#endregion
}
}