Table of Contents

Class LibrarySync

Namespace
EncDotNet.S100.Collections.Library
Assembly
EncDotNet.S100.Collections.dll

Keeps synced sources' local copies current (issue #807): after a synced source is indexed, the items its ILibrarySyncPolicy wants are downloaded when missing or outdated, and copies in its managed folder that no source lists any more (or lists as cancelled) are deleted. The source is then re-indexed once, so downloaded items get their bounds (and packages their cells). A source is synced when Sync is on and a policy supports its kind: SecomSyncPolicy (which prunes) and OnlineSyncPolicy (the other online kinds, which only download, #809).

public sealed class LibrarySync : IDisposable
Inheritance
LibrarySync
Implements
Inherited Members

Remarks

UI-free and shared by the viewer and headless hosts (#792). Downloads go through LibraryDownloads without a progress notification: the objects are small and the sync runs in the background.

Pruning is conservative: it runs only after a complete, fresh listing (an index with a fingerprint and no warnings, so neither a stale copy served while the service was down nor a capped listing), and keeps anything any source of the same managed folder still lists. A sync that downloads or deletes nothing does not re-index, so the index-sync cycle settles.

Constructors

LibrarySync(CollectionLibrary, LibraryDownloads, LibrarySyncOptions?, ILogger<LibrarySync>?, TimeProvider?, IEnumerable<ILibrarySyncPolicy>?)

Creates a sync over library, downloading through downloads.

public LibrarySync(CollectionLibrary library, LibraryDownloads downloads, LibrarySyncOptions? options = null, ILogger<LibrarySync>? logger = null, TimeProvider? timeProvider = null, IEnumerable<ILibrarySyncPolicy>? policies = null)

Parameters

library CollectionLibrary

The library whose synced sources are kept current.

downloads LibraryDownloads

The downloads that hold the local copies.

options LibrarySyncOptions

Options; defaults when null.

logger ILogger<LibrarySync>

A logger, or null.

timeProvider TimeProvider

The clock; defaults to System.

policies IEnumerable<ILibrarySyncPolicy>

The sync rules per source kind; defaults to SecomSyncPolicy and OnlineSyncPolicy.

Properties

IsSyncing

True while any source is syncing.

public bool IsSyncing { get; }

Property Value

bool

Methods

CanSync(CollectionSource)

True when source's kind can be kept in sync (online sources).

public bool CanSync(CollectionSource source)

Parameters

source CollectionSource

Returns

bool

CanSyncByDefault(CollectionSource)

True when the default policies can keep source's kind in sync (online sources).

public static bool CanSyncByDefault(CollectionSource source)

Parameters

source CollectionSource

Returns

bool

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

IsSynced(CollectionSource)

True when source is kept in sync.

public bool IsSynced(CollectionSource source)

Parameters

source CollectionSource

Returns

bool

StatusOf(Guid)

Where sourceId stood after its last sync, or null before one.

public LibrarySyncStatus? StatusOf(Guid sourceId)

Parameters

sourceId Guid

Returns

LibrarySyncStatus

SyncAsync(Guid, CancellationToken)

Syncs sourceId against its current index now (it is otherwise synced after each index).

public Task<LibrarySyncStatus?> SyncAsync(Guid sourceId, CancellationToken cancellationToken = default)

Parameters

sourceId Guid
cancellationToken CancellationToken

Returns

Task<LibrarySyncStatus>

Where it stands, or null when it is not a synced, indexed source.

WhenIdle()

Completes when no source is syncing.

public Task WhenIdle()

Returns

Task

Events

Synced

Raised on the syncing thread after a source has been synced.

public event EventHandler<LibrarySyncedEventArgs>? Synced

Event Type

EventHandler<LibrarySyncedEventArgs>