git_bsmd/nsw/Source/bsmd.dbh/Request.cs

105 lines
4.0 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 bsmd.database;
using bsmd.dbh.request;
namespace bsmd.dbh
{
public class Request
{
public static bool SendMessage(Message aMessage)
{
if (aMessage == null) return false;
// map message to dbh NSWRequest object
Root root = new Root();
root.Version = "1.8";
root.ReportingParty = new RootReportingParty();
root.ReportingParty.RPCity = aMessage.ReportingParty.City;
root.ReportingParty.RPCountry = aMessage.ReportingParty.Country;
root.ReportingParty.RPEMail = aMessage.ReportingParty.EMail;
root.ReportingParty.RPFax = aMessage.ReportingParty.Fax;
root.ReportingParty.RPFirstName = aMessage.ReportingParty.FirstName;
root.ReportingParty.RPLastName = aMessage.ReportingParty.LastName;
root.ReportingParty.RPName = aMessage.ReportingParty.Name;
root.ReportingParty.RPPhone = aMessage.ReportingParty.Phone;
root.ReportingParty.RPPostalCode = aMessage.ReportingParty.PostalCode;
root.ReportingParty.RPStreetAndNumber = aMessage.ReportingParty.StreetAndNumber;
root.ReportingParty.RPTypeSpecified = aMessage.ReportingParty.ReportingPartyType.HasValue;
if (root.ReportingParty.RPTypeSpecified)
root.ReportingParty.RPType = (RootReportingPartyRPType) aMessage.ReportingParty.ReportingPartyType.Value;
root.Timestamp = DateTime.Now;
switch(aMessage.MessageNotificationClass)
{
case Message.NotificationClass.VISIT:
{
root.Type = RootType.VISIT;
root.Item = new RootVisit();
if (aMessage.MessageCore.IMO != null)
{
((RootVisit)root.Item).ItemElementName = ItemChoiceType.IMONumber;
((RootVisit)root.Item).Item = aMessage.MessageCore.IMO;
}
else
{
((RootVisit)root.Item).ItemElementName = ItemChoiceType.ENINumber;
((RootVisit)root.Item).Item = aMessage.MessageCore.ENI;
}
((RootVisit)root.Item).PortOfCall = aMessage.MessageCore.PoC;
((RootVisit)root.Item).ETAPortOfCall = aMessage.MessageCore.ETA.Value;
break;
}
case Message.NotificationClass.TRANSIT:
root.Type = RootType.TRANSIT;
root.Item = new RootTransit();
if (aMessage.MessageCore.IMO != null)
{
((RootTransit)root.Item).ItemElementName = ItemChoiceType1.IMONumber;
((RootTransit)root.Item).Item = aMessage.MessageCore.IMO;
}
else
{
((RootTransit)root.Item).ItemElementName = ItemChoiceType1.ENINumber;
((RootTransit)root.Item).Item = aMessage.MessageCore.ENI;
}
((RootTransit)root.Item).ETAKielCanal = aMessage.MessageCore.ETA.Value;
break;
case Message.NotificationClass.STAT:
break;
default:
throw new NotImplementedException("sending message type not implemented yet!");
}
// send object
return false;
}
}
}