Added Events, Filters, and IncludeSubdirectories to fileupdate call type
This commit is contained in:
@@ -280,11 +280,22 @@ public class FileUpdateCall : ICall
|
||||
{
|
||||
throw new IndexerConfigurationException($"Path not set for a Call in Worker \"{Worker.Name}\"");
|
||||
}
|
||||
|
||||
List<string> events = callConfig.Events ?? [];
|
||||
bool allEvents = events.Count == 0;
|
||||
List<string> filters = callConfig.Filters ?? [];
|
||||
bool includeSubdirectories = callConfig.IncludeSubdirectories ?? false;
|
||||
|
||||
_watcher = new FileSystemWatcher(CallConfig.Path);
|
||||
_watcher.Created += OnFileChanged;
|
||||
_watcher.Changed += OnFileChanged;
|
||||
_watcher.Deleted += OnFileChanged;
|
||||
_watcher.Renamed += OnFileChanged;
|
||||
if (allEvents || events.Contains("Created")) _watcher.Created += OnFileChanged;
|
||||
if (allEvents || events.Contains("Changed")) _watcher.Changed += OnFileChanged;
|
||||
if (allEvents || events.Contains("Deleted")) _watcher.Deleted += OnFileChanged;
|
||||
if (allEvents || events.Contains("Renamed")) _watcher.Renamed += OnFileChanged;
|
||||
foreach (string filter in filters)
|
||||
{
|
||||
_watcher.Filters.Add(filter);
|
||||
}
|
||||
_watcher.IncludeSubdirectories = includeSubdirectories;
|
||||
_watcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
|
||||
namespace Indexer.Models;
|
||||
|
||||
public class CallConfig
|
||||
{
|
||||
public required string Type { get; set; }
|
||||
public long? Interval { get; set; } // For Type: Interval
|
||||
public string? Path { get; set; } // For Type: FileSystemWatcher
|
||||
public string? Schedule { get; set; } // For Type: Schedule
|
||||
public List<string>? Events { get; set; } // For Type: Schedule
|
||||
public List<string>? Filters { get; set; } // For Type: Schedule
|
||||
public bool? IncludeSubdirectories { get; set; } // For Type: Schedule
|
||||
}
|
||||
public interface ICall
|
||||
{
|
||||
|
||||
@@ -34,7 +34,10 @@
|
||||
},
|
||||
{
|
||||
"Type": "fileupdate",
|
||||
"Path": "./Scripts/example_content"
|
||||
"Path": "./Scripts/example_content",
|
||||
"Events": ["Created", "Changed", "Deleted", "Renamed"],
|
||||
"Filters": ["*.md", "*.txt"],
|
||||
"IncludeSubdirectories": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user