Excel Implementierung ff
This commit is contained in:
parent
fba6a204e3
commit
7d94d4e481
Binary file not shown.
@ -13,18 +13,6 @@
|
|||||||
<setting name="ConnectionString" serializeAs="String">
|
<setting name="ConnectionString" serializeAs="String">
|
||||||
<value>replace me!</value>
|
<value>replace me!</value>
|
||||||
</setting>
|
</setting>
|
||||||
<setting name="ArchiveFolder" serializeAs="String">
|
|
||||||
<value>E:\temp\SietasSheets</value>
|
|
||||||
</setting>
|
|
||||||
<setting name="POP3Server" serializeAs="String">
|
|
||||||
<value />
|
|
||||||
</setting>
|
|
||||||
<setting name="POP3User" serializeAs="String">
|
|
||||||
<value />
|
|
||||||
</setting>
|
|
||||||
<setting name="POP3Password" serializeAs="String">
|
|
||||||
<value />
|
|
||||||
</setting>
|
|
||||||
<setting name="SleepSeconds" serializeAs="String">
|
<setting name="SleepSeconds" serializeAs="String">
|
||||||
<value>300</value>
|
<value>300</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
|||||||
@ -1,23 +1,16 @@
|
|||||||
using System;
|
using bsmd.database;
|
||||||
|
using bsmd.email;
|
||||||
|
using log4net;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
|
||||||
using log4net;
|
|
||||||
|
|
||||||
using bsmd.database;
|
|
||||||
using bsmd.email;
|
|
||||||
|
|
||||||
|
|
||||||
namespace bsmd.ExcelReadService
|
namespace bsmd.ExcelReadService
|
||||||
{
|
{
|
||||||
public partial class ExcelReadService : ServiceBase
|
public partial class ExcelReadService : ServiceBase
|
||||||
{
|
{
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
|
|||||||
@ -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.Configuration.ApplicationScopedSettingAttribute()]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Configuration.DefaultSettingValueAttribute("300")]
|
[global::System.Configuration.DefaultSettingValueAttribute("300")]
|
||||||
|
|||||||
@ -5,18 +5,6 @@
|
|||||||
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
||||||
<Value Profile="(Default)">replace me!</Value>
|
<Value Profile="(Default)">replace me!</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
<Setting Name="ArchiveFolder" Type="System.String" Scope="Application">
|
|
||||||
<Value Profile="(Default)">E:\temp\SietasSheets</Value>
|
|
||||||
</Setting>
|
|
||||||
<Setting Name="POP3Server" Type="System.String" Scope="Application">
|
|
||||||
<Value Profile="(Default)" />
|
|
||||||
</Setting>
|
|
||||||
<Setting Name="POP3User" Type="System.String" Scope="Application">
|
|
||||||
<Value Profile="(Default)" />
|
|
||||||
</Setting>
|
|
||||||
<Setting Name="POP3Password" Type="System.String" Scope="Application">
|
|
||||||
<Value Profile="(Default)" />
|
|
||||||
</Setting>
|
|
||||||
<Setting Name="SleepSeconds" Type="System.Int32" Scope="Application">
|
<Setting Name="SleepSeconds" Type="System.Int32" Scope="Application">
|
||||||
<Value Profile="(Default)">300</Value>
|
<Value Profile="(Default)">300</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
|||||||
@ -958,33 +958,37 @@ namespace bsmd.ExcelReadService
|
|||||||
// lookup poc, imo, eta
|
// lookup poc, imo, eta
|
||||||
poc = reader.ReadText("Visit.PortOfCall");
|
poc = reader.ReadText("Visit.PortOfCall");
|
||||||
|
|
||||||
// Prüfen auf Transit
|
if (poc != null)
|
||||||
if (poc.ToUpper().Contains("CANAL"))
|
|
||||||
{
|
{
|
||||||
poc = "ZZNOK";
|
// Prüfen auf Transit
|
||||||
isTransit = true;
|
if (poc.ToUpper().Contains("CANAL"))
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Im Sheet könnte der Name statt des LOCODES stehen!
|
|
||||||
if (!RuleEngine.IsGermanLocode(poc))
|
|
||||||
{
|
{
|
||||||
// somehow lookup LOCODE from the port's name!
|
poc = "ZZNOK";
|
||||||
poc = LocodeDB.LocodeGERFromCity(poc);
|
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)
|
if (result == null)
|
||||||
|
|||||||
@ -9,12 +9,13 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
namespace bsmd.database
|
namespace bsmd.database
|
||||||
{
|
{
|
||||||
public class INFO : DatabaseEntity
|
public class INFO : DatabaseEntity
|
||||||
{
|
{
|
||||||
|
private static ILog _log = LogManager.GetLogger(typeof(INFO));
|
||||||
public INFO()
|
public INFO()
|
||||||
{
|
{
|
||||||
this.tablename = "[dbo].[INFO]";
|
this.tablename = "[dbo].[INFO]";
|
||||||
@ -148,32 +149,36 @@ namespace bsmd.database
|
|||||||
|
|
||||||
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
||||||
{
|
{
|
||||||
|
_log.InfoFormat("rule checking port area {0}", this.PortArea ?? "");
|
||||||
if (!this.PortArea.IsNullOrEmpty())
|
if (!this.PortArea.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
string key = this.MessageCore.PoC + this.PortArea;
|
string key = this.MessageCore.PoC + this.PortArea;
|
||||||
bool hasValue = DBManager.Instance.GetPortAreaDict().ContainsKey(key);
|
bool hasValue = DBManager.Instance.GetPortAreaDict().ContainsKey(key);
|
||||||
if (!hasValue)
|
if (!hasValue)
|
||||||
{
|
{
|
||||||
|
_log.WarnFormat("No port area entry found: PoC {0}, area {1}", this.MessageCore.PoC ?? "", this.PortArea ?? "");
|
||||||
if(this.MessageCore.PoC == null)
|
if(this.MessageCore.PoC == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (PortArea pa in DBManager.Instance.GetPortAreaDict().Values)
|
foreach (PortArea pa in DBManager.Instance.GetPortAreaDict().Values)
|
||||||
{
|
{
|
||||||
if (this.PortArea.Equals(pa.Code))
|
if (this.PortArea.Equals(pa.Code))
|
||||||
{
|
{
|
||||||
hasValue = true;
|
hasValue = true;
|
||||||
|
_log.InfoFormat("PoC null but port area found: {0} {1} {2}", pa.Name, pa.Country, pa.Port);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasValue) {
|
if (!hasValue) {
|
||||||
|
_log.WarnFormat("creating violation for invalid port area {0}", this.PortArea ?? "");
|
||||||
violations.Add(RuleEngine.CreateViolation(ValidationCode.PORTAREA,
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.PORTAREA,
|
||||||
string.Format("{0} is not in the list of valid port areas", this.PortArea),
|
string.Format("{0} is not in the list of valid port areas", this.PortArea),
|
||||||
null));
|
null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -22,7 +22,7 @@ namespace bsmd.email
|
|||||||
public class BSMDMail : IDisposable
|
public class BSMDMail : IDisposable
|
||||||
{
|
{
|
||||||
private SmtpClient client;
|
private SmtpClient client;
|
||||||
ILog log = LogManager.GetLogger(typeof(BSMDMail));
|
private static ILog log = LogManager.GetLogger(typeof(BSMDMail));
|
||||||
|
|
||||||
internal BSMDMail()
|
internal BSMDMail()
|
||||||
{
|
{
|
||||||
@ -42,11 +42,13 @@ namespace bsmd.email
|
|||||||
SslPolicyErrors sslPolicyErrors)
|
SslPolicyErrors sslPolicyErrors)
|
||||||
{ return true; };
|
{ return true; };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Synchrones Senden einer E-Mail
|
||||||
|
/// </summary>
|
||||||
internal void Send(MailMessage message)
|
internal void Send(MailMessage message)
|
||||||
{
|
{
|
||||||
// doch nicht asynchron, da nur eine Nachricht gleichzeitig geschickt werden kann und ich so den sync code spare
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.client.Send(message);
|
this.client.Send(message);
|
||||||
@ -60,63 +62,67 @@ namespace bsmd.email
|
|||||||
{
|
{
|
||||||
log.ErrorFormat("other error while sending e-mail:{0}", ex.Message);
|
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);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// sendet eine E-Mail mit Attachments (jetzt asynchron)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="subject">Betreffzeile</param>
|
||||||
|
/// <param name="filenameList">Liste von Dateien die angehängt werden sollen</param>
|
||||||
public static void SendNSWReportWithAttachments(string subject, List<string> filenameList)
|
public static void SendNSWReportWithAttachments(string subject, List<string> 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)
|
message.To.Add(recipient);
|
||||||
{
|
}
|
||||||
MailMessage message = new MailMessage();
|
|
||||||
MailAddress fromAddress = new MailAddress(Properties.Settings.Default.Sender);
|
|
||||||
|
|
||||||
message.From = fromAddress;
|
foreach (string filename in filenameList)
|
||||||
message.Subject = string.Format(subject);
|
{
|
||||||
message.IsBodyHtml = false;
|
Attachment attachment = new Attachment(filename, MediaTypeNames.Application.Octet);
|
||||||
message.Body = "see attachment";
|
ContentDisposition disposition = attachment.ContentDisposition;
|
||||||
message.To.Add(recipient);
|
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)
|
// mailer.Send(message);
|
||||||
{
|
|
||||||
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.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)
|
public static void SendSystemInfo(string subject, string body, string recipient)
|
||||||
{
|
{
|
||||||
using (BSMDMail mailer = new BSMDMail())
|
using (BSMDMail mailer = new BSMDMail())
|
||||||
@ -134,7 +140,47 @@ namespace bsmd.email
|
|||||||
|
|
||||||
mailer.Send(message);
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user