Beispiel #1
0
        public async Task TransferAsync(string sourceName, object sourceConfiguration,
                                        string sinkName, object sinkConfiguration, ITransferStatistics statistics, CancellationToken cancellation)
        {
            IDataSourceAdapterFactoryAdapter sourceFactoryAdapter;

            if (!sources.TryGetValue(sourceName, out sourceFactoryAdapter))
            {
                throw Errors.UnknownDataSource(sourceName);
            }

            IDataSinkAdapterFactoryAdapter sinkFactoryAdapter;

            if (!sinks.TryGetValue(sinkName, out sinkFactoryAdapter))
            {
                throw Errors.UnknownDataSink(sinkName);
            }

            var context = new DataTransferContext
            {
                SourceName = sourceName,
                SinkName   = sinkName
            };

            // Lets start timer now, since factories may take some time as well and we want to capture that
            statistics.Start();

            var source = sourceFactoryAdapter.CreateAsync(sourceConfiguration, context);
            var sink   = sinkFactoryAdapter.CreateAsync(sinkConfiguration, context);

            using (var sourceInstance = await source)
                using (var sinkInstance = await sink)
                    await transferAction.ExecuteAsync(sourceInstance, sinkInstance, statistics, cancellation);
        }
        public async Task TransferAsync(string sourceName, object sourceConfiguration,
            string sinkName, object sinkConfiguration, ITransferStatistics statistics, CancellationToken cancellation)
        {
            IDataSourceAdapterFactoryAdapter sourceFactoryAdapter;
            if (!sources.TryGetValue(sourceName, out sourceFactoryAdapter))
                throw Errors.UnknownDataSource(sourceName);

            IDataSinkAdapterFactoryAdapter sinkFactoryAdapter;
            if (!sinks.TryGetValue(sinkName, out sinkFactoryAdapter))
                throw Errors.UnknownDataSink(sinkName);

            var context = new DataTransferContext
            {
                SourceName = sourceName,
                SinkName = sinkName
            };

            try
            {
                // Lets start timer now, since factories may take some time as well and we want to capture that
                statistics.Start();

                var source = sourceFactoryAdapter.CreateAsync(sourceConfiguration, context, cancellation);
                var sink = sinkFactoryAdapter.CreateAsync(sinkConfiguration, context, cancellation);

                using (var sourceInstance = await source)
                using (var sinkInstance = await sink)
                    await transferAction.ExecuteAsync(sourceInstance, sinkInstance, statistics, cancellation);
            }
            finally
            {
                statistics.Stop();
            }
        }
Beispiel #3
0
        public async Task ExecuteAsync(IDataSourceAdapter source, IDataSinkAdapter sink, ITransferStatistics statistics, CancellationToken cancellation)
        {
            Guard.NotNull("source", source);
            Guard.NotNull("sink", sink);

            try
            {
                statistics.Start();

                await TransferData(source, sink, statistics, cancellation);
            }
            finally
            {
                statistics.Stop();
            }
        }