|
|
@ -1,6 +1,8 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZeroLevel.Services.FileSystem
|
|
|
|
namespace ZeroLevel.Services.FileSystem
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -12,6 +14,7 @@ namespace ZeroLevel.Services.FileSystem
|
|
|
|
private readonly string _temporaryFolder;
|
|
|
|
private readonly string _temporaryFolder;
|
|
|
|
private readonly TimeSpan _period;
|
|
|
|
private readonly TimeSpan _period;
|
|
|
|
private readonly Action<FileMeta> _callback;
|
|
|
|
private readonly Action<FileMeta> _callback;
|
|
|
|
|
|
|
|
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 OnMovingFileToTemporary = delegate { };
|
|
|
@ -21,6 +24,7 @@ namespace ZeroLevel.Services.FileSystem
|
|
|
|
private readonly bool _useSubdirectories = false;
|
|
|
|
private readonly bool _useSubdirectories = false;
|
|
|
|
|
|
|
|
|
|
|
|
public PeriodicFileSystemWatcher(TimeSpan period, string watch_folder, string temp_folder, Action<FileMeta> callback
|
|
|
|
public PeriodicFileSystemWatcher(TimeSpan period, string watch_folder, string temp_folder, Action<FileMeta> callback
|
|
|
|
|
|
|
|
, IEnumerable<string> extensions = null
|
|
|
|
, bool removeTempFileAfterCallback = false
|
|
|
|
, bool removeTempFileAfterCallback = false
|
|
|
|
, bool useSubdirectories = false)
|
|
|
|
, bool useSubdirectories = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -32,13 +36,14 @@ namespace ZeroLevel.Services.FileSystem
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(callback));
|
|
|
|
throw new ArgumentNullException(nameof(callback));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_extensions = new HashSet<string>(extensions?.Select(e => e.ToLowerInvariant()) ?? Enumerable.Empty<string>());
|
|
|
|
_useSubdirectories = useSubdirectories;
|
|
|
|
_useSubdirectories = useSubdirectories;
|
|
|
|
_autoRemoveTempFileAfterCallback = removeTempFileAfterCallback;
|
|
|
|
_autoRemoveTempFileAfterCallback = removeTempFileAfterCallback;
|
|
|
|
_callback = callback;
|
|
|
|
_callback = callback;
|
|
|
|
_sourceFolder = watch_folder;
|
|
|
|
_sourceFolder = watch_folder;
|
|
|
|
_temporaryFolder = temp_folder;
|
|
|
|
_temporaryFolder = temp_folder;
|
|
|
|
_period = period;
|
|
|
|
_period = period;
|
|
|
|
if (_temporaryFolder.IndexOf(':') < 0)
|
|
|
|
if (Path.IsPathRooted(_temporaryFolder) == false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_temporaryFolder = Path.Combine(Configuration.BaseDirectory, _temporaryFolder);
|
|
|
|
_temporaryFolder = Path.Combine(Configuration.BaseDirectory, _temporaryFolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -171,11 +176,21 @@ namespace ZeroLevel.Services.FileSystem
|
|
|
|
/// Getting a list of files from the input directory
|
|
|
|
/// Getting a list of files from the input directory
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private string[] GetFilesFromSource()
|
|
|
|
private string[] GetFilesFromSource()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_extensions.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string[] files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
|
|
|
|
|
|
|
|
.Where(f => _extensions.Contains(Path.GetExtension(f).ToLowerInvariant())).ToArray();
|
|
|
|
|
|
|
|
Array.Sort<string>(files, FileNameSortCompare);
|
|
|
|
|
|
|
|
return files;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string[] files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
|
|
|
string[] files = Directory.GetFiles(_sourceFolder, "*.*", _useSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
|
|
|
Array.Sort<string>(files, FileNameSortCompare);
|
|
|
|
Array.Sort<string>(files, FileNameSortCompare);
|
|
|
|
return files;
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// File Name Comparison
|
|
|
|
/// File Name Comparison
|
|
|
|