Class CollectionLibrary
- Namespace
- EncDotNet.S100.Collections.Library
- Assembly
- EncDotNet.S100.Collections.dll
Owns a set of dataset collections (issue #655): persists their
definitions to a store file (collections.json), keeps each source's
index cached on disk, and re-indexes sources in the background without
loading any dataset. UI-free, so the viewer's Library and a headless host
(#792) share it.
public sealed class CollectionLibrary : IDisposable
- Inheritance
-
CollectionLibrary
- Implements
- Inherited Members
Remarks
State is exposed as immutable Collections snapshots plus a coarse Changed event, raised on whichever thread made the change; UI consumers marshal to their UI thread themselves.
Indexing runs one source at a time on a background worker. At start-up the cached indexes are loaded first (so the library is populated immediately) and every source is then refreshed; an unchanged source costs only a fingerprint check.
S-128 datasets loaded this session appear in a transient session collection (SessionCollectionName); KeepSessionCatalogue(Guid) turns one into a persisted collection.
Constructors
CollectionLibrary(CollectionIndexer, CollectionLibraryOptions, ILogger?, TimeProvider?)
Creates a library over the store and index cache named by options.
public CollectionLibrary(CollectionIndexer indexer, CollectionLibraryOptions options, ILogger? logger = null, TimeProvider? timeProvider = null)
Parameters
indexerCollectionIndexerIndexes each source.
optionsCollectionLibraryOptionsWhere the library persists, and how.
loggerILoggerLogs store, cache and indexing failures.
timeProviderTimeProviderThe clock for creation and index times (tests).
Fields
SessionCollectionId
The fixed id of the transient session collection.
public static readonly Guid SessionCollectionId
Field Value
Properties
Collections
The library: persisted collections in order, followed by the session collection when it has any catalogue.
public IReadOnlyList<LibraryCollection> Collections { get; }
Property Value
Methods
AddCollection(string, IEnumerable<CollectionSource>)
Creates a collection and queues its sources for indexing.
public DatasetCollection AddCollection(string name, IEnumerable<CollectionSource> sources)
Parameters
namestringsourcesIEnumerable<CollectionSource>
Returns
AddSessionCatalogue(string, string?, S128Dataset)
Shows a loaded S-128 dataset's product entries in the session
collection under label (replacing any previous
dataset with that label).
public void AddSessionCatalogue(string label, string? path, S128Dataset dataset)
Parameters
labelstringpathstringdatasetS128Dataset
AddSources(Guid, IEnumerable<CollectionSource>)
Adds sources to an existing collection and queues them for indexing.
public bool AddSources(Guid collectionId, IEnumerable<CollectionSource> sources)
Parameters
collectionIdGuidsourcesIEnumerable<CollectionSource>
Returns
- bool
False when the collection does not exist.
ClearSessionCatalogues()
Removes every session catalogue.
public void ClearSessionCatalogues()
Dispose()
Stops the background indexing worker.
public void Dispose()
Find(Guid)
Finds a collection by id in the current snapshot.
public LibraryCollection? Find(Guid collectionId)
Parameters
collectionIdGuid
Returns
Initialize()
Loads collections.json and starts the background worker, which
loads cached indexes and then refreshes every source. Idempotent.
public void Initialize()
KeepSessionCatalogue(Guid)
Persists the session catalogue with source id sourceId
as a new collection (named after its file) and removes it from the
session. Returns the new collection, or null when the
catalogue is unknown or has no file on disk.
public DatasetCollection? KeepSessionCatalogue(Guid sourceId)
Parameters
sourceIdGuid
Returns
Refresh(Guid?, Guid?)
Queues sources for re-indexing: every source when
collectionId is null, otherwise that collection's
sources (or just sourceId).
public void Refresh(Guid? collectionId = null, Guid? sourceId = null)
Parameters
RemoveCollection(Guid)
Removes a collection and its cached indexes. The referenced data is never touched.
public bool RemoveCollection(Guid collectionId)
Parameters
collectionIdGuid
Returns
RemoveSessionCatalogue(string)
Removes a session catalogue added with AddSessionCatalogue(string, string?, S128Dataset).
public bool RemoveSessionCatalogue(string label)
Parameters
labelstring
Returns
RemoveSource(Guid, Guid)
Removes one source from a collection, with its cached index.
public bool RemoveSource(Guid collectionId, Guid sourceId)
Parameters
Returns
RenameCollection(Guid, string)
Renames a collection.
public bool RenameCollection(Guid collectionId, string name)
Parameters
Returns
RenameSource(Guid, Guid, string)
Renames a source (its display name).
public bool RenameSource(Guid collectionId, Guid sourceId, string name)
Parameters
Returns
UpdateSource(Guid, CollectionSource)
Replaces a source's definition (for example a new group selection for a collection manifest), keeping its id and current index, and queues it for re-indexing.
public bool UpdateSource(Guid collectionId, CollectionSource source)
Parameters
collectionIdGuidsourceCollectionSource
Returns
- bool
False when the collection or source does not exist.
WhenIdle()
A task that completes when no indexing is queued or running (for tests and shutdown).
public Task WhenIdle()
Returns
Events
Changed
Raised after any change to Collections, on the changing thread.
public event EventHandler? Changed
Event Type
SourceIndexed
Raised on the indexing thread after a source has been indexed (or its previous index confirmed current), after Changed.
public event EventHandler<LibrarySourceIndexedEventArgs>? SourceIndexed