Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class.
 /// </summary>
 /// <param name="info">Serialization information.</param>
 /// <param name="context">Streaming context.</param>
 protected SingleObjectTransfer(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.transferJob           = (TransferJob)info.GetValue(TransferJobName, typeof(TransferJob));
     this.shouldTransferChecked = info.GetBoolean(ShouldTransferCheckedName);
     this.transferJob.Transfer  = this;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class.
 /// </summary>
 /// <param name="other">Another <see cref="SingleObjectTransfer"/> object. </param>
 private SingleObjectTransfer(SingleObjectTransfer other)
     : base(other)
 {
     this.ProgressTracker      = other.ProgressTracker.Copy();
     this.transferJob          = other.transferJob.Copy();
     this.transferJob.Transfer = this;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransferJob"/> class.
 /// </summary>
 /// <param name="other">The other transfer job to copy properties.</param>
 private TransferJob(TransferJob other)
 {
     this.Overwrite  = other.Overwrite;
     this.CopyId     = other.CopyId;
     this.CheckPoint = other.CheckPoint.Copy();
     this.Status     = other.Status;
 }
        private static ServiceSideSyncCopyController CreateServiceSideSyncCopyConstroller(
            TransferScheduler transferScheduler,
            TransferJob transferJob,
            CancellationToken cancellationToken)
        {
            CloudBlob destinationBlob = transferJob.Destination.Instance as CloudBlob;

            if (null == destinationBlob)
            {
                throw new TransferException(Resources.ServiceSideSyncCopyNotSupportException);
            }

            if (BlobType.PageBlob == destinationBlob.BlobType)
            {
                return(new PageBlobServiceSideSyncCopyController(transferScheduler, transferJob, cancellationToken));
            }
            else if (BlobType.AppendBlob == destinationBlob.BlobType)
            {
                return(new AppendBlobServiceSideSyncCopyController(transferScheduler, transferJob, cancellationToken));
            }
            else if (BlobType.BlockBlob == destinationBlob.BlobType)
            {
                return(new BlockBlobServiceSideSyncCopyController(transferScheduler, transferJob, cancellationToken));
            }
            else
            {
                throw new TransferException(string.Format(CultureInfo.CurrentCulture, Resources.NotSupportedBlobType, destinationBlob.BlobType));
            }
        }
        private static TransferControllerBase GenerateTransferConstroller(
            TransferScheduler transferScheduler,
            TransferJob transferJob,
            CancellationToken cancellationToken)
        {
            TransferControllerBase controller = null;

            switch (transferJob.Transfer.TransferMethod)
            {
            case TransferMethod.SyncCopy:
                controller = new SyncTransferController(transferScheduler, transferJob, cancellationToken);
                break;

            case TransferMethod.ServiceSideAsyncCopy:
                controller = CreateAsyncCopyController(transferScheduler, transferJob, cancellationToken);
                break;

            case TransferMethod.ServiceSideSyncCopy:
                controller = CreateServiceSideSyncCopyConstroller(transferScheduler, transferJob, cancellationToken);
                break;

            case TransferMethod.DummyCopy:
                controller = new DummyTransferController(transferScheduler, transferJob, cancellationToken);
                break;
            }

            return(controller);
        }
        private async Task ExecuteJobInternalAsync(
            TransferJob job,
            CancellationToken cancellationToken)
        {
            Debug.Assert(
                job.Status == TransferJobStatus.NotStarted ||
                job.Status == TransferJobStatus.SkippedDueToShouldNotTransfer ||
                job.Status == TransferJobStatus.Monitor ||
                job.Status == TransferJobStatus.Transfer);

            if (job.Status == TransferJobStatus.SkippedDueToShouldNotTransfer)
            {
                return;
            }

            TransferControllerBase controller = GenerateTransferConstroller(this, job, cancellationToken);

            Utils.CheckCancellation(this.cancellationTokenSource.Token);
            this.controllerQueue.Add(controller, this.cancellationTokenSource.Token);

            try
            {
                await controller.TaskCompletionSource.Task;
            }

#if EXPECT_INTERNAL_WRAPPEDSTORAGEEXCEPTION
            catch (Exception ex) when(ex is StorageException || (ex is AggregateException && ex.InnerException is StorageException))
            {
                var storageException = ex as StorageException ?? ex.InnerException as StorageException;

                if (storageException.InnerException is OperationCanceledException)
                {
                    throw storageException.InnerException;
                }

                throw new TransferException(TransferErrorCode.Unknown,
                                            Resources.UncategorizedException,
                                            storageException);
            }
#else
            catch (StorageException se)
            {
                throw new TransferException(
                          TransferErrorCode.Unknown,
                          Resources.UncategorizedException,
                          se);
            }
#endif
            finally
            {
                controller.Dispose();
            }
        }
Ejemplo n.º 7
0
 private static void UpdateProgress(TransferJob job, Action updateAction)
 {
     try
     {
         job.ProgressUpdateLock?.EnterReadLock();
         updateAction();
     }
     finally
     {
         job.ProgressUpdateLock?.ExitReadLock();
     }
 }
        /// <summary>
        /// Execute a transfer job asynchronously.
        /// </summary>
        /// <param name="job">Transfer job to be executed.</param>
        /// <param name="cancellationToken">Token used to notify the job that it should stop.</param>
        public Task ExecuteJobAsync(
            TransferJob job,
            CancellationToken cancellationToken)
        {
            if (null == job)
            {
                throw new ArgumentNullException(nameof(job));
            }

            lock (this.disposeLock)
            {
                this.CheckDisposed();

                return(this.ExecuteJobInternalAsync(job, cancellationToken));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleObjectTransfer"/> class.
        /// This constructor will check whether source and destination is valid for the operation:
        /// Uri is only valid for non-staging copy.
        /// cannot copy from local file/stream to local file/stream
        /// </summary>
        /// <param name="source">Transfer source.</param>
        /// <param name="dest">Transfer destination.</param>
        /// <param name="transferMethod">Transfer method, see <see cref="TransferMethod"/> for detail available methods.</param>
        public SingleObjectTransfer(TransferLocation source, TransferLocation dest, TransferMethod transferMethod)
            : base(source, dest, transferMethod)
        {
            Debug.Assert(source != null && dest != null);
            Debug.Assert(
                source.Type == TransferLocationType.FilePath || source.Type == TransferLocationType.Stream ||
                source.Type == TransferLocationType.AzureBlob || source.Type == TransferLocationType.AzureFile ||
                source.Type == TransferLocationType.SourceUri);
            Debug.Assert(
                dest.Type == TransferLocationType.FilePath || dest.Type == TransferLocationType.Stream ||
                dest.Type == TransferLocationType.AzureBlob || dest.Type == TransferLocationType.AzureFile ||
                dest.Type == TransferLocationType.SourceUri);
            Debug.Assert(!((source.Type == TransferLocationType.FilePath || source.Type == TransferLocationType.Stream) &&
                           (dest.Type == TransferLocationType.FilePath || dest.Type == TransferLocationType.Stream)));

            if (source.Type == TransferLocationType.AzureBlob && dest.Type == TransferLocationType.AzureBlob)
            {
                CloudBlob sourceBlob = (source as AzureBlobLocation).Blob;
                CloudBlob destBlob   = (dest as AzureBlobLocation).Blob;
                if (sourceBlob.BlobType != destBlob.BlobType)
                {
                    throw new InvalidOperationException(Resources.SourceAndDestinationBlobTypeDifferent);
                }

                if (StorageExtensions.Equals(sourceBlob, destBlob))
                {
                    throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException);
                }
            }

            if (source.Type == TransferLocationType.AzureFile && dest.Type == TransferLocationType.AzureFile)
            {
                CloudFile sourceFile = (source as AzureFileLocation).AzureFile;
                CloudFile destFile   = (dest as AzureFileLocation).AzureFile;
                if (string.Equals(sourceFile.SnapshotQualifiedUri.Host, destFile.SnapshotQualifiedUri.Host, StringComparison.OrdinalIgnoreCase) &&
                    string.Equals(sourceFile.SnapshotQualifiedUri.PathAndQuery, destFile.SnapshotQualifiedUri.PathAndQuery, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException);
                }
            }

            this.transferJob = new TransferJob(this);
        }
Ejemplo n.º 10
0
        public void UpdateTransferJobStatus(TransferJob transferJob, TransferJobStatus targetStatus)
        {
            lock (this.ProgressTracker)
            {
                switch (targetStatus)
                {
                case TransferJobStatus.Transfer:
                case TransferJobStatus.Monitor:
                    if (transferJob.Status == TransferJobStatus.Failed)
                    {
                        UpdateProgress(transferJob, () => this.ProgressTracker.AddNumberOfFilesFailed(-1));
                    }

                    break;

                case TransferJobStatus.Skipped:
                    UpdateProgress(transferJob, () => this.ProgressTracker.AddNumberOfFilesSkipped(1));
                    break;

                case TransferJobStatus.Finished:
                    UpdateProgress(transferJob, () => this.ProgressTracker.AddNumberOfFilesTransferred(1));
                    break;

                case TransferJobStatus.Failed:
                    UpdateProgress(transferJob, () => this.ProgressTracker.AddNumberOfFilesFailed(1));
                    break;

                case TransferJobStatus.NotStarted:

                default:
                    break;
                }

                transferJob.Status = targetStatus;
            }

            transferJob.Transfer.UpdateJournal();
        }
        private static AsyncCopyController CreateAsyncCopyController(TransferScheduler transferScheduler, TransferJob transferJob, CancellationToken cancellationToken)
        {
            if (transferJob.Destination.Type == TransferLocationType.AzureFile)
            {
                return(new FileAsyncCopyController(transferScheduler, transferJob, cancellationToken));
            }

            if (transferJob.Destination.Type == TransferLocationType.AzureBlob)
            {
                return(new BlobAsyncCopyController(transferScheduler, transferJob, cancellationToken));
            }

            throw new InvalidOperationException(Resources.CanOnlyCopyToFileOrBlobException);
        }
        private async Task ExecuteJobInternalAsync(
            TransferJob job,
            CancellationToken cancellationToken)
        {
            Debug.Assert(
                job.Status == TransferJobStatus.NotStarted ||
                job.Status == TransferJobStatus.Monitor ||
                job.Status == TransferJobStatus.Transfer);

            TransferControllerBase controller = null;

            switch (job.Transfer.TransferMethod)
            {
            case TransferMethod.SyncCopy:
                controller = new SyncTransferController(this, job, cancellationToken);
                break;

            case TransferMethod.AsyncCopy:
                controller = AsyncCopyController.CreateAsyncCopyController(this, job, cancellationToken);
                break;

            case TransferMethod.DummyCopy:
                controller = new DummyTransferController(this, job, cancellationToken);
                break;
            }

            Utils.CheckCancellation(this.cancellationTokenSource.Token);
            this.controllerQueue.Add(controller, this.cancellationTokenSource.Token);

            try
            {
                await controller.TaskCompletionSource.Task;
            }

#if EXPECT_INTERNAL_WRAPPEDSTORAGEEXCEPTION
            catch (Exception ex) when(ex is StorageException || (ex is AggregateException && ex.InnerException is StorageException))
            {
                var storageException = ex as StorageException ?? ex.InnerException as StorageException;

                if (storageException.InnerException is OperationCanceledException)
                {
                    throw storageException.InnerException;
                }

                throw new TransferException(TransferErrorCode.Unknown,
                                            Resources.UncategorizedException,
                                            storageException);
            }
#else
            catch (StorageException se)
            {
                throw new TransferException(
                          TransferErrorCode.Unknown,
                          Resources.UncategorizedException,
                          se);
            }
#endif
            finally
            {
                controller.Dispose();
            }
        }