Class LibraryOperations
- Namespace
- EncDotNet.S100.Collections.Library
- Assembly
- EncDotNet.S100.Collections.dll
The Library's actions for a host without view models (issue #792): open items into the host's session, download online items (then re-index or open them), and tell when all that work has finished. Every operation is tracked by Activity from the moment it is called until the datasets it opens are open, so AwaitIdleAsync(TimeSpan, CancellationToken) never reports idle between a download finishing and its datasets opening (#790).
public sealed class LibraryOperations
- Inheritance
-
LibraryOperations
- Inherited Members
Remarks
The viewer drives the same pieces (LibraryDownloads,
LibraryLoader, LibraryActivityTracker) from its
Library panel; a headless host such as s100 mcp serve uses this
class with a LibraryLoader over its dataset catalog.
Constructors
LibraryOperations(CollectionLibrary, LibraryDownloads, LibraryLoader, LibraryActivityTracker?)
Creates the operations over a library, its downloads and a loader.
public LibraryOperations(CollectionLibrary library, LibraryDownloads downloads, LibraryLoader loader, LibraryActivityTracker? activity = null)
Parameters
libraryCollectionLibraryThe library the items come from (their sources are re-indexed after a download).
downloadsLibraryDownloadsDownloads of online items.
loaderLibraryLoaderOpens items into the host's session.
activityLibraryActivityTrackerTracks running operations; a new tracker when null.
Fields
IdlePollInterval
How often AwaitIdleAsync(TimeSpan, CancellationToken) re-checks.
public static readonly TimeSpan IdlePollInterval
Field Value
Properties
Activity
The running operations.
public LibraryActivityTracker Activity { get; }
Property Value
Downloads
Downloads of online items (progress, per-item status, cancelling).
public LibraryDownloads Downloads { get; }
Property Value
Library
The library the items come from.
public CollectionLibrary Library { get; }
Property Value
Loader
Opens items into the host's session (and knows which are open).
public LibraryLoader Loader { get; }
Property Value
Methods
AwaitIdleAsync(TimeSpan, CancellationToken)
Waits until nothing is indexing, downloading or opening datasets, or
until timeout passes.
public Task<LibraryIdleWait> AwaitIdleAsync(TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpanHow long to wait at most (zero to just look).
cancellationTokenCancellationTokenCancels the wait.
Returns
DownloadAsync(IReadOnlyList<(CollectionItem Item, LibrarySource Source)>, bool, IProgress<LibraryDownloadProgress>?, CancellationToken)
Downloads the downloadable items among items and
re-indexes their sources (so what an index reads from a downloaded copy
appears), then waits for that when a package was downloaded (whose
datasets the Library lists only after it) or, with load,
opens the downloaded items. The operation is tracked from the call (before
the first await), so a caller may start it without awaiting and an
AwaitIdleAsync(TimeSpan, CancellationToken) that follows still waits for all of it.
public Task<LibraryDownloadOutcome> DownloadAsync(IReadOnlyList<(CollectionItem Item, LibrarySource Source)> items, bool load, IProgress<LibraryDownloadProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
itemsIReadOnlyList<(CollectionItem Item, LibrarySource Source)>The items to download, each with the source it was indexed from.
loadboolTrue to open the downloaded items afterwards.
progressIProgress<LibraryDownloadProgress>Told the batch's progress as it starts and as each item finishes, or null.
cancellationTokenCancellationTokenCancels the download (and what follows).
Returns
GetActivity()
The Library's activity now.
public LibraryActivitySnapshot GetActivity()
Returns
LoadAsync(IReadOnlyList<CollectionItem>, bool, CancellationToken)
Opens items (downloaded online items open their
copy): now, or with defer as they come into view
where the host supports it. Tracked until the opens finish.
public Task<LibraryLoadResult> LoadAsync(IReadOnlyList<CollectionItem> items, bool defer = false, CancellationToken cancellationToken = default)
Parameters
itemsIReadOnlyList<CollectionItem>The items to open.
deferboolTrue to load as the items come into view.
cancellationTokenCancellationTokenCancels the load.
Returns
LoadLatestRunAsync(Guid, CancellationToken)
"Load latest run" for a weather source (#1075): re-reads the source, so its latest published run is listed, downloads that run (replacing the previous, unless it was pinned) and opens it. A run already downloaded is just opened. Pinned runs are left alone.
public Task<LibraryDownloadOutcome?> LoadLatestRunAsync(Guid sourceId, CancellationToken cancellationToken = default)
Parameters
sourceIdGuidThe source.
cancellationTokenCancellationTokenCancels the refresh, download and load.
Returns
- Task<LibraryDownloadOutcome>
What the download and load did, or null when the source isn't in the Library or lists no run.
StateOf(CollectionItem, LibrarySource, TimeProvider?)
The state of item as the Library shows it: its downloaded copy and whether it is open.
public LibraryItemState StateOf(CollectionItem item, LibrarySource source, TimeProvider? time = null)
Parameters
itemCollectionItemThe indexed item.
sourceLibrarySourceThe source it was indexed from.
timeTimeProviderThe clock that decides whether a downloaded forecast run has ended.