|
|
@@ -1,4 +1,5 @@
|
|
|
using GSG.NET.Concurrent;
|
|
|
+using GSG.NET.FileSystem;
|
|
|
using GSG.NET.Logging;
|
|
|
using GSG.NET.PLC.KNC;
|
|
|
using GSG.NET.Utils;
|
|
|
@@ -6,6 +7,8 @@ using log4net.Appender;
|
|
|
using System;
|
|
|
using System.Configuration;
|
|
|
using System.Drawing;
|
|
|
+using System.IO;
|
|
|
+using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
namespace OHVDriveLogger
|
|
|
@@ -36,6 +39,8 @@ namespace OHVDriveLogger
|
|
|
this.Load += FormMain_Load;
|
|
|
this.FormClosing += FormMain_FormClosing;
|
|
|
|
|
|
+ MidnightNotifier.DayChanged += MidnightNotifier_DayChanged;
|
|
|
+
|
|
|
this.vehicleID = ConfigurationManager.AppSettings["VehicleID"];
|
|
|
this.UploadIP = ConfigurationManager.AppSettings["FTPUploadIP"];
|
|
|
this.PLCAddress = ConfigurationManager.AppSettings["PLC_IP"];
|
|
|
@@ -45,6 +50,13 @@ namespace OHVDriveLogger
|
|
|
FTPLogger.Instance.PLCAddress = this.PLCAddress;
|
|
|
}
|
|
|
|
|
|
+ private void MidnightNotifier_DayChanged( object sender, EventArgs e )
|
|
|
+ {
|
|
|
+ logger.I( "자정 Event Occur" );
|
|
|
+ Task.Run( () => { DeleteNoBackupFiles( @"c:\LOG\OHV\DriveLogger\", 2 ); } );
|
|
|
+ Task.Run( () => { DeleteNoBackupFiles( @"c:\LOG\OHV\Vehicle\", 2 ); } );
|
|
|
+ }
|
|
|
+
|
|
|
private void FormMain_FormClosing( object sender, FormClosingEventArgs e )
|
|
|
{
|
|
|
this.threadCancel.Cancel();
|
|
|
@@ -109,8 +121,6 @@ namespace OHVDriveLogger
|
|
|
plc.WriteBit( "DRIVE_LOGGING_ONOFF", false );
|
|
|
else
|
|
|
plc.WriteBit( "DRIVE_LOGGING_ONOFF", true );
|
|
|
-
|
|
|
- //logger.I( $"Test" );
|
|
|
}
|
|
|
|
|
|
void Th_DoWorker()
|
|
|
@@ -212,5 +222,49 @@ namespace OHVDriveLogger
|
|
|
{
|
|
|
this.Close();
|
|
|
}
|
|
|
+
|
|
|
+ void DeleteNoBackupFiles(string directoryPath, int backupDays )
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var dt = DateTime.Now.AddDays( -backupDays );
|
|
|
+ int delCount = 0;
|
|
|
+
|
|
|
+ foreach ( string path in FileUtils.GetFiles( directoryPath, "*", false ) )
|
|
|
+ {
|
|
|
+ var fi = new FileInfo( path );
|
|
|
+ if ( fi.LastWriteTime > dt )
|
|
|
+ continue;
|
|
|
+
|
|
|
+ FileUtils.DeleteFileIfExist( path );
|
|
|
+ delCount++;
|
|
|
+ logger.D( $"Deleted File - Name : [ {fi.Name} ]" );
|
|
|
+
|
|
|
+ if ( delCount > 2 )
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //if ( !IsFolderMakeDay )
|
|
|
+ // return;
|
|
|
+
|
|
|
+ //foreach ( string item in FileUtils.GetFolders( FolderRoot, false ) )
|
|
|
+ //{
|
|
|
+ // var ct = Directory.GetCreationTime( item );
|
|
|
+ // if ( ct > dt )
|
|
|
+ // continue;
|
|
|
+
|
|
|
+ // int cnt = FileUtils.GetFiles( item, "*", false ).Length;
|
|
|
+ // if ( cnt > 0 )
|
|
|
+ // continue;
|
|
|
+
|
|
|
+ // Directory.Delete( item );
|
|
|
+ //}
|
|
|
+
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|