using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using log4net; using bsmd.database; using System.IO; namespace bsmd.dbh { public static class MessageController { private static readonly ILog _log = LogManager.GetLogger(typeof(MessageController)); public static bool SendMessage(MessageCore core, Message message) { bool result = true; try { if (message == null) return false; 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; } string messageFile = RequestUtil.CreateMessageFile(core, message); if (messageFile != null) { // move file to output directory } else { result = false; } } catch (Exception ex) { _log.Error(ex.ToString()); result = false; } return result; } public static bool SendCancelCore(MessageCore core) { bool result = true; return result; } public static void SendAndReceive() { // sent unsent messages in output folder // remove files from output folder to archive folder // receive files from remote host // SFTP verbindung öffnen und alle Dateien herunterladen string localDir = Properties.Settings.Default.OutgoingFolder; bsmd.dakosy.SFtp.GetAll(Properties.Settings.Default.RemoteOutgoingFolder, Properties.Settings.Default.IncomingFolder); foreach (string inputFile in Directory.GetFiles(localDir)) { // lokale Dateien verarbeiten if (!ResponseUtil.Read(inputFile)) { _log.ErrorFormat("Error reading input file {0}", inputFile); } else { File.Move(inputFile, Properties.Settings.Default.IncomingArchiveFolder); } // remote Dateien löschen bsmd.dakosy.SFtp.RemoveProcessedFile(Properties.Settings.Default.RemoteOutgoingFolder, Path.GetFileName(inputFile)); } } } }