Fix PeriodicFileSystemWatcher

pull/1/head
unknown 4 years ago
parent 4dbd9fcede
commit c1cd0ef8e2

@ -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,41 +81,43 @@ namespace ZeroLevel.Services.FileSystem
OnStartMovingFilesToTemporary?.Invoke(files.Length);
foreach (var file in files)
{
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)))
{
continue;
}
string tempFile;
try
{
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Find new file {file}");
if (FSUtils.IsFileLocked(new FileInfo(file)))
{
continue;
}
string tempFile;
try
tempFile = MoveToTemporary(file);
if (string.IsNullOrWhiteSpace(tempFile))
{
tempFile = MoveToTemporary(file);
if (string.IsNullOrWhiteSpace(tempFile))
{
Log.SystemWarning($"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to move file '{file}' to temporary directory '{_temporaryFolder}'. Without system error!");
continue;
}
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to attempt to move file '{file}' to temporary directory '{_temporaryFolder}'");
Log.SystemWarning($"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to move file '{file}' to temporary directory '{_temporaryFolder}'. Without system error!");
continue;
}
finally
{
OnMovingFileToTemporary?.Invoke();
}
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Handle file {file}");
try
{
_callback(new FileMeta(Path.GetFileName(file), tempFile));
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault callback for file '{tempFile}'");
}
OnMovingFileToTemporary?.Invoke(file, tempFile);
}
catch (Exception ex)
{
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Failed to attempt to move file '{file}' to temporary directory '{_temporaryFolder}'");
continue;
}
Log.Debug($"[PeriodicFileSystemWatcher.CheckSourceFolder] Handle file {file}");
try
{
_callback(new FileMeta(Path.GetFileName(file), tempFile));
}
catch (Exception ex)
{
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 {file}");
Log.SystemError(ex, $"[PeriodicFileSystemWatcher.CheckSourceFolder] Fault delete file {tempFile}");
}
}
OnCompleteMovingFilesToTemporary?.Invoke();

@ -6,16 +6,16 @@
</Description>
<Authors>ogoun</Authors>
<Company>ogoun</Company>
<AssemblyVersion>3.3.4.6</AssemblyVersion>
<PackageReleaseNotes>Extended the MemoryStreamReader.</PackageReleaseNotes>
<AssemblyVersion>3.3.4.7</AssemblyVersion>
<PackageReleaseNotes>Fix PeriodicFileSystemWatcher</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/ogoun/Zero/wiki</PackageProjectUrl>
<Copyright>Copyright Ogoun 2020</Copyright>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageIconUrl></PackageIconUrl>
<RepositoryUrl>https://github.com/ogoun/Zero</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Version>3.3.4.6</Version>
<FileVersion>3.3.4.6</FileVersion>
<Version>3.3.4.7</Version>
<FileVersion>3.3.4.7</FileVersion>
<Platforms>AnyCPU;x64</Platforms>
<PackageIcon>zero.png</PackageIcon>
</PropertyGroup>

Loading…
Cancel
Save

Powered by TurnKey Linux.