/// <summary>
        /// Execute the transfer asynchronously.
        /// </summary>
        /// <param name="scheduler">Transfer scheduler</param>
        /// <param name="cancellationToken">Token that can be used to cancel the transfer.</param>
        /// <returns>A task representing the transfer operation.</returns>
        public override async Task ExecuteAsync(TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            if (this.transferJob.Status == TransferJobStatus.Finished ||
                this.transferJob.Status == TransferJobStatus.Skipped)
            {
                return;
            }

            if (transferJob.Status == TransferJobStatus.Failed)
            {
                // Resuming a failed transfer job
                this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Transfer);
            }

            try
            {
                await scheduler.ExecuteJobAsync(transferJob, cancellationToken);

                this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Finished);
            }
            catch (TransferException exception)
            {
                if (exception.ErrorCode == TransferErrorCode.NotOverwriteExistingDestination)
                {
                    // transfer skipped
                    this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Skipped);
                }
                else
                {
                    // transfer failed
                    this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Failed);
                }

                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute the transfer asynchronously.
        /// </summary>
        /// <param name="scheduler">Transfer scheduler</param>
        /// <param name="cancellationToken">Token that can be used to cancel the transfer.</param>
        /// <returns>A task representing the transfer operation.</returns>
        public override async Task ExecuteAsync(TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            if (this.transferJob.Status == TransferJobStatus.Finished ||
                this.transferJob.Status == TransferJobStatus.Skipped)
            {
                return;
            }

            TransferEventArgs eventArgs = new TransferEventArgs(this.Source.ToString(), this.Destination.ToString());

            eventArgs.StartTime = DateTime.UtcNow;

            if (this.transferJob.Status == TransferJobStatus.Failed)
            {
                // Resuming a failed transfer job
                if (string.IsNullOrEmpty(this.transferJob.CopyId))
                {
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Transfer);
                }
                else
                {
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Monitor);
                }
            }

            try
            {
                await scheduler.ExecuteJobAsync(this.transferJob, cancellationToken);

                this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Finished);

                eventArgs.EndTime = DateTime.UtcNow;

                if (this.Context != null)
                {
                    this.Context.OnTransferSuccess(eventArgs);
                }
            }
            catch (TransferException exception)
            {
                eventArgs.EndTime   = DateTime.UtcNow;
                eventArgs.Exception = exception;

                if (exception.ErrorCode == TransferErrorCode.NotOverwriteExistingDestination)
                {
                    // transfer skipped
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Skipped);
                    if (this.Context != null)
                    {
                        this.Context.OnTransferSkipped(eventArgs);
                    }

                    throw;
                }
                else
                {
                    // transfer failed
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Failed);
                    if (this.Context != null)
                    {
                        this.Context.OnTransferFailed(eventArgs);
                    }

                    throw;
                }
            }
            catch (Exception ex)
            {
                eventArgs.EndTime   = DateTime.UtcNow;
                eventArgs.Exception = ex;

                // transfer failed
                this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Failed);

                if (this.Context != null)
                {
                    this.Context.OnTransferFailed(eventArgs);
                }

                throw;
            }
        }
        /// <summary>
        /// Execute the transfer asynchronously.
        /// </summary>
        /// <param name="scheduler">Transfer scheduler</param>
        /// <param name="cancellationToken">Token that can be used to cancel the transfer.</param>
        /// <returns>A task representing the transfer operation.</returns>
        public override async Task ExecuteAsync(TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            if (this.transferJob.Status == TransferJobStatus.Finished ||
                this.transferJob.Status == TransferJobStatus.Skipped)
            {
                return;
            }

            TransferEventArgs eventArgs = new TransferEventArgs(this.Source.ToString(), this.Destination.ToString());
            eventArgs.StartTime = DateTime.UtcNow;

            if (this.transferJob.Status == TransferJobStatus.Failed)
            {
                // Resuming a failed transfer job
                if (string.IsNullOrEmpty(this.transferJob.CopyId))
                {
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Transfer);
                }
                else
                {
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Monitor);
                }
            }

            try
            {
                await scheduler.ExecuteJobAsync(this.transferJob, cancellationToken);
                this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Finished);

                eventArgs.EndTime = DateTime.UtcNow;

                if(this.Context != null)
                {
                    this.Context.OnTransferSuccess(eventArgs);
                }
            }
            catch (TransferException exception)
            {
                eventArgs.EndTime = DateTime.UtcNow;
                eventArgs.Exception = exception;

                if (exception.ErrorCode == TransferErrorCode.NotOverwriteExistingDestination)
                {
                    // transfer skipped
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Skipped);
                    if (this.Context != null)
                    {
                        this.Context.OnTransferSkipped(eventArgs);
                    }

                    throw;
                }
                else
                {
                    // transfer failed
                    this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Failed);
                    if (this.Context != null)
                    {
                        this.Context.OnTransferFailed(eventArgs);
                    }

                    throw;
                }
            }
            catch (Exception ex)
            {
                eventArgs.EndTime = DateTime.UtcNow;
                eventArgs.Exception = ex;

                // transfer failed
                this.UpdateTransferJobStatus(this.transferJob, TransferJobStatus.Failed);

                if (this.Context != null)
                {
                    this.Context.OnTransferFailed(eventArgs);
                }

                throw;
            }
        }
        /// <summary>
        /// Execute the transfer asynchronously.
        /// </summary>
        /// <param name="scheduler">Transfer scheduler</param>
        /// <param name="cancellationToken">Token that can be used to cancel the transfer.</param>
        /// <returns>A task representing the transfer operation.</returns>
        public override async Task ExecuteAsync(TransferScheduler scheduler, CancellationToken cancellationToken)
        {
            if (this.transferJob.Status == TransferJobStatus.Finished ||
                this.transferJob.Status == TransferJobStatus.Skipped)
            {
                return;
            }

            if (transferJob.Status == TransferJobStatus.Failed)
            {
                // Resuming a failed transfer job
                this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Transfer);
            }

            try
            {
                await scheduler.ExecuteJobAsync(transferJob, cancellationToken);
                this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Finished);
            }
            catch (TransferException exception)
            {
                if (exception.ErrorCode == TransferErrorCode.NotOverwriteExistingDestination)
                {
                    // transfer skipped
                    this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Skipped);
                }
                else
                {
                    // transfer failed
                    this.UpdateTransferJobStatus(transferJob, TransferJobStatus.Failed);
                }

                throw;
            }
        }