예제 #1
0
        /// <summary>
        /// Synchronizes the items that exist in the source 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 SyncItemsInSourceOnlyBatchAsync(List <TKey> batchKeys, CancellationToken cancellationToken)
        {
            if (!batchKeys.Any())
            {
                return;
            }

            switch (Configurations.SyncMode.ItemsInSourceOnly)
            {
            case SyncItemOperation.None:      // do nothing
                break;

            case SyncItemOperation.Add:
                var comparisonResult = new ComparisonResult <TItem>();
                comparisonResult.ItemsInSourceOnly.AddRange(await SourceProvider.GetAsync(batchKeys, cancellationToken).ConfigureAwait(false));
                await SyncAsync(comparisonResult, cancellationToken).ConfigureAwait(false);

                break;

            case SyncItemOperation.Delete:
                BeforeDeletingItemsFromSourceAction?.Invoke(batchKeys);
                await SourceProvider.DeleteAsync(batchKeys, cancellationToken).ConfigureAwait(false);

                break;

            default:
                throw new NotSupportedException($"Not supported source {nameof(SyncItemOperation)} '{Configurations.SyncMode.ItemsInSourceOnly.ToString()}'.");
            }
        }
예제 #2
0
        /// <summary>
        /// Deletes the items from the source.
        /// </summary>
        /// <param name="items">The items to be deleted.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param>
        /// <returns></returns>
        protected override async Task DeleteFromSourceAsync(List <TItem> items, CancellationToken cancellationToken)
        {
            if (items == null || !items.Any())
            {
                return;
            }

            await SourceProvider.DeleteAsync(items.Select(x => KeySelector(x)).ToList(), cancellationToken).ConfigureAwait(false);
        }
예제 #3
0
 /// <summary>
 /// Deletes the items from the source.
 /// </summary>
 /// <param name="items">The items to be deleted.</param>
 /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param>
 /// <returns></returns>
 protected override Task DeleteFromSourceAsync(List <TItem> items, CancellationToken cancellationToken) => SourceProvider.DeleteAsync(items, cancellationToken);