diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 20a26389..c657ba0b 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.ExcelReadService/App.config b/nsw/Source/bsmd.ExcelReadService/App.config index 631df383..74872a60 100644 --- a/nsw/Source/bsmd.ExcelReadService/App.config +++ b/nsw/Source/bsmd.ExcelReadService/App.config @@ -13,18 +13,6 @@ replace me! - - E:\temp\SietasSheets - - - - - - - - - - 300 diff --git a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs index 549a9163..c36bae61 100644 --- a/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs +++ b/nsw/Source/bsmd.ExcelReadService/ExcelReadService.cs @@ -1,23 +1,16 @@ -using System; +using bsmd.database; +using bsmd.email; +using log4net; +using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Diagnostics; -using System.Linq; using System.IO; using System.ServiceProcess; -using System.Text; -using System.Threading.Tasks; using System.Timers; -using log4net; - -using bsmd.database; -using bsmd.email; - namespace bsmd.ExcelReadService -{ +{ public partial class ExcelReadService : ServiceBase { private Timer _timer; diff --git a/nsw/Source/bsmd.ExcelReadService/Properties/Settings.Designer.cs b/nsw/Source/bsmd.ExcelReadService/Properties/Settings.Designer.cs index 9058be63..4c21e0c4 100644 --- a/nsw/Source/bsmd.ExcelReadService/Properties/Settings.Designer.cs +++ b/nsw/Source/bsmd.ExcelReadService/Properties/Settings.Designer.cs @@ -32,42 +32,6 @@ namespace bsmd.ExcelReadService.Properties { } } - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("E:\\temp\\SietasSheets")] - public string ArchiveFolder { - get { - return ((string)(this["ArchiveFolder"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string POP3Server { - get { - return ((string)(this["POP3Server"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string POP3User { - get { - return ((string)(this["POP3User"])); - } - } - - [global::System.Configuration.ApplicationScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string POP3Password { - get { - return ((string)(this["POP3Password"])); - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("300")] diff --git a/nsw/Source/bsmd.ExcelReadService/Properties/Settings.settings b/nsw/Source/bsmd.ExcelReadService/Properties/Settings.settings index fddb6043..fc6899fc 100644 --- a/nsw/Source/bsmd.ExcelReadService/Properties/Settings.settings +++ b/nsw/Source/bsmd.ExcelReadService/Properties/Settings.settings @@ -5,18 +5,6 @@ replace me! - - E:\temp\SietasSheets - - - - - - - - - - 300 diff --git a/nsw/Source/bsmd.ExcelReadService/Util.cs b/nsw/Source/bsmd.ExcelReadService/Util.cs index 3c3b77c9..5ffed974 100644 --- a/nsw/Source/bsmd.ExcelReadService/Util.cs +++ b/nsw/Source/bsmd.ExcelReadService/Util.cs @@ -958,33 +958,37 @@ namespace bsmd.ExcelReadService // lookup poc, imo, eta poc = reader.ReadText("Visit.PortOfCall"); - // Prüfen auf Transit - if (poc.ToUpper().Contains("CANAL")) + if (poc != null) { - poc = "ZZNOK"; - isTransit = true; - } - else - { - // Im Sheet könnte der Name statt des LOCODES stehen! - if (!RuleEngine.IsGermanLocode(poc)) + // Prüfen auf Transit + if (poc.ToUpper().Contains("CANAL")) { - // somehow lookup LOCODE from the port's name! - poc = LocodeDB.LocodeGERFromCity(poc); + poc = "ZZNOK"; + isTransit = true; + } + else + { + // Im Sheet könnte der Name statt des LOCODES stehen! + if (!RuleEngine.IsGermanLocode(poc)) + { + // somehow lookup LOCODE from the port's name! + poc = LocodeDB.LocodeGERFromCity(poc); + } + } + + imo = reader.ReadText("Visit.IMONumber"); + + // ETA + eta = reader.ReadDateTime("NOA_NOD.ETADateToPortOfCall", "NOA_NOD.ETATimeToPortOfCall"); + + if ((imo != null) && (eta.HasValue)) + { + result = DBManager.Instance.GetMessageCoreByShipInfos(imo, eta.Value, poc); + if (result.IsNew) + result.IsTransit = isTransit; } } - - imo = reader.ReadText("Visit.IMONumber"); - - // ETA - eta = reader.ReadDateTime("NOA_NOD.ETADateToPortOfCall", "NOA_NOD.ETATimeToPortOfCall"); - - result = DBManager.Instance.GetMessageCoreByShipInfos(imo, eta.Value, poc); - if (result.IsNew) - result.IsTransit = isTransit; - } - if (result == null) diff --git a/nsw/Source/bsmd.database/INFO.cs b/nsw/Source/bsmd.database/INFO.cs index 2e9c3b57..9de0e2ae 100644 --- a/nsw/Source/bsmd.database/INFO.cs +++ b/nsw/Source/bsmd.database/INFO.cs @@ -9,12 +9,13 @@ using System.Collections.Generic; using System.Data.SqlClient; +using log4net; namespace bsmd.database { public class INFO : DatabaseEntity { - + private static ILog _log = LogManager.GetLogger(typeof(INFO)); public INFO() { this.tablename = "[dbo].[INFO]"; @@ -148,32 +149,36 @@ namespace bsmd.database public override void Validate(List errors, List violations) { + _log.InfoFormat("rule checking port area {0}", this.PortArea ?? ""); if (!this.PortArea.IsNullOrEmpty()) { string key = this.MessageCore.PoC + this.PortArea; bool hasValue = DBManager.Instance.GetPortAreaDict().ContainsKey(key); if (!hasValue) { + _log.WarnFormat("No port area entry found: PoC {0}, area {1}", this.MessageCore.PoC ?? "", this.PortArea ?? ""); if(this.MessageCore.PoC == null) { + foreach (PortArea pa in DBManager.Instance.GetPortAreaDict().Values) { if (this.PortArea.Equals(pa.Code)) { hasValue = true; + _log.InfoFormat("PoC null but port area found: {0} {1} {2}", pa.Name, pa.Country, pa.Port); break; } } } if (!hasValue) { + _log.WarnFormat("creating violation for invalid port area {0}", this.PortArea ?? ""); violations.Add(RuleEngine.CreateViolation(ValidationCode.PORTAREA, string.Format("{0} is not in the list of valid port areas", this.PortArea), null)); } } } - } #endregion diff --git a/nsw/Source/bsmd.email/BSMDMail.cs b/nsw/Source/bsmd.email/BSMDMail.cs index 3d30d220..96158a26 100644 --- a/nsw/Source/bsmd.email/BSMDMail.cs +++ b/nsw/Source/bsmd.email/BSMDMail.cs @@ -22,7 +22,7 @@ namespace bsmd.email public class BSMDMail : IDisposable { private SmtpClient client; - ILog log = LogManager.GetLogger(typeof(BSMDMail)); + private static ILog log = LogManager.GetLogger(typeof(BSMDMail)); internal BSMDMail() { @@ -42,11 +42,13 @@ namespace bsmd.email SslPolicyErrors sslPolicyErrors) { return true; }; - } + } + /// + /// Synchrones Senden einer E-Mail + /// internal void Send(MailMessage message) - { - // doch nicht asynchron, da nur eine Nachricht gleichzeitig geschickt werden kann und ich so den sync code spare + { try { this.client.Send(message); @@ -60,63 +62,67 @@ namespace bsmd.email { log.ErrorFormat("other error while sending e-mail:{0}", ex.Message); } - - // http://stackoverflow.com/questions/7276375/what-are-best-practices-for-using-smtpclient-sendasync-and-dispose-under-net-4 - // asynchron schicken und wenn's erledigt ist gleich disposen (wichtig!) - - // in meinem Fall nicht so recht wirksam, da eine Mail meist an mehrere Empfänger geschickt wird - - /* - smtpClient.SendCompleted += (s, e) => - { - smtpClient.Dispose(); - message.Dispose(); - }; - - smtpClient.SendAsync(message, null); - */ - - } - + /// + /// sendet eine E-Mail mit Attachments (jetzt asynchron) + /// + /// Betreffzeile + /// Liste von Dateien die angehängt werden sollen public static void SendNSWReportWithAttachments(string subject, List filenameList) { - using (BSMDMail mailer = new BSMDMail()) + BSMDMail mailer = new BSMDMail(); + MailMessage message = new MailMessage(); + MailAddress fromAddress = new MailAddress(Properties.Settings.Default.Sender); + + message.From = fromAddress; + message.Subject = string.Format(subject); + message.IsBodyHtml = false; + message.Body = "see attachment"; + + foreach (string recipient in Properties.Settings.Default.Recipient) { - foreach (string recipient in Properties.Settings.Default.Recipient) - { - MailMessage message = new MailMessage(); - MailAddress fromAddress = new MailAddress(Properties.Settings.Default.Sender); + message.To.Add(recipient); + } - message.From = fromAddress; - message.Subject = string.Format(subject); - message.IsBodyHtml = false; - message.Body = "see attachment"; - message.To.Add(recipient); + foreach (string filename in filenameList) + { + Attachment attachment = new Attachment(filename, MediaTypeNames.Application.Octet); + ContentDisposition disposition = attachment.ContentDisposition; + disposition.CreationDate = File.GetCreationTime(filename); + disposition.ModificationDate = File.GetLastWriteTime(filename); + disposition.ReadDate = File.GetLastAccessTime(filename); + disposition.FileName = Path.GetFileName(filename); + disposition.Size = new FileInfo(filename).Length; + disposition.DispositionType = DispositionTypeNames.Attachment; + message.Attachments.Add(attachment); + } - foreach (string filename in filenameList) - { - Attachment attachment = new Attachment(filename, MediaTypeNames.Application.Octet); - ContentDisposition disposition = attachment.ContentDisposition; - disposition.CreationDate = File.GetCreationTime(filename); - disposition.ModificationDate = File.GetLastWriteTime(filename); - disposition.ReadDate = File.GetLastAccessTime(filename); - disposition.FileName = Path.GetFileName(filename); - disposition.Size = new FileInfo(filename).Length; - disposition.DispositionType = DispositionTypeNames.Attachment; - message.Attachments.Add(attachment); - } + // mailer.Send(message); - mailer.Send(message); + mailer.client.SendCompleted += (s, e) => + { + log.InfoFormat("{0} email send completed", subject); + mailer.Dispose(); + message.Dispose(); + }; - message.Dispose(); - - } + try + { + mailer.client.SendAsync(message, null); + } + catch (SmtpException smtpException) + { + log.ErrorFormat("SMTP error while sending e-mail:{0}", smtpException.Message); + } + catch (Exception ex) + { + log.ErrorFormat("other error while sending e-mail:{0}", ex.Message); } } + public static void SendSystemInfo(string subject, string body, string recipient) { using (BSMDMail mailer = new BSMDMail()) @@ -134,7 +140,47 @@ namespace bsmd.email mailer.Send(message); } + } + + public static void SendSystemInfoAsync(string subject, string body, string recipient) + { + BSMDMail mailer = new BSMDMail(); + + MailMessage message = new MailMessage(); + MailAddress fromAddress = new MailAddress(Properties.Settings.Default.Sender); + message.From = fromAddress; + message.Subject = subject; + message.IsBodyHtml = false; + message.Body = body; + + message.To.Add(recipient); + MailAddress adminAddress = new MailAddress(Properties.Settings.Default.AdminEmail); + message.CC.Add(adminAddress); + + // http://stackoverflow.com/questions/7276375/what-are-best-practices-for-using-smtpclient-sendasync-and-dispose-under-net-4 + // asynchron schicken und wenn's erledigt ist gleich disposen (wichtig!) + + mailer.client.SendCompleted += (s, e) => + { + log.InfoFormat("system info email async send to {0} completed", recipient); + mailer.Dispose(); + message.Dispose(); + }; + + try + { + mailer.client.SendAsync(message, null); + } + catch (SmtpException smtpException) + { + log.ErrorFormat("SMTP error while sending e-mail:{0}", smtpException.Message); + } + catch (Exception ex) + { + log.ErrorFormat("other error while sending e-mail:{0}", ex.Message); + } } + public void Dispose() {