diff --git a/SendNSWMessageService/App.config b/SendNSWMessageService/App.config
index 011014da..b417c5bb 100644
--- a/SendNSWMessageService/App.config
+++ b/SendNSWMessageService/App.config
@@ -34,6 +34,12 @@
Initial Catalog=nswtest;Data Source=192.168.2.24\SQLEXPRESS;Uid=dfuser;pwd=dfpasswd;Persist Security Info=False;Connection Reset=false
+
+ 24
+
+
+ 10
+
diff --git a/SendNSWMessageService/NSWSendService.cs b/SendNSWMessageService/NSWSendService.cs
index 8d2e3b58..91056ea6 100644
--- a/SendNSWMessageService/NSWSendService.cs
+++ b/SendNSWMessageService/NSWSendService.cs
@@ -13,6 +13,7 @@ namespace SendNSWMessageService
public partial class NSWSendService : ServiceBase
{
private Timer _timer;
+ private Timer _filesTimer;
private readonly object _timerlock = new object();
private bool processRunning = false;
private readonly ILog _log = LogManager.GetLogger(typeof(NSWSendService));
@@ -62,11 +63,23 @@ namespace SendNSWMessageService
this._timer = new Timer();
this._timer.Interval = Properties.Settings.Default.SleepSeconds * 1000;
this._timer.Elapsed += _timer_Elapsed;
- this._timer.Enabled = true;
+ this._timer.Enabled = true;
+
+ this._filesTimer = new Timer();
+ this._filesTimer.Interval = Properties.Settings.Default.PurgeFilesTimerIntervalHours * 60 * 60 * 1000; // hours to millisecs
+ this._filesTimer.Elapsed += _filesTimer_Elapsed;
+ this._filesTimer.Enabled = true;
+ }
+
+ private void _filesTimer_Elapsed(object sender, ElapsedEventArgs e)
+ {
+ bsmd.dbh.MessageController.PurgeOldFiles(Properties.Settings.Default.TempFilesMaxAgeDays);
+ bsmd.hisnord.transmitter.PurgeOldFiles(Properties.Settings.Default.TempFilesMaxAgeDays);
}
public void DoOnce()
{
+ this._filesTimer_Elapsed(null, null);
this._timer_Elapsed(null, null);
}
@@ -307,17 +320,20 @@ namespace SendNSWMessageService
protected override void OnPause()
{
- this._timer.Stop();
+ this._timer.Stop();
+ this._filesTimer.Stop();
}
protected override void OnContinue()
{
- this._timer.Start();
+ this._timer.Start();
+ this._filesTimer.Start();
}
protected override void OnStop()
{
this._timer.Enabled = false;
+ this._filesTimer.Enabled = false;
this.EventLog.WriteEntry("NSW Send Service stopped.", EventLogEntryType.Information);
_log.Info("NSW Send Service stopped");
}
diff --git a/SendNSWMessageService/Properties/Settings.Designer.cs b/SendNSWMessageService/Properties/Settings.Designer.cs
index 1d06180c..79b6785d 100644
--- a/SendNSWMessageService/Properties/Settings.Designer.cs
+++ b/SendNSWMessageService/Properties/Settings.Designer.cs
@@ -41,5 +41,23 @@ namespace SendNSWMessageService.Properties {
return ((string)(this["ConnectionString"]));
}
}
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("24")]
+ public int PurgeFilesTimerIntervalHours {
+ get {
+ return ((int)(this["PurgeFilesTimerIntervalHours"]));
+ }
+ }
+
+ [global::System.Configuration.ApplicationScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("10")]
+ public int TempFilesMaxAgeDays {
+ get {
+ return ((int)(this["TempFilesMaxAgeDays"]));
+ }
+ }
}
}
diff --git a/SendNSWMessageService/Properties/Settings.settings b/SendNSWMessageService/Properties/Settings.settings
index 8b3df149..ab3581d9 100644
--- a/SendNSWMessageService/Properties/Settings.settings
+++ b/SendNSWMessageService/Properties/Settings.settings
@@ -8,5 +8,11 @@
Initial Catalog=nswtest;Data Source=192.168.2.24\SQLEXPRESS;Uid=dfuser;pwd=dfpasswd;Persist Security Info=False;Connection Reset=false
+
+ 24
+
+
+ 10
+
\ No newline at end of file
diff --git a/bsmd.dbh/MessageController.cs b/bsmd.dbh/MessageController.cs
index 77226721..d674f590 100644
--- a/bsmd.dbh/MessageController.cs
+++ b/bsmd.dbh/MessageController.cs
@@ -6,6 +6,7 @@ using System;
using System.IO;
using bsmd.database;
+using System.Linq;
namespace bsmd.dbh
{
@@ -14,6 +15,8 @@ namespace bsmd.dbh
private static readonly ILog _log = LogManager.GetLogger(typeof(MessageController));
private static int? _fileSequenceCounter = null;
+ #region send single message
+
public static bool SendMessage(MessageCore core, Message message)
{
bool result = true;
@@ -63,6 +66,10 @@ namespace bsmd.dbh
return result;
}
+ #endregion
+
+ #region send cancel core messaage
+
public static bool SendCancelCore(MessageCore core)
{
bool result = true;
@@ -103,6 +110,10 @@ namespace bsmd.dbh
return result;
}
+ #endregion
+
+ #region send and receive files (SFTP)
+
public static void SendAndReceive()
{
// sent unsent messages in output folder
@@ -144,5 +155,35 @@ namespace bsmd.dbh
}
}
+ #endregion
+
+ #region Purge old files
+
+ public static void PurgeOldFiles(int maxAgeDays)
+ {
+ DirectoryInfo info = new DirectoryInfo(Properties.Settings.Default.IncomingArchiveFolder);
+ FileInfo[] files = info.GetFiles();
+ foreach (FileInfo file in files)
+ {
+ if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
+ {
+ _log.Debug($"deleting {file.Name}");
+ file.Delete();
+ }
+ }
+ info = new DirectoryInfo(Properties.Settings.Default.OutgoingArchiveFolder);
+ files = info.GetFiles();
+ foreach (FileInfo file in files)
+ {
+ if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
+ {
+ _log.Debug($"deleting {file.Name}");
+ file.Delete();
+ }
+ }
+ }
+
+ #endregion
+
}
}
diff --git a/bsmd.hisnord/Properties/Settings.Designer.cs b/bsmd.hisnord/Properties/Settings.Designer.cs
index 54f77b9b..5dc16adc 100644
--- a/bsmd.hisnord/Properties/Settings.Designer.cs
+++ b/bsmd.hisnord/Properties/Settings.Designer.cs
@@ -34,7 +34,7 @@ namespace bsmd.hisnord.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("E:\\svnlager\\BSMD\\nsw\\HIS-NORD\\Transmitter-Tool\\IMP")]
+ [global::System.Configuration.DefaultSettingValueAttribute("Transmitter-Tool\\IMP")]
public string OutputDir {
get {
return ((string)(this["OutputDir"]));
@@ -43,7 +43,7 @@ namespace bsmd.hisnord.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("E:\\svnlager\\BSMD\\nsw\\HIS-NORD\\Transmitter-Tool\\client.bat")]
+ [global::System.Configuration.DefaultSettingValueAttribute("Transmitter-Tool\\client.bat")]
public string Transmitter {
get {
return ((string)(this["Transmitter"]));
@@ -52,7 +52,7 @@ namespace bsmd.hisnord.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("E:\\svnlager\\BSMD\\nsw\\HIS-NORD\\Transmitter-Tool\\RESULTS")]
+ [global::System.Configuration.DefaultSettingValueAttribute("Transmitter-Tool\\RESULTS")]
public string ResultDir {
get {
return ((string)(this["ResultDir"]));
@@ -61,7 +61,7 @@ namespace bsmd.hisnord.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("E:\\svnlager\\BSMD\\nsw\\HIS-NORD\\Transmitter-Tool\\ANSWERS")]
+ [global::System.Configuration.DefaultSettingValueAttribute("Transmitter-Tool\\ANSWERS")]
public string AnswerDir {
get {
return ((string)(this["AnswerDir"]));
@@ -70,7 +70,7 @@ namespace bsmd.hisnord.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("E:\\svnlager\\BSMD\\nsw\\HIS-NORD\\Transmitter-Tool\\ANSWERS_DONE")]
+ [global::System.Configuration.DefaultSettingValueAttribute("Transmitter-Tool\\ANSWERS_DONE")]
public string AnswerArchiveDir {
get {
return ((string)(this["AnswerArchiveDir"]));
@@ -79,7 +79,7 @@ namespace bsmd.hisnord.Properties {
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Configuration.DefaultSettingValueAttribute("E:\\svnlager\\BSMD\\nsw\\HIS-NORD\\Transmitter-Tool\\ANSWERS_CORRUPT")]
+ [global::System.Configuration.DefaultSettingValueAttribute("Transmitter-Tool\\ANSWERS_CORRUPT")]
public string AnswerCorruptDir {
get {
return ((string)(this["AnswerCorruptDir"]));
diff --git a/bsmd.hisnord/Properties/Settings.settings b/bsmd.hisnord/Properties/Settings.settings
index 6e8b3071..738f5594 100644
--- a/bsmd.hisnord/Properties/Settings.settings
+++ b/bsmd.hisnord/Properties/Settings.settings
@@ -6,22 +6,22 @@
1
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\IMP
+ Transmitter-Tool\IMP
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\client.bat
+ Transmitter-Tool\client.bat
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\RESULTS
+ Transmitter-Tool\RESULTS
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS
+ Transmitter-Tool\ANSWERS
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_DONE
+ Transmitter-Tool\ANSWERS_DONE
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_CORRUPT
+ Transmitter-Tool\ANSWERS_CORRUPT
E:\svnlager\BSMD\nsw\HIS-NORD\
diff --git a/bsmd.hisnord/Request.cs b/bsmd.hisnord/Request.cs
index 8f2a0974..f33f215c 100644
--- a/bsmd.hisnord/Request.cs
+++ b/bsmd.hisnord/Request.cs
@@ -74,7 +74,9 @@ namespace bsmd.hisnord
}
}
- }
+ }
+
+ #region Create message file to send
public static bool? CreateSendFile(MessageCore core, Message message)
{
@@ -1807,7 +1809,9 @@ namespace bsmd.hisnord
}
return retval;
- }
+ }
+
+ #endregion
#region helper func for HAZ positions
diff --git a/bsmd.hisnord/app.config b/bsmd.hisnord/app.config
index ca96bc37..a288eeed 100644
--- a/bsmd.hisnord/app.config
+++ b/bsmd.hisnord/app.config
@@ -11,22 +11,22 @@
1
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\IMP
+ Transmitter-Tool\IMP
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\client.bat
+ Transmitter-Tool\client.bat
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\RESULTS
+ Transmitter-Tool\RESULTS
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS
+ Transmitter-Tool\ANSWERS
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_DONE
+ Transmitter-Tool\ANSWERS_DONE
- E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_CORRUPT
+ Transmitter-Tool\ANSWERS_CORRUPT
E:\svnlager\BSMD\nsw\HIS-NORD\
diff --git a/bsmd.hisnord/transmitter.cs b/bsmd.hisnord/transmitter.cs
index d0b7d117..4ceefbe8 100644
--- a/bsmd.hisnord/transmitter.cs
+++ b/bsmd.hisnord/transmitter.cs
@@ -106,8 +106,45 @@ namespace bsmd.hisnord
string resultDir = Path.Combine(Properties.Settings.Default.TransmitterRoot, Properties.Settings.Default.ResultDir);
string resultFullPath = Path.Combine(resultDir, resultFilename);
return result.ReadResult(resultFullPath);
- }
-
+ }
+
+ public static void PurgeOldFiles(int maxAgeDays)
+ {
+ // "ANSWERS_DONE"
+ DirectoryInfo info = new DirectoryInfo(Path.Combine(Properties.Settings.Default.TransmitterRoot, Properties.Settings.Default.AnswerArchiveDir));
+ FileInfo[] files = info.GetFiles();
+ foreach (FileInfo file in files)
+ {
+ if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
+ {
+ _log.Debug($"deleting {file.Name}");
+ file.Delete();
+ }
+ }
+
+ info = new DirectoryInfo(Path.Combine(Properties.Settings.Default.TransmitterRoot, Properties.Settings.Default.ResultDir)); // "RESULTS"
+ files = info.GetFiles();
+ foreach (FileInfo file in files)
+ {
+ if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
+ {
+ _log.Debug($"deleting {file.Name}");
+ file.Delete();
+ }
+ }
+
+ info = new DirectoryInfo(Path.Combine(Properties.Settings.Default.TransmitterRoot, "READY"));
+ files = info.GetFiles();
+ foreach (FileInfo file in files)
+ {
+ if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
+ {
+ _log.Debug($"deleting {file.Name}");
+ file.Delete();
+ }
+ }
+ }
+
///
/// class to read transmitter result xml files
///