153 lines
7.1 KiB
C#
153 lines
7.1 KiB
C#
using bsmd.database;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using System.Xml.Serialization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using log4net;
|
|
using System.Xml.Linq;
|
|
|
|
namespace bsmd.hisnord
|
|
{
|
|
public class Response
|
|
{
|
|
|
|
private static ILog _log = LogManager.GetLogger(typeof(Response));
|
|
|
|
|
|
public static void ReadAnswers()
|
|
{
|
|
foreach (string answerFile in Directory.GetFiles(Properties.Settings.Default.AnswerDir))
|
|
{
|
|
bool isOK = true;
|
|
|
|
// Informationen aus dem Dateinamen
|
|
// Meldetyp_Referenz_ID_Timestamp.xml
|
|
string bareFileName = Path.GetFileNameWithoutExtension(answerFile);
|
|
string[] fileNameElems = bareFileName.Split('_');
|
|
|
|
if (fileNameElems.Length < 4)
|
|
{
|
|
_log.WarnFormat("ANSWER file {0}.xml has an invalid file name", bareFileName);
|
|
isOK = false;
|
|
}
|
|
else
|
|
{
|
|
int prozessStatus;
|
|
if (!Int32.TryParse(fileNameElems[fileNameElems.Length - 1], out prozessStatus))
|
|
{
|
|
_log.WarnFormat("ANSWER file {0}.xml has no process status at the end (2..6)", bareFileName);
|
|
isOK = false;
|
|
}
|
|
else
|
|
{
|
|
int timestampMilliSecs;
|
|
if (!Int32.TryParse(fileNameElems[fileNameElems.Length - 2], out timestampMilliSecs))
|
|
{
|
|
_log.WarnFormat("ANSWER file {0}.xml has no readable timestamp", bareFileName);
|
|
isOK = false;
|
|
}
|
|
else
|
|
{
|
|
string refId = fileNameElems[fileNameElems.Length - 3];
|
|
string meldeTyp = fileNameElems[fileNameElems.Length - 4];
|
|
if (fileNameElems.Length == 5)
|
|
meldeTyp = string.Format("{0}_{1}", fileNameElems[fileNameElems.Length - 5], meldeTyp);
|
|
|
|
// TODO: klären was man hier liest: reguläre Antwort oder Schnittstellenfehler
|
|
// XML Linq statt Serialisierung
|
|
try
|
|
{
|
|
XElement xml = XElement.Load(answerFile);
|
|
|
|
// declare Namespaces
|
|
XNamespace ns1 = "http://api.national-single-window.de/visitIdRequest";
|
|
XNamespace ns6 = "http://api.national-single-window.de/receipt";
|
|
//XNamespace ns15 = "http://api.national-single-window.de/statusForClientRequestId";
|
|
XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
|
|
XNamespace ns15 = "http://api.national-single-window.de/visitIdResponse";
|
|
|
|
if(xml.Descendants("SystemError").Count() > 0)
|
|
{
|
|
// Fehlernachricht
|
|
SystemError systemError = new SystemError(xml);
|
|
|
|
// Speichern
|
|
|
|
}
|
|
else
|
|
{
|
|
// NSW Rückmeldung
|
|
NSWResponse nswResponse = new NSWResponse(xml);
|
|
|
|
// Rückmeldung auswerten
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
if (visitIdResponse != null)
|
|
{
|
|
_log.InfoFormat("HIS-NORD: Visit-ID {0} delivered for Core {1}", visitIdResponse.VisitId, visitIdResponse.ClientRequestId);
|
|
// update MessageCore
|
|
if (visitIdResponse.ClientRequestId != null)
|
|
{
|
|
Guid messageCoreId;
|
|
if (Guid.TryParse(visitIdResponse.ClientRequestId, out messageCoreId))
|
|
{
|
|
MessageCore answerCore = DBManager.Instance.GetMessageCoreById(messageCoreId);
|
|
if (answerCore == null)
|
|
{
|
|
_log.WarnFormat("HIS-NORD: Core not found for notification id {0}", visitIdResponse.NotificationId);
|
|
}
|
|
else
|
|
{
|
|
if (!answerCore.IsTransit)
|
|
answerCore.VisitId = visitIdResponse.VisitId;
|
|
else
|
|
answerCore.TransitId = visitIdResponse.VisitId;
|
|
answerCore.BSMDStatusInternal = MessageCore.BSMDStatus.RESPONDED;
|
|
DBManager.Instance.Save(answerCore);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_log.WarnFormat("{0} ANSWER parsed, but MessageCoreId is no Guid: {1}",
|
|
Path.GetFileName(answerFile), visitIdResponse.ClientRequestId);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_log.WarnFormat("Client request id is null in {0}", answerFile);
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_log.WarnFormat("Exception deserializing ANSWER file: {0}", ex.ToString());
|
|
isOK = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(isOK)
|
|
{
|
|
// archive file
|
|
File.Move(answerFile, Path.Combine(Properties.Settings.Default.AnswerArchiveDir, Path.GetFileName(answerFile)));
|
|
}
|
|
else
|
|
{
|
|
File.Move(answerFile, Path.Combine(Properties.Settings.Default.AnswerCorruptDir, Path.GetFileName(answerFile)));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|