예제 #1
0
        /// <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()}'.");
            }
        }
예제 #2
0
        /// <summary>
        /// Delete the items from the destination.
        /// </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 DeleteFromDestinationAsync(List <TItem> items, CancellationToken cancellationToken)
        {
            if (items == null || !items.Any())
            {
                return;
            }

            await DestinationProvider.DeleteAsync(items.Select(x => KeySelector(x)).ToList(), cancellationToken).ConfigureAwait(false);
        }