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,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 {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.