From 0ae84839d16ab1766de7ffcef649244ff1ce9ae5 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Tue, 15 Nov 2022 18:44:38 +0100 Subject: [PATCH] repaired message return handling --- bsmd.dbh/MessageController.cs | 9 +++- bsmd.dbh/Properties/Settings.Designer.cs | 9 ++++ bsmd.dbh/Properties/Settings.settings | 3 ++ bsmd.dbh/RequestUtil.cs | 2 +- bsmd.dbh/ResponseUtil.cs | 55 +++++++++++++++++++++--- bsmd.dbh/app.config | 3 ++ 6 files changed, 72 insertions(+), 9 deletions(-) diff --git a/bsmd.dbh/MessageController.cs b/bsmd.dbh/MessageController.cs index 08978a50..138403f9 100644 --- a/bsmd.dbh/MessageController.cs +++ b/bsmd.dbh/MessageController.cs @@ -92,14 +92,19 @@ namespace bsmd.dbh foreach (string inputFile in Directory.GetFiles(Properties.Settings.Default.IncomingFolder)) { + string justFilename = Path.GetFileName(inputFile); // lokale Dateien verarbeiten if (!ResponseUtil.Read(inputFile)) { - _log.ErrorFormat("Error reading input file {0}", inputFile); + _log.ErrorFormat("Error reading input file {0}", justFilename); + string errorPath = Path.Combine(Properties.Settings.Default.IncomingErrorFolder, justFilename); + File.Move(inputFile, errorPath); } else { - File.Move(inputFile, Properties.Settings.Default.IncomingArchiveFolder); + _log.InfoFormat("Incoming file {0} processed", justFilename); + string archivePath = Path.Combine(Properties.Settings.Default.IncomingArchiveFolder, justFilename); + File.Move(inputFile, archivePath); } // remote Dateien löschen bsmd.dakosy.SFtp.RemoveProcessedFile(Properties.Settings.Default.RemoteOutgoingFolder, Path.GetFileName(inputFile)); diff --git a/bsmd.dbh/Properties/Settings.Designer.cs b/bsmd.dbh/Properties/Settings.Designer.cs index dbf02fe4..ff974b23 100644 --- a/bsmd.dbh/Properties/Settings.Designer.cs +++ b/bsmd.dbh/Properties/Settings.Designer.cs @@ -94,5 +94,14 @@ namespace bsmd.dbh.Properties { return ((string)(this["SFTPSessionName"])); } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string IncomingErrorFolder { + get { + return ((string)(this["IncomingErrorFolder"])); + } + } } } diff --git a/bsmd.dbh/Properties/Settings.settings b/bsmd.dbh/Properties/Settings.settings index f3f78a19..c1debefc 100644 --- a/bsmd.dbh/Properties/Settings.settings +++ b/bsmd.dbh/Properties/Settings.settings @@ -26,5 +26,8 @@ dbh + + + \ No newline at end of file diff --git a/bsmd.dbh/RequestUtil.cs b/bsmd.dbh/RequestUtil.cs index 73f19307..6c15d829 100644 --- a/bsmd.dbh/RequestUtil.cs +++ b/bsmd.dbh/RequestUtil.cs @@ -29,7 +29,7 @@ namespace bsmd.dbh root.SourceDocumentVersion = "7.0"; root.Timestamp = DateTime.Now; root.Sender = Properties.Settings.Default.Sender; - root.SenderReference = "N"; + root.SenderReference = message.Id.ToString(); bsmd.database.ReportingParty reportingParty = DBManager.Instance.GetReportingPartyDict()[core.DefaultReportingPartyId.Value]; Request.ReportingParty rp = new Request.ReportingParty(); rp.RPCity = reportingParty.City; diff --git a/bsmd.dbh/ResponseUtil.cs b/bsmd.dbh/ResponseUtil.cs index cd98d2e2..9e1e6d9a 100644 --- a/bsmd.dbh/ResponseUtil.cs +++ b/bsmd.dbh/ResponseUtil.cs @@ -34,7 +34,7 @@ namespace bsmd.dbh return result; } - string fileSeqString = m.Groups[0].Value; + string fileSeqString = m.Groups[1].Value; if(!Int32.TryParse(fileSeqString, out int fileSeqNum)) { @@ -57,7 +57,7 @@ namespace bsmd.dbh return result; } - bsmd.dbh.Response.Root root; + bsmd.dbh.Response.Root root = null; try { @@ -66,14 +66,57 @@ namespace bsmd.dbh { root = (bsmd.dbh.Response.Root) serializer.Deserialize(s); } + + if(Guid.TryParse(root.SenderReference, out Guid refGuid)) + { + if (!sentMessage.Id.Equals(refGuid)) + _log.WarnFormat("sender ref {0} does not match sent message id {1}", refGuid, sentMessage.Id); + } + else + { + _log.WarnFormat("sender ref {0} is no guid", root.SenderReference); + } + + switch(sentMessage.MessageNotificationClass) + { + case Message.NotificationClass.VISIT: + if(root.Type == Response.RootType.VISIT) + { + if(aCore.VisitId.IsNullOrEmpty() && !root.VisitId.IsNullOrEmpty()) + { + aCore.VisitId = root.VisitId; + _log.InfoFormat("Received Visit-Id {0} for core {1}", root.VisitId, aCore.Id); + } + } + break; + case Message.NotificationClass.TRANSIT: + if (root.Type == Response.RootType.TRANSIT) + { + if (aCore.TransitId.IsNullOrEmpty() && !root.TransitId.IsNullOrEmpty()) + { + aCore.TransitId = root.TransitId; + _log.InfoFormat("Received Transit-Id {0} for core {1}", root.TransitId, aCore.Id); + } + } + break; + default: + + + break; + } + + if (!(aCore.Cancelled ?? false)) + aCore.BSMDStatusInternal = MessageCore.BSMDStatus.RESPONDED; + + DBManager.Instance.Save(aCore); + result = true; } + catch(Exception ex) { - _log.ErrorFormat("Failed to deserialize: {0}", ex.Message); + _log.ErrorFormat("Failed to deserialize return message: {0}", ex.Message); return result; - } - - + } return result; } diff --git a/bsmd.dbh/app.config b/bsmd.dbh/app.config index 52806f8b..27cebe9c 100644 --- a/bsmd.dbh/app.config +++ b/bsmd.dbh/app.config @@ -31,6 +31,9 @@ dbh + + +