Table of Contents

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

indexer CollectionIndexer

Indexes each source.

options CollectionLibraryOptions

Where the library persists, and how.

logger ILogger

Logs store, cache and indexing failures.

timeProvider TimeProvider

The clock for creation and index times (tests).

Fields

SessionCollectionId

The fixed id of the transient session collection.

public static readonly Guid SessionCollectionId

Field Value

Guid

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

IReadOnlyList<LibraryCollection>

Methods

AddCollection(string, IEnumerable<CollectionSource>)

Creates a collection and queues its sources for indexing.

public DatasetCollection AddCollection(string name, IEnumerable<CollectionSource> sources)

Parameters

name string
sources IEnumerable<CollectionSource>

Returns

DatasetCollection

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

label string
path string
dataset S128Dataset

AddSources(Guid, IEnumerable<CollectionSource>)

Adds sources to an existing collection and queues them for indexing.

public bool AddSources(Guid collectionId, IEnumerable<CollectionSource> sources)

Parameters

collectionId Guid
sources IEnumerable<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

collectionId Guid

Returns

LibraryCollection

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

sourceId Guid

Returns

DatasetCollection

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

collectionId Guid?
sourceId Guid?

RemoveCollection(Guid)

Removes a collection and its cached indexes. The referenced data is never touched.

public bool RemoveCollection(Guid collectionId)

Parameters

collectionId Guid

Returns

bool

RemoveSessionCatalogue(string)

Removes a session catalogue added with AddSessionCatalogue(string, string?, S128Dataset).

public bool RemoveSessionCatalogue(string label)

Parameters

label string

Returns

bool

RemoveSource(Guid, Guid)

Removes one source from a collection, with its cached index.

public bool RemoveSource(Guid collectionId, Guid sourceId)

Parameters

collectionId Guid
sourceId Guid

Returns

bool

RenameCollection(Guid, string)

Renames a collection.

public bool RenameCollection(Guid collectionId, string name)

Parameters

collectionId Guid
name string

Returns

bool

RenameSource(Guid, Guid, string)

Renames a source (its display name).

public bool RenameSource(Guid collectionId, Guid sourceId, string name)

Parameters

collectionId Guid
sourceId Guid
name string

Returns

bool

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

collectionId Guid
source CollectionSource

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

Task

Events

Changed

Raised after any change to Collections, on the changing thread.

public event EventHandler? Changed

Event Type

EventHandler

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

Event Type

EventHandler<LibrarySourceIndexedEventArgs>