Add publication sync and reconciliation coverage
This commit is contained in:
parent
7a335b1a11
commit
abdfff6f4e
3 changed files with 195 additions and 0 deletions
|
|
@ -1544,6 +1544,89 @@ namespace GameCult.Mesh
|
|||
return DocumentFromPublication<TDocument>(source, key, verse.Context, storeOptions, peerOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads one typed document from a configured publication source and hydrates it into a local node.
|
||||
/// </summary>
|
||||
public static async Task<TDocument> SyncDocumentFromPublicationAsync<TDocument>(
|
||||
CultMeshNode node,
|
||||
CultMeshDocumentPublicationSource source,
|
||||
CultRecordKey key,
|
||||
CultMeshVerseContext context,
|
||||
CultMeshStoreDocumentOptions? storeOptions = null,
|
||||
CultMeshPeerSnapshotDocumentOptions? peerOptions = null,
|
||||
bool flush = false)
|
||||
where TDocument : class
|
||||
{
|
||||
if (node == null) throw new ArgumentNullException(nameof(node));
|
||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||
|
||||
var document = await DocumentFromPublication<TDocument>(
|
||||
source,
|
||||
key,
|
||||
context,
|
||||
storeOptions,
|
||||
peerOptions)
|
||||
.LatestAsync()
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await Document<TDocument>(node, key, context)
|
||||
.ReplaceAsync(document)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (flush)
|
||||
await node.FlushAsync().ConfigureAwait(false);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads one typed document from a configured publication source and hydrates it into a local node.
|
||||
/// </summary>
|
||||
public static Task<TDocument> SyncDocumentFromPublicationAsync<TDocument>(
|
||||
CultMeshNode node,
|
||||
CultMeshDocumentPublicationSource source,
|
||||
CultRecordKey key,
|
||||
CultMeshVerse verse,
|
||||
CultMeshStoreDocumentOptions? storeOptions = null,
|
||||
CultMeshPeerSnapshotDocumentOptions? peerOptions = null,
|
||||
bool flush = false)
|
||||
where TDocument : class
|
||||
{
|
||||
if (verse == null) throw new ArgumentNullException(nameof(verse));
|
||||
return SyncDocumentFromPublicationAsync<TDocument>(
|
||||
node,
|
||||
source,
|
||||
key,
|
||||
verse.Context,
|
||||
storeOptions,
|
||||
peerOptions,
|
||||
flush);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads one typed document from a configured publication source and hydrates it into a local node.
|
||||
/// </summary>
|
||||
public static Task<TDocument> SyncDocumentFromPublicationAsync<TDocument>(
|
||||
CultMeshNode node,
|
||||
CultMeshDocumentPublicationSource source,
|
||||
string recordKey,
|
||||
CultMeshVerse verse,
|
||||
CultMeshStoreDocumentOptions? storeOptions = null,
|
||||
CultMeshPeerSnapshotDocumentOptions? peerOptions = null,
|
||||
bool flush = false)
|
||||
where TDocument : class
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(recordKey)) throw new ArgumentException("Value must be non-empty.", nameof(recordKey));
|
||||
return SyncDocumentFromPublicationAsync<TDocument>(
|
||||
node,
|
||||
source,
|
||||
new CultRecordKey(recordKey),
|
||||
verse,
|
||||
storeOptions,
|
||||
peerOptions,
|
||||
flush);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a typed document handle directly over one distributed CultNet database record.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue