/// <summary> /// Synchronizes the items that exist in the destination only. /// </summary> /// <param name="batchKeys">The keys of the items.</param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param> /// <returns></returns> private async Task SyncItemsInDestinationOnlyBatchAsync(List <TKey> batchKeys, CancellationToken cancellationToken) { if (!batchKeys.Any()) { return; } switch (Configurations.SyncMode.ItemsInDestinationOnly) { case SyncItemOperation.None: // do nothing break; case SyncItemOperation.Add: var comparisonResult = new ComparisonResult <TItem>(); comparisonResult.ItemsInDestinationOnly.AddRange(await DestinationProvider.GetAsync(batchKeys, cancellationToken).ConfigureAwait(false)); await SyncAsync(comparisonResult, cancellationToken).ConfigureAwait(false); break; case SyncItemOperation.Delete: BeforeDeletingItemsFromDestinationAction?.Invoke(batchKeys); await DestinationProvider.DeleteAsync(batchKeys, cancellationToken).ConfigureAwait(false); break; default: throw new NotSupportedException($"Not supported destination {nameof(SyncItemOperation)} '{Configurations.SyncMode.ItemsInDestinationOnly.ToString()}'."); } }
/// <summary> /// Synchronizes the items that exist in the source and destination. /// </summary> /// <param name="batchKeys">The keys of the items.</param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param> /// <returns></returns> private async Task SyncMatchesBatchAsync(List <TKey> batchKeys, CancellationToken cancellationToken) { var srcTask = SourceProvider.GetAsync(batchKeys, cancellationToken); var dstTask = DestinationProvider.GetAsync(batchKeys, cancellationToken); await Task.WhenAll(srcTask, dstTask); // Compare var comparisonResult = await ComparerAgent <TKey, TItem> .Create() .Configure((c) => { c.AllowDuplicateItems = RuleAllowanceType.None; c.AllowDuplicateKeys = RuleAllowanceType.None; c.AllowNullableItems = RuleAllowanceType.None; }) .SetKeySelector(KeySelector) .SetCompareItemFunc(CompareItemFunc) .SetSourceProvider(srcTask.Result) .SetDestinationProvider(dstTask.Result) .CompareAsync(cancellationToken).ConfigureAwait(false); // Sync await SyncAsync(comparisonResult, cancellationToken).ConfigureAwait(false); }