private async Task DoTransfer(Transfer transfer, TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            using (transfer)
            {
                bool hasError = false;

                Interlocked.Increment(ref this.outstandingTasks);

                try
                {
                    await transfer.ExecuteAsync(scheduler, cancellationToken);
                }
                catch
                {
                    // catch exception thrown from sub-transfer as it's already recorded
                    hasError = true;
                }
                finally
                {
                    if (!hasError)
                    {
                        this.subTransfers.RemoveTransfer(transfer);
                    }

                    if (Interlocked.Decrement(ref this.outstandingTasks) == 0)
                    {
                        // all transfers are done
                        this.allTransfersCompleteSource.SetResult(null);
                    }

                    this.enumerationResetEvent.Set();
                }
            }
        }
Example #2
0
        private async void DoTransfer(Transfer transfer, TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            using (transfer)
            {
                bool hasError = false;

                Interlocked.Increment(ref this.outstandingTasks);

                try
                {
                    await transfer.ExecuteAsync(scheduler, cancellationToken).ConfigureAwait(false);
                }
                catch
                {
                    // catch exception thrown from sub-transfer as it's already recorded
                    hasError = true;
                }
                finally
                {
                    // Don't keep the failed transferring in memory, if the checkpoint is persist to a streamed journal,
                    // instead, should only keep them in the streamed journal.
                    if ((!hasError) ||
                        (null != this.Journal))
                    {
                        this.subTransfers.RemoveTransfer(transfer);
                    }

                    this.enumerationResetEvent.Set();

                    if (Interlocked.Decrement(ref this.outstandingTasks) == 0)
                    {
                        // all transfers are done
                        this.allTransfersCompleteSource.SetResult(null);
                    }
                }
            }
        }
        private async Task DoTransfer(Transfer transfer, TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            using (transfer)
            {
                bool hasError = false;

                Interlocked.Increment(ref this.outstandingTasks);

                try
                {
                    await transfer.ExecuteAsync(scheduler, cancellationToken);
                }
                catch
                {
                    // catch exception thrown from sub-transfer as it's already recorded
                    hasError = true;
                }
                finally
                {
                    if (!hasError)
                    {
                        this.subTransfers.RemoveTransfer(transfer);
                    }

                    if (Interlocked.Decrement(ref this.outstandingTasks) == 0)
                    {
                        // all transfers are done
                        this.allTransfersCompleteSource.SetResult(null);
                    }

                    this.enumerationResetEvent.Set();
                }
            }
        }
        private static async Task DoTransfer(Transfer transfer, CancellationToken cancellationToken)
        {
            if (!TryAddTransfer(transfer))
            {
                throw new TransferException(TransferErrorCode.TransferAlreadyExists, Resources.TransferAlreadyExists);
            }

            try
            {
                await transfer.ExecuteAsync(scheduler, cancellationToken);
            }
            finally
            {
                RemoveTransfer(transfer);
            }
        }
        private static async Task DoTransfer(Transfer transfer, TransferContext transferContext, CancellationToken cancellationToken)
        {
            using (transfer)
            {
                if (!TryAddTransfer(transfer))
                {
                    throw new TransferException(TransferErrorCode.TransferAlreadyExists, Resources.TransferAlreadyExists);
                }

                if (transferContext != null)
                {
                    if (transfer.Context == null)
                    {
                        // associate transfer with transfer context
                        transfer.Context = transferContext;
                    }
                }

                try
                {
                    await transfer.ExecuteAsync(scheduler, cancellationToken);
                }
                finally
                {
                    RemoveTransfer(transfer);
                }
            }
        }