Documentation
Table of Contents

Class FileIntentCatalog

Namespace
IntentSharp.Catalog
Assembly
IntentSharp.Catalog.dll

A catalog loaded from a folder of .intent.json, .intent.yaml and *.intent.yml files (subfolders included by default), reloaded while the application runs. A FileSystemWatcher notices edits, waits until the folder has been quiet for DebounceInterval (250 ms by default), reads every file again, swaps in a new IntentCatalogSnapshot atomically and fires the change token. Callers never poll: IntentRuntime reads Current on every call, so the next call uses the new definitions.

public sealed class FileIntentCatalog : IIntentCatalog, IDisposable
Inheritance
object
FileIntentCatalog
Implements
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Extension Methods

Remarks

Loading never throws for content. A file with problems in some definitions keeps the good ones (and the last good version of each broken one); a file that fails as a whole keeps all of its previous definitions. So does a file that is still on disk but that the folder listing no longer shows, because the folder it is in cannot be listed. Problems are in Problems, with the file (relative to Folder) and the line, and are logged at Warning. A name defined in two files belongs to the file that comes first in path order.

The constructor starts watching and then performs the first load with synchronous file reads, so Current is ready when it returns and an edit made during that load is picked up by one more reload. Every later load (watcher or ReloadAsync(CancellationToken)) is asynchronous and never overlaps another. A relative folder is resolved against BaseDirectory, where files copied to the output directory land.

When the watcher reports an error (the folder was deleted or replaced, a network share dropped, or more changes arrived than it could buffer), the catalog reloads, starts a new watcher as soon as the folder exists again and then reloads every file. While the folder is missing, a load keeps the previous definitions and reports the missing folder as a problem. Dispose() stops watching.

Constructors

FileIntentCatalog(string, FileIntentCatalogOptions?, ILogger<FileIntentCatalog>?)

Opens the catalog over folder and loads every file before returning; it watches the folder unless WatchForChanges is false.

Properties

Current

The snapshot from the most recent load. Never null; the first load finishes before the constructor returns.

Folder

The full path of the folder definitions are loaded from.

Methods

Dispose()

Stops watching the folder and cancels a load in progress. Current keeps the last snapshot, and ReloadAsync(CancellationToken) throws ObjectDisposedException afterwards. Calling it more than once is safe.

GetChangeToken()

A token that fires once, after the next load publishes a snapshot (a reload after an edit or a call to ReloadAsync(CancellationToken)). Take a new token after it fires. A change callback that throws is logged at Warning and does not stop the reload.

ReloadAsync(CancellationToken)

Reads every definition file now and publishes a new snapshot (firing the change token). Content problems are reported in the snapshot. When the folder no longer exists, the snapshot keeps the previous definitions and reports that.