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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.