예제 #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());
        }
 public DataAdapterConfigurationProvidersCollection(IDataTransferService transferService, IEnumerable <IDataAdapterConfigurationProvider> configurationProviders)
 {
     sources = transferService.GetKnownSources();
     sinks   = transferService.GetKnownSinks();
     this.configurationProviders = configurationProviders;
 }
예제 #4
0
        public void Print()
        {
            Console.WriteLine(Resources.HelpHeaderFormat, Assembly.GetExecutingAssembly().GetName().Version);
            Console.WriteLine();

            PrintUsage();
            Console.WriteLine();

            PrintAdapters(Resources.HelpKnownSourcesHeader, CommandLineOneTimeTransferConfiguration.SourceSwitch, service.GetKnownSources());
            Console.WriteLine();

            PrintAdapters(Resources.HelpKnownTargetsHeader, CommandLineOneTimeTransferConfiguration.TargetSwitch, service.GetKnownSinks());
        }
 public DataAdapterConfigurationProvidersCollection(IDataTransferService transferService, IEnumerable<IDataAdapterConfigurationProvider> configurationProviders)
 {
     sources = transferService.GetKnownSources();
     sinks = transferService.GetKnownSinks();
     this.configurationProviders = configurationProviders;
 }