Example #1
0
        private async Task ProcessSourceAsync(IDatabaseSmugglerSource source, DatabaseSmugglerOperationState state, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(source.DisplayName) == false)
            {
                Notifications.ShowProgress("Processing source: {0}", source.DisplayName);
            }

            var maxEtags = await source
                           .FetchCurrentMaxEtagsAsync(cancellationToken)
                           .ConfigureAwait(false);

            while (true)
            {
                var type = await source
                           .GetNextSmuggleTypeAsync(cancellationToken)
                           .ConfigureAwait(false);

                switch (type)
                {
                case SmuggleType.None:
                    return;

                case SmuggleType.Index:
                    await new IndexSmuggler(_options, _notifications, source, _destination)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                case SmuggleType.Document:
                    await new DocumentSmuggler(_options, _notifications, source, _destination, maxEtags)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                case SmuggleType.Transformer:
                    await new TransformerSmuggler(_options, _notifications, source, _destination)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                case SmuggleType.DocumentDeletion:
                    await new DocumentDeletionsSmuggler(_options, _notifications, source, _destination, maxEtags)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                case SmuggleType.Identity:
                    await new IdentitySmuggler(_options, _notifications, source, _destination)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                case SmuggleType.Attachment:
                    await new AttachmentSmuggler(_options, _notifications, source, _destination)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                case SmuggleType.AttachmentDeletion:
                    await new AttachmentDeletionsSmuggler(_options, _notifications, source, _destination)
                    .SmuggleAsync(state, cancellationToken)
                    .ConfigureAwait(false);
                    continue;

                default:
                    throw new NotSupportedException(type.ToString());
                }
            }
        }