public sealed class RunicPathWatcher : IDisposable Watches files, symbolic links, directories and Git checkouts, and reports their changes in a model context.
Remarks
Events from FileSystemWatcher are debounced: a change is reported once no event arrived for RunicPathWatcherOptions.Debounce, or ten debounce intervals after the first event of a burst at the latest. The watcher then reads each affected target, and reports the targets whose state differs from the last reading, so noise such as a lock file next to a Git ref is not reported. A target that changes and changes back within that window is therefore not reported, except a RunicWatchTarget.File or RunicWatchTarget.Files, for which an event alone counts.
Both callbacks run in turns of the model context, so they can set ViewModel state directly. The watcher stops when it is disposed and when the context closes; no callback starts after RunicPathWatcher.Dispose returns in a turn of the context.
Where events cannot be trusted, the watcher reads its targets every RunicPathWatcherOptions.PollingInterval instead: on network, FUSE and virtiofs file systems, while a directory a target needs is missing, after a watch failed to start, and with RunicPathWatcherOptions.UsePolling. Otherwise it still reads them every 30 seconds, or every polling interval when that is longer, to recover from events the platform lost. It also watches the parent of each watched directory, so that a directory deleted and created again, as by rm -rf and git clone, is watched again at once.
Methods
Dispose
public void Dispose() Stops watching. Changes that were not reported yet are dropped.
Start
public static RunicPathWatcher Start(IRunicModelContext context, IEnumerable<RunicWatchTarget> targets, Action<RunicPathChange> changed, Action<RunicPathWatchError>? failed = null, RunicPathWatcherOptions? options = null) Starts watching targets.
Parameters
contextThe model context in which
changedandfailedrun.targetsThe targets; a change reports the instances that changed.
changedReceives each change in a turn of
context.failedReceives problems in a turn of
context: a missing directory, a checkout that is not a Git repository, lost events or a watch that could not start. The watcher keeps working, by polling where needed. Without a callback, problems are written toTraceas event 1015.optionsDebounce, polling and time; null uses the defaults.
Returns
The watcher; dispose it with the ViewModel that owns it.
Exceptions
ArgumentExceptionThere are no targets, or an option is out of range.
Remarks
The targets' current state is read before this method returns, and later changes are reported. Read the initial state after starting the watcher, so that a change in between is not lost.