diff --git a/SendNSWMessageService/NSWSendService.cs b/SendNSWMessageService/NSWSendService.cs index 91056ea6..692a0878 100644 --- a/SendNSWMessageService/NSWSendService.cs +++ b/SendNSWMessageService/NSWSendService.cs @@ -292,9 +292,7 @@ namespace SendNSWMessageService // external processing for dbh bsmd.dbh.MessageController.SendAndReceive(); - List coresMarkedForStatusQuery = DBManager.Instance.GetMessageCoresWithNSWStatusFlag(); - - foreach (MessageCore core in coresMarkedForStatusQuery) + foreach (MessageCore core in DBManager.Instance.GetMessageCoresWithNSWStatusFlag()) { core.QueryNSWStatus = false; // reset flag Status aStatus = new Status(core); diff --git a/bsmd.dakosy/sftp.cs b/bsmd.dakosy/sftp.cs index 83c05cc5..d4bdd43c 100644 --- a/bsmd.dakosy/sftp.cs +++ b/bsmd.dakosy/sftp.cs @@ -97,7 +97,7 @@ namespace bsmd.dakosy } - public static void TransmitAll(string remoteDir, string localDir, Direction direction, string sessionName) + private static Process StartWinSCPProcess() { Process winscp = new Process(); winscp.StartInfo.FileName = Properties.Settings.Default.WINSCPFullPath; @@ -107,12 +107,24 @@ namespace bsmd.dakosy winscp.StartInfo.RedirectStandardOutput = true; winscp.StartInfo.RedirectStandardError = true; winscp.StartInfo.CreateNoWindow = true; - winscp.Start(); + winscp.EnableRaisingEvents = true; + winscp.OutputDataReceived += (s, e) => { if (!e.Data.IsNullOrEmpty()) _log.Debug(e.Data); }; + winscp.ErrorDataReceived += (s, e) => { if (!e.Data.IsNullOrEmpty()) _log.Warn(e.Data); }; + winscp.Start(); + winscp.BeginErrorReadLine(); + winscp.BeginOutputReadLine(); + + return winscp; + } + + public static void TransmitAll(string remoteDir, string localDir, Direction direction, string openCommand) + { + Process winscp = StartWinSCPProcess(); // Feed in the scripting commands winscp.StandardInput.WriteLine("option batch abort"); winscp.StandardInput.WriteLine("option confirm off"); - winscp.StandardInput.WriteLine("open " + sessionName); + winscp.StandardInput.WriteLine(openCommand); winscp.StandardInput.WriteLine("lcd " + localDir); // winscp.StandardInput.WriteLine("ls"); if (remoteDir != null) @@ -120,63 +132,30 @@ namespace bsmd.dakosy if(direction == Direction.INCOMING) winscp.StandardInput.WriteLine("get *.xml"); if(direction == Direction.OUTGOING) - winscp.StandardInput.WriteLine("put *.xml"); - // move back up since winscp session remembers the last folder - winscp.StandardInput.WriteLine("cd .."); - winscp.StandardInput.WriteLine("cd .."); - winscp.StandardInput.Close(); - - // Collect all output - string output = winscp.StandardOutput.ReadToEnd(); - _log.Debug(output); - output = winscp.StandardError.ReadToEnd(); - if(!output.Trim().IsNullOrEmpty()) - _log.Warn(output); + winscp.StandardInput.WriteLine("put *.xml"); + winscp.StandardInput.Close(); // Wait until WinSCP finishes winscp.WaitForExit(); } - public static void RemoveProcessedFile(string remoteDir, string filename, string sessionName) + public static void RemoveProcessedFile(string remoteDir, string filename, string openCommand) { - Process winscp = new Process(); - winscp.StartInfo.FileName = Properties.Settings.Default.WINSCPFullPath; - winscp.StartInfo.Arguments = "/xmllog=\"" + Properties.Settings.Default.SFTPLog + "\""; - winscp.StartInfo.UseShellExecute = false; - winscp.StartInfo.RedirectStandardInput = true; - winscp.StartInfo.RedirectStandardOutput = true; - winscp.StartInfo.RedirectStandardError = true; - winscp.StartInfo.CreateNoWindow = true; - winscp.Start(); + Process winscp = StartWinSCPProcess(); // Feed in the scripting commands winscp.StandardInput.WriteLine("option batch abort"); winscp.StandardInput.WriteLine("option confirm off"); - winscp.StandardInput.WriteLine("open " + sessionName); + winscp.StandardInput.WriteLine(openCommand); // winscp.StandardInput.WriteLine("ls"); if (remoteDir != null) winscp.StandardInput.WriteLine("cd " + remoteDir); - winscp.StandardInput.WriteLine("rm " + filename); - if (remoteDir != null) - { - // move back up since winscp session remembers the last folder - winscp.StandardInput.WriteLine("cd .."); - winscp.StandardInput.WriteLine("cd .."); - } - winscp.StandardInput.Close(); - - // Collect all output - string output = winscp.StandardOutput.ReadToEnd(); - _log.Debug(output); - output = winscp.StandardError.ReadToEnd(); - if (!output.Trim().IsNullOrEmpty()) - _log.Warn(output); + winscp.StandardInput.WriteLine("rm " + filename); + winscp.StandardInput.Close(); // Wait until WinSCP finishes winscp.WaitForExit(); - } - } } diff --git a/bsmd.dbh/MessageController.cs b/bsmd.dbh/MessageController.cs index f634d7b9..0dc06443 100644 --- a/bsmd.dbh/MessageController.cs +++ b/bsmd.dbh/MessageController.cs @@ -6,7 +6,7 @@ using System; using System.IO; using bsmd.database; -using System.Linq; + namespace bsmd.dbh { @@ -117,7 +117,7 @@ namespace bsmd.dbh public static void SendAndReceive() { // sent unsent messages in output folder - bsmd.dakosy.SFtp.TransmitAll(Properties.Settings.Default.RemoteIncomingFolder, Properties.Settings.Default.OutgoingFolder, dakosy.SFtp.Direction.OUTGOING, Properties.Settings.Default.SFTPSessionName); + bsmd.dakosy.SFtp.TransmitAll(Properties.Settings.Default.RemoteIncomingFolder, Properties.Settings.Default.OutgoingFolder, dakosy.SFtp.Direction.OUTGOING, Properties.Settings.Default.SFTPOpenCommand); // move files from output folder to archive folder foreach(string sentFile in Directory.GetFiles(Properties.Settings.Default.OutgoingFolder)) { @@ -130,7 +130,7 @@ namespace bsmd.dbh // receive files from remote host // SFTP verbindung öffnen und alle Dateien herunterladen - bsmd.dakosy.SFtp.TransmitAll(Properties.Settings.Default.RemoteOutgoingFolder, Properties.Settings.Default.IncomingFolder, dakosy.SFtp.Direction.INCOMING, Properties.Settings.Default.SFTPSessionName); + bsmd.dakosy.SFtp.TransmitAll(Properties.Settings.Default.RemoteOutgoingFolder, Properties.Settings.Default.IncomingFolder, dakosy.SFtp.Direction.INCOMING, Properties.Settings.Default.SFTPOpenCommand); foreach (string inputFile in Directory.GetFiles(Properties.Settings.Default.IncomingFolder)) { @@ -151,7 +151,7 @@ namespace bsmd.dbh File.Delete(inputFile); } // remote Dateien löschen - bsmd.dakosy.SFtp.RemoveProcessedFile(Properties.Settings.Default.RemoteOutgoingFolder, Path.GetFileName(inputFile), Properties.Settings.Default.SFTPSessionName); + bsmd.dakosy.SFtp.RemoveProcessedFile(Properties.Settings.Default.RemoteOutgoingFolder, Path.GetFileName(inputFile), Properties.Settings.Default.SFTPOpenCommand); } } diff --git a/bsmd.dbh/Properties/Settings.Designer.cs b/bsmd.dbh/Properties/Settings.Designer.cs index d448198b..c8c71aea 100644 --- a/bsmd.dbh/Properties/Settings.Designer.cs +++ b/bsmd.dbh/Properties/Settings.Designer.cs @@ -89,15 +89,17 @@ namespace bsmd.dbh.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("dbh")] - public string SFTPSessionName { + public string SFTPOpenCommand { get { - return ((string)(this["SFTPSessionName"])); + return ((string)(this["SFTPOpenCommand"])); } } [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [global::System.Configuration.DefaultSettingValueAttribute("sftp://f-000333@fx.dbh.de/ -hostkey=\"ecdsa-sha2-nistp256 256 453JBU8hAOOQ7wEvmTw5" + + "fXsUyZsVCSufyATbGKLh+ak\" -privatekey=\"C:\\work\\Services\\SendNSWMessageService\\dbh" + + "\\sshkeynp.ppk\"")] public string IncomingErrorFolder { get { return ((string)(this["IncomingErrorFolder"])); diff --git a/bsmd.dbh/Properties/Settings.settings b/bsmd.dbh/Properties/Settings.settings index 4db2b6c2..477b320d 100644 --- a/bsmd.dbh/Properties/Settings.settings +++ b/bsmd.dbh/Properties/Settings.settings @@ -23,11 +23,11 @@ test/dbh_2_bsmd - + dbh - + sftp://f-000333@fx.dbh.de/ -hostkey="ecdsa-sha2-nistp256 256 453JBU8hAOOQ7wEvmTw5fXsUyZsVCSufyATbGKLh+ak" -privatekey="C:\work\Services\SendNSWMessageService\dbh\sshkeynp.ppk" 00006017 diff --git a/bsmd.dbh/RequestUtil.cs b/bsmd.dbh/RequestUtil.cs index 4aeed901..5013b7f5 100644 --- a/bsmd.dbh/RequestUtil.cs +++ b/bsmd.dbh/RequestUtil.cs @@ -778,7 +778,7 @@ namespace bsmd.dbh rootPre.TankerDetails.ConditionCargoBallastTanks = (TankCondition)pre72h.ConditionCargoBallastTanks.Value; if (pre72h.NatureOfCargo != string.Empty) rootPre.TankerDetails.TypeOfCargo = pre72h.NatureOfCargo; - bool sendVolume = pre72h.VolumeOfCargo.HasValue && (pre72h.VolumeOfCargo.Value > 0); + bool sendVolume = pre72h.VolumeOfCargo > 0; rootPre.TankerDetails.VolumeOfCargo_TNESpecified = sendVolume; if (sendVolume) rootPre.TankerDetails.VolumeOfCargo_TNE = Decimal.Round((decimal)(pre72h.VolumeOfCargo.Value), 3); diff --git a/bsmd.dbh/ResponseUtil.cs b/bsmd.dbh/ResponseUtil.cs index 5d9905e5..3020110f 100644 --- a/bsmd.dbh/ResponseUtil.cs +++ b/bsmd.dbh/ResponseUtil.cs @@ -129,7 +129,7 @@ namespace bsmd.dbh case Response.RootType.RESET: if(root.ReportingClassesResetted?.ReportingClass.Length > 0) { - _log.InfoFormat("Message {0} RESET confirmed, {1} messages", sentMessage.MessageNotificationClassDisplay, root.Messages.Length); ; + _log.InfoFormat("Message {0} RESET confirmed, {1} messages", sentMessage.MessageNotificationClassDisplay, root.Messages?.Length); sentMessage.SendSuccess = false; // bestätigter Reset setzt grünen Buppel zurück sentMessage.Status = Message.MessageStatus.ACCEPTED; sentMessage.InternalStatus = Message.BSMDStatus.CONFIRMED; diff --git a/bsmd.dbh/app.config b/bsmd.dbh/app.config index b9d62b74..391f6795 100644 --- a/bsmd.dbh/app.config +++ b/bsmd.dbh/app.config @@ -28,11 +28,11 @@ test/dbh_2_bsmd - + dbh - + sftp://f-000333@fx.dbh.de/ -hostkey="ecdsa-sha2-nistp256 256 453JBU8hAOOQ7wEvmTw5fXsUyZsVCSufyATbGKLh+ak" -privatekey="C:\work\Services\SendNSWMessageService\dbh\sshkeynp.ppk" 00006017 diff --git a/misc/SendNSWMessageService.exe.config b/misc/SendNSWMessageService.exe.config new file mode 100644 index 00000000..5edee9d4 --- /dev/null +++ b/misc/SendNSWMessageService.exe.config @@ -0,0 +1,157 @@ + + + +
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + BSMD-PROD + + + t7g7fDP18#7GQw#D + + + https://www.his-nord.de/HIS-Service/StatusInfoNSW.jsp + + + + + Initial Catalog=nswtest;Data Source=192.168.2.24\SQLEXPRESS;Uid=dfuser;pwd=dfpasswd;Persist Security Info=False;Connection Reset=false + + + 30 + + + + + dakosy + + + c:\temp\sftp_log.xml + + + c:\work\dakosy\out + + + c:\work\dakosy\in + + + True + + + c:\work\Tools\WinSCP\WinSCP.com + + + in/prod/ed02 + + + in/test/ed02 + + + out/prod + + + out/test + + + + + https://edi-gate.dbh.de/bsmd-soap + + + 00003050 + + + + + 00006017 + + + C:\temp\dbh\out + + + C:\temp\dbh\out_archive + + + C:\temp\dbh\in + + + C:\temp\dbh\in_archive + + + C:\temp\dbh\in_error + + + test/bsmd_2_dbh + + + test/dbh_2_bsmd + + + open sftp://f-000333@fx.dbh.de/ -hostkey="ecdsa-sha2-nistp256 256 453JBU8hAOOQ7wEvmTw5fXsUyZsVCSufyATbGKLh+ak" -privatekey="C:\git_lager\git_bsmd\bsmd.dbh\misc\sshkeynp.ppk" + + + + + C:\work\HIS-NORD\Test + + + IMP + + + client.bat + + + 1 + + + RESULTS + + + ANSWERS + + + ANSWERS_DONE + + + ANSWERS_CORRUPT + + + + + + + + + + + + \ No newline at end of file