Table of Contents

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

library CollectionLibrary

The library the items come from (their sources are re-indexed after a download).

downloads LibraryDownloads

Downloads of online items.

loader LibraryLoader

Opens items into the host's session.

activity LibraryActivityTracker

Tracks running operations; a new tracker when null.

Fields

IdlePollInterval

public static readonly TimeSpan IdlePollInterval

Field Value

TimeSpan

Properties

Activity

The running operations.

public LibraryActivityTracker Activity { get; }

Property Value

LibraryActivityTracker

Downloads

Downloads of online items (progress, per-item status, cancelling).

public LibraryDownloads Downloads { get; }

Property Value

LibraryDownloads

Library

The library the items come from.

public CollectionLibrary Library { get; }

Property Value

CollectionLibrary

Loader

Opens items into the host's session (and knows which are open).

public LibraryLoader Loader { get; }

Property Value

LibraryLoader

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

timeout TimeSpan

How long to wait at most (zero to just look).

cancellationToken CancellationToken

Cancels the wait.

Returns

Task<LibraryIdleWait>

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

items IReadOnlyList<(CollectionItem Item, LibrarySource Source)>

The items to download, each with the source it was indexed from.

load bool

True to open the downloaded items afterwards.

progress IProgress<LibraryDownloadProgress>

Told the batch's progress as it starts and as each item finishes, or null.

cancellationToken CancellationToken

Cancels the download (and what follows).

Returns

Task<LibraryDownloadOutcome>

GetActivity()

The Library's activity now.

public LibraryActivitySnapshot GetActivity()

Returns

LibraryActivitySnapshot

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

items IReadOnlyList<CollectionItem>

The items to open.

defer bool

True to load as the items come into view.

cancellationToken CancellationToken

Cancels the load.

Returns

Task<LibraryLoadResult>

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

sourceId Guid

The source.

cancellationToken CancellationToken

Cancels 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

item CollectionItem

The indexed item.

source LibrarySource

The source it was indexed from.

time TimeProvider

The clock that decides whether a downloaded forecast run has ended.

Returns

LibraryItemState