Exemplo n.º 1
0
        public async Task <TransferResult> RunAsync()
        {
            ValidateConfiguration();

            IDataAdapterDefinition sourceDefinition;

            if (!transferService.GetKnownSources().TryGetValue(configuration.SourceName, out sourceDefinition))
            {
                throw Errors.UnknownSource(configuration.SourceName);
            }

            IDataAdapterDefinition sinkDefinition;

            if (!transferService.GetKnownSinks().TryGetValue(configuration.TargetName, out sinkDefinition))
            {
                throw Errors.UnknownDestination(configuration.TargetName);
            }

            ITransferStatistics statistics = null;

            using (var cancellation = new ConsoleCancellationSource())
            {
                statistics = await statisticsHandler.CreateNew(statisticsConfiguration, cancellation.Token);

                using (new Timer(PrintStatistics, statistics, TimeSpan.Zero, GetProgressUpdateInterval()))
                {
                    await transferService
                    .TransferAsync(
                        // From
                        configuration.SourceName,
                        dataAdapterConfiguration.TryCreate(sourceDefinition.ConfigurationType, configuration.SourceConfiguration),
                        // To
                        configuration.TargetName,
                        dataAdapterConfiguration.TryCreate(sinkDefinition.ConfigurationType, configuration.TargetConfiguration),
                        // With statistics
                        statistics,
                        // Allow cancellation
                        cancellation.Token);
                }
            }

            if (statistics == null)
            {
                return(TransferResult.Empty);
            }

            var statisticsSnapshot = statistics.GetSnapshot();

            statisticsHandler.PrintResult(statisticsSnapshot);

            return(new TransferResult(statisticsSnapshot.Transferred, statisticsSnapshot.Failed));
        }
        public async Task RunAsync()
        {
            ValidateConfiguration();

            IDataAdapterDefinition sourceDefinition;

            if (!transferService.GetKnownSources().TryGetValue(configuration.SourceName, out sourceDefinition))
            {
                throw Errors.UnknownSource(configuration.SourceName);
            }

            IDataAdapterDefinition sinkDefinition;

            if (!transferService.GetKnownSinks().TryGetValue(configuration.TargetName, out sinkDefinition))
            {
                throw Errors.UnknownDestination(configuration.TargetName);
            }

            var statistics = statisticsHandler.CreateNew();

            using (var cancellation = new ConsoleCancellationSource())
            {
                using (var timer = new Timer(PrintStatistics, statistics, TimeSpan.Zero, TimeSpan.FromSeconds(1)))
                {
                    await transferService
                    .TransferAsync(
                        // From
                        configuration.SourceName,
                        dataAdapterConfiguration.TryCreate(sourceDefinition.ConfigurationType, configuration.SourceConfiguration),
                        // To
                        configuration.TargetName,
                        dataAdapterConfiguration.TryCreate(sinkDefinition.ConfigurationType, configuration.TargetConfiguration),
                        // With statistics
                        statistics,
                        // Allow cancellation
                        cancellation.Token);
                }
            }

            statisticsHandler.PrintResult(statistics.GetSnapshot());
        }