This site provides a machine-readable index at /llms.txt.

Skip to main content Skip to navigation

FileWatcher Pennington.Infrastructure

Manages FileSystemWatcher instances and notifies subscribers of changes.

Constructors

.ctor

#
public FileWatcher(IFileSystem fileSystem, ILogger<FileWatcher>? logger = null);

Initializes the watcher with a filesystem abstraction and optional logger.

Parameters

fileSystem IFileSystem
logger ILogger<FileWatcher>? (optional)

Methods

AddPathWatch

#
public void AddPathWatch(string path, string filePattern, Action<string, WatcherChangeTypes> onFileChanged, bool includeSubdirectories = true);

Watch a path for file changes matching a pattern.

Parameters

path string
filePattern string
onFileChanged Action<string, WatcherChangeTypes>
includeSubdirectories bool (optional)

Dispose

#
public void Dispose();

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

SubscribeToChanges

#
public void SubscribeToChanges(Action onUpdate);

Subscribe to be notified when any watched file changes.

Parameters

onUpdate Action

SubscribeToChanges

#
public void SubscribeToChanges(Action<FileChangeNotification> onUpdate);

Subscribe to be notified when any watched file changes, with the changed path and change type.

Parameters

onUpdate Action<FileChangeNotification>

Pennington.Infrastructure.FileWatcher

namespace Pennington.Infrastructure;

/// Manages FileSystemWatcher instances and notifies subscribers of changes.
public class FileWatcher
{
    /// Initializes the watcher with a filesystem abstraction and optional logger.
    
public FileWatcher(IFileSystem fileSystem, ILogger<FileWatcher>? logger = null);
/// Watch a path for file changes matching a pattern.
public void AddPathWatch(string path, string filePattern, Action<string, WatcherChangeTypes> onFileChanged, bool includeSubdirectories = true);
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose();
/// Subscribe to be notified when any watched file changes.
public void SubscribeToChanges(Action onUpdate);
/// Subscribe to be notified when any watched file changes, with the changed path and change type.
public void SubscribeToChanges(Action<FileChangeNotification> onUpdate);
}