2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-12-15 20:34:58 +01:00

Added Basic File Watched

Started structure of Status Service
Not Yet Tested
This commit is contained in:
2024-04-18 23:45:29 +10:00
parent ac30d3cd2a
commit 6f4330ef12
9 changed files with 137 additions and 32 deletions

View File

@@ -0,0 +1,40 @@
namespace Pulsar.Features;
public class FileWatcherService(IOptions<PulsarConfiguration> options, IFileHandlerService fileHandlerService) : IHostedService
{
private FileSystemWatcher watcher = null!;
public Task StartAsync(CancellationToken cancellationToken)
{
watcher = new FileSystemWatcher(options.Value.JournalDirectory)
{
EnableRaisingEvents = true,
IncludeSubdirectories = true
};
watcher.BeginInit();
watcher.Created += HandleFileChanged;
watcher.Changed += HandleFileChanged;
watcher.Renamed += HandleFileChanged; // ?
watcher.IncludeSubdirectories = false;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastWrite & NotifyFilters.Size & NotifyFilters.FileName;
watcher.EndInit();
return Task.CompletedTask;
}
private void HandleFileChanged(object sender, FileSystemEventArgs e)
{
fileHandlerService.HandleFile(e.FullPath);
}
public Task StopAsync(CancellationToken cancellationToken)
{
watcher.Dispose();
return Task.CompletedTask;
}
}