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">
|
||||
<value>replace me!</value>
|
||||
</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">
|
||||
<value>300</value>
|
||||
</setting>
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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")]
|
||||
|
||||
@ -5,18 +5,6 @@
|
||||
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">replace me!</Value>
|
||||
</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">
|
||||
<Value Profile="(Default)">300</Value>
|
||||
</Setting>
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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<MessageError> errors, List<MessageViolation> 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
|
||||
|
||||
@ -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; };
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Synchrones Senden einer E-Mail
|
||||
/// </summary>
|
||||
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);
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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)
|
||||
{
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user