예제 #1
0
        public async Task Execute()
        {
            TransferModel.HasImportStarted = true;

            ImportOperationContext operationContext = null;
            Exception criticalError = null;

            try
            {
                using (var cancellation = TransferModel.ImportCancellation = new CancellationTokenSource())
                {
                    var statistics = await statisticsFactory.Create(errorDetailsProviderFactory.Create(TransferModel.InfrastructureConfiguration),
                                                                    TransferModel.InfrastructureConfiguration, cancellation.Token);

                    UpdateStatistics(
                        operationContext = new ImportOperationContext(statistics, Presenter.DataContext as ImportViewModel)
                    {
                        ViewModel = { IsImportRunning = true }
                    });

                    using (new DisposableDispatcherTimer <ImportOperationContext>(
                               TimeSpan.FromSeconds(1), UpdateStatistics, operationContext))
                    {
                        await Task.Run(() =>
                                       transferService.TransferAsync(
                                           // From
                                           TransferModel.SourceAdapterName, TransferModel.SourceConfiguration,
                                           // To
                                           TransferModel.SinkAdapterName, TransferModel.SinkConfiguration,
                                           // With statistics
                                           statistics,
                                           // Allow cancellation
                                           cancellation.Token));
                    }
                }
            }
            catch (Exception error)
            {
                // Preserve error and allow finally block to execute right away
                criticalError = error;
            }
            finally
            {
                TransferModel.ImportCancellation = null;

                if (operationContext != null)
                {
                    operationContext.ViewModel.IsImportRunning = false;
                    UpdateStatistics(operationContext);
                }
            }

            taskBarService.Notify();

            if (criticalError != null)
            {
                errorHandler.Handle(criticalError);
            }
        }
예제 #2
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 Execute()
        {
            TransferModel.HasImportStarted = true;

            ImportOperationContext operationContext = null;
            Exception criticalError = null;

            try
            {
                var statistics = statisticsFactory.Create();
                operationContext = new ImportOperationContext(statistics, Presenter.DataContext as ImportViewModel);
                operationContext.ViewModel.IsImportRunning = true;

                using (var cancellation = TransferModel.ImportCancellation = new CancellationTokenSource())
                {
                    using (var timer = new Timer(UpdateStatistics, operationContext, TimeSpan.Zero, TimeSpan.FromSeconds(1)))
                    {
                        await Task.Run(() =>
                                       transferService.TransferAsync(
                                           // From
                                           TransferModel.SourceAdapterName, TransferModel.SourceConfiguration,
                                           // To
                                           TransferModel.SinkAdapterName, TransferModel.SinkConfiguration,
                                           // With statistics
                                           statistics,
                                           // Allow cancellation
                                           cancellation.Token));
                    }
                }
            }
            catch (Exception error)
            {
                // Preserve error and allow finally block to execute right away
                criticalError = error;
            }
            finally
            {
                TransferModel.ImportCancellation = null;

                if (operationContext != null)
                {
                    operationContext.ViewModel.IsImportRunning = false;
                    UpdateStatistics(operationContext);
                }
            }

            if (criticalError != null)
            {
                errorHandler.Handle(criticalError);
            }
        }
        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());
        }