//
// 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-present Informatikbüro Daniel Schick. All rights reserved.
using System;
using System.Collections.Generic;
using log4net;
using bsmd.database;
using bsmd.dbh.DBHWebReference;
namespace bsmd.dbh
{
///
/// This class implements the "oldschool" approach of sending classes via the SOAP interface.
/// It has been superseded by a file-based approach that transmits classes via SFTP.
///
[Obsolete]
public class Request
{
private static readonly ILog _log = LogManager.GetLogger(typeof(Request));
public static bool SendCancelCore(MessageCore core)
{
if ((core == null) || !(core.Cancelled ?? false)) return false;
if (!core.DefaultReportingPartyId.HasValue ||
!DBManager.Instance.GetReportingPartyDict().ContainsKey(core.DefaultReportingPartyId.Value))
{
_log.ErrorFormat("Default reporting party not set / found on core {0}, aborting CANCEL", core.Id);
return false;
}
const RootType rootType = RootType.CANCEL;
Dbh_Osis_Answ_Ws client = new Dbh_Osis_Answ_Ws();
//if (useTest)
// client.Url = "https://edi-gate.dbh.de/test/bsmd-soap";
bsmd.database.ReportingParty reportingParty = DBManager.Instance.GetReportingPartyDict()[core.DefaultReportingPartyId.Value];
DBHWebReference.ReportingParty rp = new DBHWebReference.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;
try
{
object[] items = new object[1];
DateTime timestamp = DateTime.Now;
const string version = "3.0";
object item = null;
string senderReference = core.Id.Value.ToString("N");
items[0] = item;
ItemChoiceType2 itemChoiceType2;
if (core.IsTransit)
{
item = core.TransitId;
itemChoiceType2 = DBHWebReference.ItemChoiceType2.TransitId;
}
else
{
item = core.VisitId;
itemChoiceType2 = DBHWebReference.ItemChoiceType2.VisitId;
}
_log.InfoFormat("Send Url: {0}", client.Url);
const RootVersion rootVersion = RootVersion.Item60;
string result = client.Root(
rootVersion,
version,
timestamp,
Properties.Settings.Default.Sender, // BSMD sender Kennung (festverdrahtet)
senderReference,
(bsmd.dbh.DBHWebReference.RootType) rootType,
item,
itemChoiceType2,
null, // sisnumbers (weglassen)
rp,
items,
null // violations (weglassen)
);
}
catch (Exception ex)
{
_log.ErrorFormat("Exception on dbh message send: {0}", ex.Message);
if (ex.InnerException != null)
_log.ErrorFormat("Inner exception: {0}", ex.InnerException.Message);
return false;
}
finally
{
client.Dispose();
}
return true;
}
public static bool SendMessage(Message message)
{
if (message == null) return false;
RootType rootType = message.Reset ? RootType.RESET : RootType.DATA;
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;
}
// message.StatusInfo = ""; // zurücksetzen analog zu HIS-Nord (5.10.17)
// message.ChangedBy = "";
// map message to dbh NSWRequest object
Dbh_Osis_Answ_Ws client = new Dbh_Osis_Answ_Ws();
//if (useTest)
// client.Url = "https://edi-gate.dbh.de/test/bsmd-soap";
DBHWebReference.ReportingParty rp = new DBHWebReference.ReportingParty();
rp.RPCity = message.ReportingParty.City;
rp.RPCountry = message.ReportingParty.Country;
rp.RPEMail = message.ReportingParty.EMail;
rp.RPFax = message.ReportingParty.Fax;
rp.RPFirstName = message.ReportingParty.FirstName;
rp.RPLastName = message.ReportingParty.LastName;
rp.RPName = message.ReportingParty.Name;
rp.RPPhone = message.ReportingParty.Phone;
rp.RPPostalCode = message.ReportingParty.PostalCode;
rp.RPStreetAndNumber = message.ReportingParty.StreetAndNumber;
rp.RPTypeSpecified = message.ReportingParty.ReportingPartyType.HasValue;
if (rp.RPTypeSpecified)
rp.RPType = (ReportingPartyRPType) message.ReportingParty.ReportingPartyType.Value;
DateTime timestamp = DateTime.Now;
const string version = "3.0";
object item = null;
string senderReference = message.Id.Value.ToString("N");
ItemChoiceType2 itemChoiceType2 = ItemChoiceType2.Visit;
switch (message.MessageNotificationClass)
{
#region VISIT
case Message.NotificationClass.VISIT:
{
DBHWebReference.RootVisit rootVisit = new DBHWebReference.RootVisit();
rootType = RootType.VISIT;
if (!message.MessageCore.IMO.IsNullOrEmpty())
{
rootVisit.ItemElementName = DBHWebReference.ItemChoiceType.IMONumber;
rootVisit.Item = message.MessageCore.IMO;
}
else
{
rootVisit.ItemElementName = DBHWebReference.ItemChoiceType.ENINumber;
rootVisit.Item = message.MessageCore.ENI;
}
rootVisit.PortOfCall = message.MessageCore.PoC;
if (message.MessageCore.ETA.HasValue)
rootVisit.ETAPortOfCall = message.MessageCore.ETA.Value.ToDBHDateString();
else
rootVisit.ETAPortOfCall = null;
item = rootVisit;
break;
}
#endregion
#region TRANSIT
case Message.NotificationClass.TRANSIT:
{
DBHWebReference.RootTransit rootTransit = new DBHWebReference.RootTransit();
rootType = RootType.TRANSIT;
itemChoiceType2 = DBHWebReference.ItemChoiceType2.Transit;
if (!message.MessageCore.IMO.IsNullOrEmpty())
{
rootTransit.ItemElementName = DBHWebReference.ItemChoiceType1.IMONumber;
rootTransit.Item = message.MessageCore.IMO;
}
else
{
rootTransit.ItemElementName = DBHWebReference.ItemChoiceType1.ENINumber;
rootTransit.Item = message.MessageCore.ENI;
}
if (message.MessageCore.ETAKielCanal.HasValue)
rootTransit.ETAKielCanal = message.MessageCore.ETAKielCanal.Value.ToDBHDateString();
else
rootTransit.ETAKielCanal = null;
item = rootTransit;
break;
}
#endregion
#region NOA_NOD
case Message.NotificationClass.NOA_NOD:
{
if (message.Elements[0] is NOA_NOD noa_nod)
{
RootNOA_NOD rootNoaNod = new RootNOA_NOD();
if (noa_nod.ETAToNextPort.HasValue)
rootNoaNod.ETAToNextPort = noa_nod.ETAToNextPort.Value.ToDBHDateString();
// rootNoaNod.ETAToNextPortSpecified = noa_nod.ETAToNextPort.HasValue;
if ((noa_nod.ETDFromLastPort.HasValue) && (!noa_nod.LastPort.Equals("ZZUKN", StringComparison.OrdinalIgnoreCase)))
rootNoaNod.ETDFromLastPort = noa_nod.ETDFromLastPort.Value.ToDBHDateString();
// rootNoaNod.ETDFromLastPortSpecified = noa_nod.ETDFromLastPort.HasValue;
rootNoaNod.LastPort = noa_nod.LastPort;
rootNoaNod.NextPort = noa_nod.NextPort;
List choiceList = new List();
List