250 lines
10 KiB
C#
250 lines
10 KiB
C#
//
|
|
// Class: Util
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 3/1/2015 8:05:05 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using bsmd.database;
|
|
//using bsmd.dbh.request;
|
|
using bsmd.dbh.DBHWebReference;
|
|
|
|
namespace bsmd.dbh
|
|
{
|
|
public class Request
|
|
{
|
|
private static ILog _log = LogManager.GetLogger(typeof(Request));
|
|
|
|
public static bool SendMessage(DatabaseEntity dbEntity)
|
|
{
|
|
if (dbEntity == null) return false;
|
|
|
|
Message aMessage = null;
|
|
|
|
|
|
if (dbEntity.GetType().IsAssignableFrom(typeof(Message)))
|
|
{
|
|
aMessage = (Message)dbEntity;
|
|
}
|
|
else
|
|
{
|
|
IMessageClass msgClass = (IMessageClass)dbEntity;
|
|
aMessage = msgClass.MessageHeader;
|
|
}
|
|
|
|
// map message to dbh NSWRequest object
|
|
Dbh_Osis_Answ_Ws client = new Dbh_Osis_Answ_Ws();
|
|
|
|
RootReportingParty rp = new RootReportingParty();
|
|
rp.RPCity = aMessage.ReportingParty.City;
|
|
rp.RPCountry = aMessage.ReportingParty.Country;
|
|
rp.RPEMail = aMessage.ReportingParty.EMail;
|
|
rp.RPFax = aMessage.ReportingParty.Fax;
|
|
rp.RPFirstName = aMessage.ReportingParty.FirstName;
|
|
rp.RPLastName = aMessage.ReportingParty.LastName;
|
|
rp.RPName = aMessage.ReportingParty.Name;
|
|
rp.RPPhone = aMessage.ReportingParty.Phone;
|
|
rp.RPPostalCode = aMessage.ReportingParty.PostalCode;
|
|
rp.RPStreetAndNumber = aMessage.ReportingParty.StreetAndNumber;
|
|
rp.RPTypeSpecified = aMessage.ReportingParty.ReportingPartyType.HasValue;
|
|
if (rp.RPTypeSpecified)
|
|
rp.RPType = (RootReportingPartyRPType)aMessage.ReportingParty.ReportingPartyType.Value;
|
|
|
|
DateTime timestamp = DateTime.Now;
|
|
string version = "1.9";
|
|
object item = null;
|
|
string senderReference = Guid.NewGuid().ToString(); // TODO
|
|
RootType rootType = RootType.DATA;
|
|
ItemChoiceType2 itemChoiceType2 = ItemChoiceType2.Visit; // ?
|
|
|
|
switch (aMessage.MessageNotificationClass)
|
|
{
|
|
|
|
#region VISIT
|
|
case Message.NotificationClass.VISIT:
|
|
{
|
|
RootVisit rootVisit = new RootVisit();
|
|
rootType = RootType.VISIT;
|
|
|
|
if (aMessage.MessageCore.IMO != null)
|
|
{
|
|
rootVisit.ItemElementName = ItemChoiceType.IMONumber;
|
|
rootVisit.Item = aMessage.MessageCore.IMO;
|
|
}
|
|
else
|
|
{
|
|
rootVisit.ItemElementName = ItemChoiceType.ENINumber;
|
|
rootVisit.Item = aMessage.MessageCore.ENI;
|
|
}
|
|
|
|
rootVisit.PortOfCall = aMessage.MessageCore.PoC;
|
|
rootVisit.ETAPortOfCall = aMessage.MessageCore.ETA.Value;
|
|
item = rootVisit;
|
|
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
#region TRANSIT
|
|
case Message.NotificationClass.TRANSIT:
|
|
{
|
|
RootTransit rootTransit = new RootTransit();
|
|
rootType = RootType.TRANSIT;
|
|
|
|
if (aMessage.MessageCore.IMO != null)
|
|
{
|
|
rootTransit.ItemElementName = ItemChoiceType1.IMONumber;
|
|
rootTransit.Item = aMessage.MessageCore.IMO;
|
|
}
|
|
else
|
|
{
|
|
rootTransit.ItemElementName = ItemChoiceType1.ENINumber;
|
|
rootTransit.Item = aMessage.MessageCore.ENI;
|
|
}
|
|
|
|
rootTransit.ETAKielCanal = aMessage.MessageCore.ETA.Value;
|
|
item = rootTransit;
|
|
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
#region NOA_NOD
|
|
case Message.NotificationClass.NOA_NOD:
|
|
{
|
|
NOA_NOD noa_nod = dbEntity as NOA_NOD;
|
|
if (noa_nod != null)
|
|
{
|
|
RootNOA_NOD rootNoaNod = new RootNOA_NOD();
|
|
rootType = RootType.DATA;
|
|
if (noa_nod.ETAToNextPort.HasValue)
|
|
rootNoaNod.ETAToNextPort = noa_nod.ETAToNextPort.Value;
|
|
rootNoaNod.ETAToNextPortSpecified = noa_nod.ETAToNextPort.HasValue;
|
|
|
|
if (noa_nod.ETDFromLastPort.HasValue)
|
|
rootNoaNod.ETDFromLastPort = noa_nod.ETDFromLastPort.Value;
|
|
rootNoaNod.ETDFromLastPortSpecified = noa_nod.ETDFromLastPort.HasValue;
|
|
|
|
rootNoaNod.LastPort = noa_nod.LastPort;
|
|
rootNoaNod.NextPort = noa_nod.NextPort;
|
|
|
|
ItemsChoiceType[] choiceArray = new ItemsChoiceType[3];
|
|
object[] choices = new object[3];
|
|
|
|
choiceArray[0] = ItemsChoiceType.CallPurpose;
|
|
RootNOA_NODCallPurpose rnncp = new RootNOA_NODCallPurpose();
|
|
if (noa_nod.CallPurposeCode.HasValue)
|
|
rnncp.CallPurposeCode = noa_nod.CallPurposeCode.Value;
|
|
rnncp.CallPurposeDescription = noa_nod.CallPurposeDescription;
|
|
choices[0] = rnncp;
|
|
|
|
if (noa_nod.ETAToKielCanal.HasValue)
|
|
{
|
|
choiceArray[1] = ItemsChoiceType.ETAToKielCanal;
|
|
choices[1] = noa_nod.ETAToKielCanal.Value;
|
|
}
|
|
if (noa_nod.ETAToPortOfCall.HasValue)
|
|
{
|
|
choiceArray[1] = ItemsChoiceType.ETAToPortOfCall;
|
|
choices[1] = noa_nod.ETAToPortOfCall.Value;
|
|
}
|
|
if (noa_nod.ETDFromKielCanal.HasValue)
|
|
{
|
|
choiceArray[2] = ItemsChoiceType.ETDFromKielCanal;
|
|
choices[2] = noa_nod.ETDFromKielCanal.Value;
|
|
}
|
|
if (noa_nod.ETDFromPortOfCall.HasValue)
|
|
{
|
|
choiceArray[2] = ItemsChoiceType.ETDFromPortOfCall;
|
|
choices[2] = noa_nod.ETDFromPortOfCall.Value;
|
|
}
|
|
|
|
item = rootNoaNod;
|
|
}
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
#region ATA
|
|
case Message.NotificationClass.ATA:
|
|
{
|
|
ATA ata = dbEntity as ATA;
|
|
if (ata != null)
|
|
{
|
|
RootATA rootATA = new RootATA();
|
|
rootType = RootType.DATA;
|
|
rootATA.ATAPortOfCall = ata.ATAPortOfCall.Value;
|
|
item = rootATA;
|
|
}
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
#region ATD
|
|
case Message.NotificationClass.ATD:
|
|
{
|
|
ATD atd = dbEntity as ATD;
|
|
if (atd != null)
|
|
{
|
|
RootATD rootATD = new RootATD();
|
|
rootType = RootType.DATA;
|
|
rootATD.ATDPortOfCall = atd.ATDPortOfCall.Value;
|
|
item = rootATD;
|
|
}
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
#region BPOL
|
|
case Message.NotificationClass.BPOL:
|
|
{
|
|
BPOL bpol = dbEntity as BPOL;
|
|
if (bpol != null)
|
|
{
|
|
RootBPOL rootBPOL = new RootBPOL();
|
|
rootType = RootType.DATA;
|
|
|
|
RootBPOLPortOfItinerary[] poiArray = new RootBPOLPortOfItinerary[bpol.PortOfItineraries.Count];
|
|
rootBPOL.PortOfItinerary = poiArray;
|
|
|
|
for (int i = 0; i < bpol.PortOfItineraries.Count; i++)
|
|
{
|
|
RootBPOLPortOfItinerary port = new RootBPOLPortOfItinerary();
|
|
if (bpol.PortOfItineraries[i].PortOfItineraryETA.HasValue)
|
|
port.PortOfItineraryETA = bpol.PortOfItineraries[i].PortOfItineraryETA.Value;
|
|
port.PortOfItineraryName = bpol.PortOfItineraries[i].PortOfItineraryName;
|
|
poiArray[i] = port;
|
|
}
|
|
|
|
if (bpol.StowawaysOnBoard.HasValue)
|
|
rootBPOL.StowawayOnBoard = bpol.StowawaysOnBoard.Value ?
|
|
RootBPOLStowawayOnBoard.Y : RootBPOLStowawayOnBoard.N;
|
|
|
|
item = rootBPOL;
|
|
}
|
|
break;
|
|
}
|
|
#endregion
|
|
|
|
default:
|
|
{
|
|
_log.ErrorFormat("DBH send message: message type {0} not implemented", aMessage.MessageNotificationClass);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// send object
|
|
string result = client.Root(version, timestamp, Properties.Settings.Default.Sender, senderReference, rootType,
|
|
item, itemChoiceType2, null, rp, null, null);
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|