예제 #1
0
        /// <summary>
        /// Synchronizes the source and destination items by using the provided key comparison result.
        /// </summary>
        /// <param name="keysComparisonResult">The comparison result of the source and destination keys.</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work.</param>
        /// <returns></returns>
        public async Task SyncAsync(KeysComparisonResult <TKey> keysComparisonResult, CancellationToken cancellationToken)
        {
            Validate();

            BeforeSyncingKeysAction?.Invoke(keysComparisonResult);

            foreach (var batchSyncOperation in Configurations.BatchSyncListsOrder.Order)
            {
                switch (batchSyncOperation)
                {
                case BatchSyncListType.ItemsInSourceOnly:
                    if (Configurations.SyncMode.ItemsInSourceOnly != SyncItemOperation.None)
                    {
                        await SyncBatchesAsync(Configurations.BatchSize, keysComparisonResult.KeysInSourceOnly, SyncItemsInSourceOnlyBatchAsync, cancellationToken).ConfigureAwait(false);
                    }
                    break;

                case BatchSyncListType.ItemsInDestinationOnly:
                    if (Configurations.SyncMode.ItemsInDestinationOnly != SyncItemOperation.None)
                    {
                        await SyncBatchesAsync(Configurations.BatchSize, keysComparisonResult.KeysInDestinationOnly, SyncItemsInDestinationOnlyBatchAsync, cancellationToken).ConfigureAwait(false);
                    }
                    break;

                case BatchSyncListType.Matches:
                    await SyncBatchesAsync(Configurations.BatchSize, keysComparisonResult.Matches, SyncMatchesBatchAsync, cancellationToken).ConfigureAwait(false);

                    break;

                default:
                    throw new NotSupportedException($"Not supported {nameof(BatchSyncListType)} '{batchSyncOperation.ToString()}'.");
                }
            }
        }
예제 #2
0
        public void KeysComparisonResultShouldHaveValidString()
        {
            var keysComparisonResult = new KeysComparisonResult <int>();

            keysComparisonResult.KeysInSourceOnly.Add(1);

            keysComparisonResult.KeysInDestinationOnly.Add(2);
            keysComparisonResult.KeysInDestinationOnly.Add(3);

            keysComparisonResult.ToString().Should().Be($"{nameof(keysComparisonResult.KeysInSourceOnly)}: {keysComparisonResult.KeysInSourceOnly.Count}, {nameof(keysComparisonResult.KeysInDestinationOnly)}: {keysComparisonResult.KeysInDestinationOnly.Count}, {nameof(keysComparisonResult.Matches)}: {keysComparisonResult.Matches.Count}");
        }