Merge branch 'feature/purge_transmission_files' into feature/eni_7.10
This commit is contained in:
commit
dc9329bedf
@ -34,6 +34,12 @@
|
||||
<setting name="ConnectionString" serializeAs="String">
|
||||
<value>Initial Catalog=nswtest;Data Source=192.168.2.24\SQLEXPRESS;Uid=dfuser;pwd=dfpasswd;Persist Security Info=False;Connection Reset=false</value>
|
||||
</setting>
|
||||
<setting name="PurgeFilesTimerIntervalHours" serializeAs="String">
|
||||
<value>24</value>
|
||||
</setting>
|
||||
<setting name="TempFilesMaxAgeDays" serializeAs="String">
|
||||
<value>10</value>
|
||||
</setting>
|
||||
</SendNSWMessageService.Properties.Settings>
|
||||
</applicationSettings>
|
||||
</configuration>
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,5 +8,11 @@
|
||||
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">Initial Catalog=nswtest;Data Source=192.168.2.24\SQLEXPRESS;Uid=dfuser;pwd=dfpasswd;Persist Security Info=False;Connection Reset=false</Value>
|
||||
</Setting>
|
||||
<Setting Name="PurgeFilesTimerIntervalHours" Type="System.Int32" Scope="Application">
|
||||
<Value Profile="(Default)">24</Value>
|
||||
</Setting>
|
||||
<Setting Name="TempFilesMaxAgeDays" Type="System.Int32" Scope="Application">
|
||||
<Value Profile="(Default)">10</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@ -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,50 @@ namespace bsmd.dbh
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Purge old files
|
||||
|
||||
public static void PurgeOldFiles(int maxAgeDays)
|
||||
{
|
||||
try
|
||||
{
|
||||
int cnt = 0;
|
||||
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();
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
_log.Info($"deleted {cnt} files from {Properties.Settings.Default.IncomingArchiveFolder}");
|
||||
|
||||
cnt = 0;
|
||||
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();
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
_log.Info($"deleted {cnt} files from {Properties.Settings.Default.OutgoingArchiveFolder}");
|
||||
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_log.ErrorFormat("Error deleting old files: {0}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
12
bsmd.hisnord/Properties/Settings.Designer.cs
generated
12
bsmd.hisnord/Properties/Settings.Designer.cs
generated
@ -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"]));
|
||||
|
||||
@ -6,22 +6,22 @@
|
||||
<Value Profile="(Default)">1</Value>
|
||||
</Setting>
|
||||
<Setting Name="OutputDir" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\IMP</Value>
|
||||
<Value Profile="(Default)">Transmitter-Tool\IMP</Value>
|
||||
</Setting>
|
||||
<Setting Name="Transmitter" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\client.bat</Value>
|
||||
<Value Profile="(Default)">Transmitter-Tool\client.bat</Value>
|
||||
</Setting>
|
||||
<Setting Name="ResultDir" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\RESULTS</Value>
|
||||
<Value Profile="(Default)">Transmitter-Tool\RESULTS</Value>
|
||||
</Setting>
|
||||
<Setting Name="AnswerDir" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS</Value>
|
||||
<Value Profile="(Default)">Transmitter-Tool\ANSWERS</Value>
|
||||
</Setting>
|
||||
<Setting Name="AnswerArchiveDir" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_DONE</Value>
|
||||
<Value Profile="(Default)">Transmitter-Tool\ANSWERS_DONE</Value>
|
||||
</Setting>
|
||||
<Setting Name="AnswerCorruptDir" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_CORRUPT</Value>
|
||||
<Value Profile="(Default)">Transmitter-Tool\ANSWERS_CORRUPT</Value>
|
||||
</Setting>
|
||||
<Setting Name="TransmitterRoot" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">E:\svnlager\BSMD\nsw\HIS-NORD\</Value>
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -11,22 +11,22 @@
|
||||
<value>1</value>
|
||||
</setting>
|
||||
<setting name="OutputDir" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\IMP</value>
|
||||
<value>Transmitter-Tool\IMP</value>
|
||||
</setting>
|
||||
<setting name="Transmitter" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\client.bat</value>
|
||||
<value>Transmitter-Tool\client.bat</value>
|
||||
</setting>
|
||||
<setting name="ResultDir" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\RESULTS</value>
|
||||
<value>Transmitter-Tool\RESULTS</value>
|
||||
</setting>
|
||||
<setting name="AnswerDir" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS</value>
|
||||
<value>Transmitter-Tool\ANSWERS</value>
|
||||
</setting>
|
||||
<setting name="AnswerArchiveDir" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_DONE</value>
|
||||
<value>Transmitter-Tool\ANSWERS_DONE</value>
|
||||
</setting>
|
||||
<setting name="AnswerCorruptDir" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\Transmitter-Tool\ANSWERS_CORRUPT</value>
|
||||
<value>Transmitter-Tool\ANSWERS_CORRUPT</value>
|
||||
</setting>
|
||||
<setting name="TransmitterRoot" serializeAs="String">
|
||||
<value>E:\svnlager\BSMD\nsw\HIS-NORD\</value>
|
||||
|
||||
@ -61,7 +61,7 @@ namespace bsmd.hisnord
|
||||
// _log.DebugFormat("started {0}", transmitterProcess.ProcessName);
|
||||
int timeout = Properties.Settings.Default.BatchTimeoutMins * 1000 * 60; // convert to ms
|
||||
|
||||
_log.InfoFormat($"starting transmitter, process ID: {processId}, timeout {timeout} ms.");
|
||||
_log.DebugFormat($"starting transmitter, process ID: {processId}, timeout {timeout} ms.");
|
||||
|
||||
if (!transmitterProcess.WaitForExit((timeout == 0) ? int.MaxValue : timeout))
|
||||
{
|
||||
@ -84,7 +84,7 @@ namespace bsmd.hisnord
|
||||
private static void TransmitterProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if(!e.Data.IsNullOrEmpty())
|
||||
_log.Info(e.Data);
|
||||
_log.Debug(e.Data);
|
||||
}
|
||||
|
||||
private static void TransmitterProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
@ -95,7 +95,7 @@ namespace bsmd.hisnord
|
||||
|
||||
private static void TransmitterProcess_Exited(object sender, EventArgs e)
|
||||
{
|
||||
_log.Info("Transmitter process exited");
|
||||
_log.Debug("Transmitter process exited");
|
||||
processId = null;
|
||||
}
|
||||
|
||||
@ -106,8 +106,63 @@ 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)
|
||||
{
|
||||
try
|
||||
{
|
||||
// "ANSWERS_DONE"
|
||||
DirectoryInfo info = new DirectoryInfo(Path.Combine(Properties.Settings.Default.TransmitterRoot, Properties.Settings.Default.AnswerArchiveDir));
|
||||
FileInfo[] files = info.GetFiles();
|
||||
int cnt = 0;
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
|
||||
{
|
||||
_log.Debug($"deleting {file.Name}");
|
||||
file.Delete();
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
_log.Info($"deleted {cnt} files from {Properties.Settings.Default.AnswerArchiveDir}");
|
||||
|
||||
// "RESULTS"
|
||||
cnt = 0;
|
||||
info = new DirectoryInfo(Path.Combine(Properties.Settings.Default.TransmitterRoot, Properties.Settings.Default.ResultDir));
|
||||
files = info.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
if (file.CreationTime < DateTime.Now.AddDays(-maxAgeDays))
|
||||
{
|
||||
_log.Debug($"deleting {file.Name}");
|
||||
file.Delete();
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
_log.Info($"deleted {cnt} files from {Properties.Settings.Default.ResultDir}");
|
||||
|
||||
// "READY"
|
||||
cnt = 0;
|
||||
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();
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
_log.Info($"deleted {cnt} files from READY");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_log.ErrorFormat("Error trying to delete old files: {0}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// class to read transmitter result xml files
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user