@ -17,7 +17,7 @@ namespace ZeroLevel.Services.FileSystem
private readonly HashSet < string > _extensions ;
public event Action < int > OnStartMovingFilesToTemporary = delegate { } ;
public event Action OnMovingFileToTemporary = delegate { } ;
public event Action < string , string > OnMovingFileToTemporary = delegate { } ;
public event Action OnCompleteMovingFilesToTemporary = delegate { } ;
private readonly bool _autoRemoveTempFileAfterCallback = false ;
@ -81,8 +81,11 @@ namespace ZeroLevel.Services.FileSystem
OnStartMovingFilesToTemporary ? . Invoke ( files . Length ) ;
foreach ( var file in files )
{
try
if ( ! File . Exists ( file ) )
{
Log . Warning ( $"[PeriodicFileSystemWatcher.CheckSourceFolder] Find '{file}' does not exists" ) ;
continue ;
}
Log . Debug ( $"[PeriodicFileSystemWatcher.CheckSourceFolder] Find new file {file}" ) ;
if ( FSUtils . IsFileLocked ( new FileInfo ( file ) ) )
{
@ -97,16 +100,13 @@ namespace ZeroLevel.Services.FileSystem
Log . SystemWarning ( $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to move file '{file}' to temporary directory '{_temporaryFolder}'. Without system error!" ) ;
continue ;
}
OnMovingFileToTemporary ? . Invoke ( file , tempFile ) ;
}
catch ( Exception ex )
{
Log . SystemError ( ex , $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to attempt to move file '{file}' to temporary directory '{_temporaryFolder}'" ) ;
continue ;
}
finally
{
OnMovingFileToTemporary ? . Invoke ( ) ;
}
Log . Debug ( $"[PeriodicFileSystemWatcher.CheckSourceFolder] Handle file {file}" ) ;
try
{
@ -116,6 +116,8 @@ namespace ZeroLevel.Services.FileSystem
{
Log . SystemError ( ex , $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault callback for file '{tempFile}'" ) ;
}
try
{
if ( _autoRemoveTempFileAfterCallback )
{
File . Delete ( tempFile ) ;
@ -123,7 +125,7 @@ namespace ZeroLevel.Services.FileSystem
}
catch ( Exception ex )
{
Log . SystemError ( ex , $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault proceed file {f ile}") ;
Log . SystemError ( ex , $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault delete file {tempF ile}") ;
}
}
OnCompleteMovingFilesToTemporary ? . Invoke ( ) ;