Class LibraryDownloads
- Namespace
- EncDotNet.S100.Collections.Library
- Assembly
- EncDotNet.S100.Collections.dll
Downloads online library items (NOAA and USACE ENCs, community packages, S-100 feeds and the NOAA S-102/S-104/S-111 forecast catalogues; issues #655, #670, #680, #685) into managed folders, a few at a time, and resolves their downloaded copies so they behave as local items. UI-free: the viewer adds its progress notification on top, and a headless host (#792) reads Progress and StatusOf(CollectionItem) directly.
public sealed class LibraryDownloads : ILibraryLocalCopies
- Inheritance
-
LibraryDownloads
- Implements
- Inherited Members
Remarks
Thread-safe. Events are raised on whichever thread did the work.
Constructors
LibraryDownloads(EncCellDownloader)
Creates downloads that save every item with downloader.
public LibraryDownloads(EncCellDownloader downloader)
Parameters
downloaderEncCellDownloaderThe downloader (and so the managed folder) for every item.
LibraryDownloads(Func<RemoteItemLocation, EncCellDownloader?>)
Creates downloads that pick a downloader (and so a managed folder) per download location, e.g. one per provider or per DownloadFolder.
public LibraryDownloads(Func<RemoteItemLocation, EncCellDownloader?> downloaderFor)
Parameters
downloaderForFunc<RemoteItemLocation, EncCellDownloader>The downloader for a location; null means the location is not downloadable. See ManagedFolders(HttpClient, string, HttpClient?, SecomRevocation?, SecomServerTrust?, Func<SecomTrustAnchors>?) for the hosts' layout.
Fields
MaxConcurrentDownloads
How many downloads run at once.
public const int MaxConcurrentDownloads = 3
Field Value
ProgressInterval
How often, at most, ProgressChanged is raised.
public static readonly TimeSpan ProgressInterval
Field Value
Properties
Logger
Where download batches and failed downloads are logged, or null for no logging. Items are logged by name only, never by location, since a location can carry credentials.
public ILogger? Logger { get; init; }
Property Value
Progress
The running bulk download, or null when none is running.
public LibraryDownloadProgress? Progress { get; }
Property Value
Methods
CanDownload(CollectionItem)
True when item can be downloaded (online, not cancelled, and a downloader takes it).
public bool CanDownload(CollectionItem item)
Parameters
itemCollectionItemThe library item.
Returns
Cancel(CollectionItem)
Cancels item's download (queued or running); the rest of the batch carries on.
public void Cancel(CollectionItem item)
Parameters
itemCollectionItemThe library item.
CancelAll()
Cancels the running bulk download.
public void CancelAll()
Delete(RemoteItemLocation, string)
Deletes the downloaded copy named name from the
managed folder that location downloads to, and
forgets it, so its items are online again.
public bool Delete(RemoteItemLocation location, string name)
Parameters
locationRemoteItemLocationAny download location of that folder.
namestringThe cell or package name (as DownloadedNames(RemoteItemLocation) lists it).
Returns
- bool
True when a copy was deleted.
DownloadAsync(IReadOnlyList<CollectionItem>, IProgress<LibraryDownloadProgress>?, CancellationToken)
Downloads the downloadable items among items, at most
MaxConcurrentDownloads at a time. A package downloads once
however many of its datasets are asked for. Never throws for a failed
or cancelled download: the result counts them.
public Task<LibraryDownloadResult> DownloadAsync(IReadOnlyList<CollectionItem> items, IProgress<LibraryDownloadProgress>? progress = null, CancellationToken cancellationToken = default)
Parameters
itemsIReadOnlyList<CollectionItem>The items to download; others are ignored.
progressIProgress<LibraryDownloadProgress>Told the batch's progress when it starts and each time an item finishes (reported on the finishing thread, not posted), or null.
cancellationTokenCancellationTokenCancels the whole batch.
Returns
- Task<LibraryDownloadResult>
How many downloaded and failed, and whether the batch was cancelled.
DownloadedNames(RemoteItemLocation)
The names of the copies downloaded into the managed folder that
location downloads to (cells or packages); empty
when the location is not downloadable.
public IReadOnlyList<string> DownloadedNames(RemoteItemLocation location)
Parameters
locationRemoteItemLocationAny download location of that folder.
Returns
FolderOf(RemoteItemLocation)
The managed folder that location downloads to, or null when it is not downloadable.
public string? FolderOf(RemoteItemLocation location)
Parameters
locationRemoteItemLocationAny download location of that folder.
Returns
IsOutdated(CollectionItem)
True when the downloaded copy of item is an older edition or update.
public bool IsOutdated(CollectionItem item)
Parameters
itemCollectionItem
Returns
LocalEditionOf(CollectionItem)
The edition of item's downloaded copy, or null when not downloaded (or unknown).
public int? LocalEditionOf(CollectionItem item)
Parameters
itemCollectionItem
Returns
- int?
LocalPublishedAtOf(CollectionItem)
When item's downloaded copy was published (for a
forecast, its run time), or null when not downloaded (or unknown).
public DateTimeOffset? LocalPublishedAtOf(CollectionItem item)
Parameters
itemCollectionItem
Returns
Localize(CollectionItem)
Returns item with a local location when it is an
online item that has been downloaded; otherwise the item itself.
public CollectionItem Localize(CollectionItem item)
Parameters
itemCollectionItem
Returns
ManagedFolders(HttpClient, string, HttpClient?, SecomRevocation?, SecomServerTrust?, Func<SecomTrustAnchors>?)
The managed download layout the viewer uses under its downloads root,
so every host keeps downloads in the same place: an item that names its
own folder (community lists, S-100 feeds and catalogues) gets that
folder; otherwise USACE cells go to usace-ienc and everything else
to noaa-enc.
public static Func<RemoteItemLocation, EncCellDownloader?> ManagedFolders(HttpClient http, string downloadsRoot, HttpClient? secomHttp = null, SecomRevocation? revocation = null, SecomServerTrust? secomTrust = null, Func<SecomTrustAnchors>? trustAnchors = null)
Parameters
httpHttpClientThe client downloads use (with a generous timeout).
downloadsRootstringThe host's downloads root.
secomHttpHttpClientThe client SECOM objects are downloaded with (see SecomHttpClient); null uses
http.revocationSecomRevocationChecks SECOM signers for revocation (see Revocation); null skips it.
secomTrustSecomServerTrustResolves each SECOM object's identity, presented and signed with (see SecomTrust); null downloads anonymously.
trustAnchorsFunc<SecomTrustAnchors>Where SECOM signers' trust anchors come from (see TrustAnchorsSource); by default
secomTrust's anchors, else BuiltIn.
Returns
- Func<RemoteItemLocation, EncCellDownloader>
A downloader selector for LibraryDownloads(Func<RemoteItemLocation, EncCellDownloader?>).
Pin(CollectionItem)
Pins the downloaded run of a weather item (#1075): keeps a copy beside the latest, so the next run doesn't replace it. Its source lists the copy as a pinned item once it re-indexes.
public string? Pin(CollectionItem item)
Parameters
itemCollectionItemA weather item with a downloaded copy.
Returns
- string
The pinned copy's name, or null when the item has no downloaded copy.
StatusOf(CollectionItem)
Where item stands in a download, or null when it is not queued, running or failed.
public LibraryDownloadItemStatus? StatusOf(CollectionItem item)
Parameters
itemCollectionItemThe library item.
Returns
Unpin(CollectionItem)
Deletes a pinned weather run (an item IsPinned(CollectionItem) says is one, #1075).
public bool Unpin(CollectionItem pinned)
Parameters
pinnedCollectionItemThe pinned item, as its source lists it.
Returns
- bool
True when the copy was deleted.
Events
Changed
Raised when a download completes, fails or is cancelled (a copy appeared or changed), and when a batch starts or ends.
public event EventHandler? Changed
Event Type
ProgressChanged
Raised (throttled to ProgressInterval) as bytes arrive, so a host can show progress without re-resolving every item.
public event EventHandler? ProgressChanged