diff --git a/nsw/Source/bsmd.POService/App.config b/nsw/Source/bsmd.POService/App.config
new file mode 100644
index 00000000..ed956b2c
--- /dev/null
+++ b/nsw/Source/bsmd.POService/App.config
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 30
+
+
+
+
+ guettner@bsmd.de
+ hsok@gmx.de
+
+
+
+
+
+
\ No newline at end of file
diff --git a/nsw/Source/bsmd.POService/POService.Designer.cs b/nsw/Source/bsmd.POService/POService.Designer.cs
new file mode 100644
index 00000000..78bfc2d1
--- /dev/null
+++ b/nsw/Source/bsmd.POService/POService.Designer.cs
@@ -0,0 +1,37 @@
+namespace bsmd.POService
+{
+ partial class POService
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ this.ServiceName = "Service1";
+ }
+
+ #endregion
+ }
+}
diff --git a/nsw/Source/bsmd.POService/POService.cs b/nsw/Source/bsmd.POService/POService.cs
new file mode 100644
index 00000000..4453c668
--- /dev/null
+++ b/nsw/Source/bsmd.POService/POService.cs
@@ -0,0 +1,227 @@
+// Copyright (c) 2020-present schick Informatik
+// Description:
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.ServiceProcess;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Timers;
+using bsmd.email;
+using bsmd.database;
+using log4net;
+
+namespace bsmd.POService
+{
+ public partial class POService : ServiceBase
+ {
+
+ #region Fields
+
+ private Timer _timer;
+ private readonly ILog _log = LogManager.GetLogger(typeof(POService));
+
+ #endregion
+
+ #region Construction
+
+ public POService()
+ {
+ Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
+ InitializeComponent();
+ }
+
+ #endregion
+
+ #region Start/Stop Service
+
+ protected override void OnStart(string[] args)
+ {
+ this.EventLog.Source = this.ServiceName;
+ this.EventLog.Log = "Application";
+ this.Init();
+ this.EventLog.WriteEntry("NSW PO Number Service started.", EventLogEntryType.Information);
+ System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
+ FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
+ string version = fvi.FileVersion;
+ _log.InfoFormat("Starting PO Number Service. v.{0} -------------- ", version);
+ this.DoOnce();
+ }
+
+ protected override void OnStop()
+ {
+ this._log.Info("Stopping PO Number Service");
+ }
+
+ #endregion
+
+ #region helper
+
+ private void Init()
+ {
+ this._timer = new Timer
+ {
+ Interval = Properties.Settings.Default.SleepSeconds * 1000
+ };
+ this._timer.Elapsed += _timer_Elapsed;
+ this._timer.Enabled = true;
+ }
+
+ internal void DoOnce()
+ {
+ this._timer_Elapsed(null, null);
+ }
+
+ internal static bool ParsePO(string inputValue)
+ {
+ bool result = false;
+
+ // Betreffzeile parsen. Ein Beispiel:
+ // "WG: PO:8204730095 DEWVNTM-ADELINA D-005E-310120";
+ // Hier kann man designen: https://regex101.com/
+ const string poPattern = @"PO:(\d+) ([A-Z]+)-(.*?)-(.*?)-(\d{6})";
+ Regex poRegex = new Regex(poPattern);
+ Match aMatch = poRegex.Match(inputValue);
+ if (aMatch.Success)
+ {
+ string poNummer = aMatch.Groups[1].Captures[0].Value;
+ string hafen = aMatch.Groups[2].Captures[0].Value;
+ string name = aMatch.Groups[3].Captures[0].Value;
+ string irgendwas = aMatch.Groups[4].Captures[0].Value;
+ string datumString = aMatch.Groups[5].Captures[0].Value;
+ result = true;
+ }
+
+ return result;
+ }
+
+ #endregion
+
+ private void _timer_Elapsed(object sender, ElapsedEventArgs e)
+ {
+
+ if (DBManager.Instance.Connect(Properties.Settings.Default.ConnectionString))
+ {
+
+ try
+ {
+ string messageId = "";
+ string attachmentLocalPath = null;
+ string mailSender = "";
+ const string receiptSubject = "PO number service INFO";
+ string mailSubject = "";
+ string body = "";
+
+ using (BSMDPopClient bsmdPopClient = new BSMDPopClient())
+ {
+ if (bsmdPopClient.IsConnected)
+ {
+ // check and download next e-Mail, saving attachment
+ while (bsmdPopClient.ReceiveSingleMailText(out messageId, out mailSender, out mailSubject, out body))
+ {
+
+ bool readResult = false;
+ string readMessage = "";
+ string receiptText = "";
+ MessageCore messageCore = null;
+
+ if (attachmentLocalPath == null)
+ {
+ receiptText = "incoming E-Mail did not contain an Excel attachment!";
+ _log.WarnFormat(receiptText);
+ }
+ else
+ {
+ // only a valid sender gets a reply
+ bool isValidSender = false;
+ foreach (string aValidSender in Properties.Settings.Default.ValidSender)
+ {
+ if (mailSender.Equals(aValidSender, StringComparison.OrdinalIgnoreCase))
+ {
+ isValidSender = true;
+ break;
+ }
+ }
+
+ if (!isValidSender)
+ {
+ receiptText = string.Format("ignored e - mail from illegal sender: {0}", mailSender);
+ _log.Warn(receiptText);
+ }
+ else
+ {
+ try
+ {
+ if(!ParsePO(mailSubject))
+ {
+
+ }
+
+
+ // aus (ungefährem) Datum, Name und Hafen den MessageCore suchen
+
+
+ // PO-Nummer und Schiffs/Anlaufklassifizierung eintragen
+
+
+ }
+ catch (Exception someException)
+ {
+ receiptText = string.Format("Error processing po mail: {0}", someException.Message);
+ _log.Error(receiptText);
+ }
+ }
+ }
+
+ if (receiptText.Length > 0)
+ {
+ _log.Debug("sending system info email");
+ BSMDMail.SendSystemInfo(receiptSubject, receiptText, mailSender);
+ }
+
+ // remove e-Mail
+ _log.InfoFormat("deleting mail with messageId {0}", messageId);
+ _log.InfoFormat("mail delete {0}", bsmdPopClient.DeleteMessageByMessageId(messageId) ? "successful" : "failed");
+
+ }
+ }
+ }
+
+ #region Phase II - Excel Sheets auf Anforderung erzeugen
+
+ List excelMessageCoreList = DBManager.Instance.GetMessageCoresForExcelCreate();
+ if (excelMessageCoreList.Count > 0)
+ _log.InfoFormat("{0} excel sheets to create from database", excelMessageCoreList.Count);
+ foreach (MessageCore excelCore in excelMessageCoreList)
+ {
+ // load messages
+ List messages = DBManager.Instance.GetMessagesForCore(excelCore, DBManager.MessageLoad.ALL);
+
+ // template
+
+ }
+
+ #endregion
+
+ DBManager.Instance.Disconnect();
+ }
+ catch (Exception ex)
+ {
+ _log.ErrorFormat("Exception occurred: {0}", ex.ToString());
+ }
+ }
+ else
+ {
+ _log.Error("DB Connection failure");
+ }
+
+ }
+
+ }
+}
diff --git a/nsw/Source/bsmd.POService/Program.cs b/nsw/Source/bsmd.POService/Program.cs
new file mode 100644
index 00000000..6fd2d191
--- /dev/null
+++ b/nsw/Source/bsmd.POService/Program.cs
@@ -0,0 +1,31 @@
+// Copyright (c) 2020-present schick Informatik
+// Description:
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.ServiceProcess;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bsmd.POService
+{
+ internal static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ public static void Main()
+ {
+ ServiceBase[] ServicesToRun;
+
+ log4net.Config.XmlConfigurator.Configure();
+
+ ServicesToRun = new ServiceBase[]
+ {
+ new POService()
+ };
+ ServiceBase.Run(ServicesToRun);
+ }
+ }
+}
diff --git a/nsw/Source/bsmd.POService/bsmd.POService.csproj b/nsw/Source/bsmd.POService/bsmd.POService.csproj
new file mode 100644
index 00000000..f08ebf7a
--- /dev/null
+++ b/nsw/Source/bsmd.POService/bsmd.POService.csproj
@@ -0,0 +1,94 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {7DCDEEB1-8192-4F82-8549-768F80776F04}
+ WinExe
+ bsmd.POService
+ bsmd.POService
+ v4.7.2
+ 512
+ true
+ false
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+ ..\..\..\..\mtc\puls200.frame\frame.ruleset
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ packages\log4net.2.0.8\lib\net45-full\log4net.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Properties\AssemblyProductInfo.cs
+
+
+ Properties\AssemblyProjectInfo.cs
+
+
+ Properties\AssemblyProjectKeyInfo.cs
+
+
+ True
+ True
+ Settings.settings
+
+
+ Component
+
+
+ POService.cs
+
+
+
+
+
+
+
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+
+
+ {19945af2-379b-46a5-b27a-303b5ec1d557}
+ bsmd.database
+
+
+ {4b48a8ad-926d-4e0c-beb3-59e040928137}
+ bsmd.email
+
+
+
+
\ No newline at end of file
diff --git a/nsw/Source/bsmd.POService/bsmd.POService.sln b/nsw/Source/bsmd.POService/bsmd.POService.sln
new file mode 100644
index 00000000..313cf47f
--- /dev/null
+++ b/nsw/Source/bsmd.POService/bsmd.POService.sln
@@ -0,0 +1,37 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29806.167
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.POService", "bsmd.POService.csproj", "{7DCDEEB1-8192-4F82-8549-768F80776F04}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.database", "..\bsmd.database\bsmd.database.csproj", "{19945AF2-379B-46A5-B27A-303B5EC1D557}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.email", "..\bsmd.email\bsmd.email.csproj", "{4B48A8AD-926D-4E0C-BEB3-59E040928137}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7DCDEEB1-8192-4F82-8549-768F80776F04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7DCDEEB1-8192-4F82-8549-768F80776F04}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7DCDEEB1-8192-4F82-8549-768F80776F04}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7DCDEEB1-8192-4F82-8549-768F80776F04}.Release|Any CPU.Build.0 = Release|Any CPU
+ {19945AF2-379B-46A5-B27A-303B5EC1D557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {19945AF2-379B-46A5-B27A-303B5EC1D557}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {19945AF2-379B-46A5-B27A-303B5EC1D557}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {19945AF2-379B-46A5-B27A-303B5EC1D557}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4B48A8AD-926D-4E0C-BEB3-59E040928137}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4B48A8AD-926D-4E0C-BEB3-59E040928137}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4B48A8AD-926D-4E0C-BEB3-59E040928137}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4B48A8AD-926D-4E0C-BEB3-59E040928137}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {FDDA69A2-BC62-40A3-891C-030FFB120992}
+ EndGlobalSection
+EndGlobal