DBH will eine fortlaufende Nummer bei der Abgabe von Dateien über SFTP Diese wird über einen zentralen Zähler vergeben und in MessageHeader gespeichert
82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
// Copyright (c) 2020-present schick Informatik
|
|
// Description: Verarbeitung von empfangenen Rückmeldungen
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Serialization;
|
|
using log4net;
|
|
using bsmd.database;
|
|
|
|
namespace bsmd.dbh
|
|
{
|
|
internal static class ResponseUtil
|
|
{
|
|
private static readonly ILog _log = LogManager.GetLogger(typeof(ResponseUtil));
|
|
private static readonly Regex _regexFilename = new Regex(@".*NSW\.DBH\.BSMD\.(.*)\.xml");
|
|
|
|
internal static bool Read(string inputFile)
|
|
{
|
|
bool result = false;
|
|
if(!inputFile.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_log.ErrorFormat("no xml file: {0}", inputFile);
|
|
return result;
|
|
}
|
|
|
|
Match m = _regexFilename.Match(inputFile);
|
|
if(!m.Success) {
|
|
_log.WarnFormat("returned file doesn't follow naming convention NSW.DBH.BSMD.*:{0}", inputFile);
|
|
return result;
|
|
}
|
|
|
|
string fileSeqString = m.Groups[0].Value;
|
|
|
|
if(!Int32.TryParse(fileSeqString, out int fileSeqNum))
|
|
{
|
|
_log.ErrorFormat("matched file sequence number couldn't be parsed: {0}", fileSeqString);
|
|
return result;
|
|
}
|
|
|
|
// load message(s?) by file seq string
|
|
Message sentMessage = DBManager.Instance.GetMessageByFileSeqNum(fileSeqNum);
|
|
if(sentMessage == null)
|
|
{
|
|
_log.ErrorFormat("cannot find a message for file sequence number {0}", fileSeqNum);
|
|
return result;
|
|
}
|
|
|
|
MessageCore aCore = DBManager.Instance.GetMessageCoreById(sentMessage.MessageCoreId.Value);
|
|
if(aCore == null)
|
|
{
|
|
_log.ErrorFormat("There is no core with id {0}", sentMessage.MessageCoreId.Value);
|
|
return result;
|
|
}
|
|
|
|
bsmd.dbh.Response.Root root;
|
|
|
|
try
|
|
{
|
|
XmlSerializer serializer = new XmlSerializer(typeof(bsmd.dbh.Response.Root));
|
|
using (Stream s = new FileStream(inputFile, FileMode.Open))
|
|
{
|
|
root = (bsmd.dbh.Response.Root) serializer.Deserialize(s);
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_log.ErrorFormat("Failed to deserialize: {0}", ex.Message);
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|