Beispiel #1
0
        protected override async Task <StorageCopyState> DoStartCopyAsync()
        {
            // To copy from source to blob, DataMovement Library should overwrite destination's properties and meta datas.
            // Clear destination's meta data here to avoid using destination's meta data.
            // Please reference to https://docs.microsoft.com/en-us/rest/api/storageservices/copy-file.
            this.destFile.Metadata.Clear();

            OperationContext operationContext = Utils.GenerateOperationContext(this.TransferContext);

            if (null != this.SourceUri)
            {
                await this.destFile.StartCopyAsync(
                    this.SourceUri,
                    null,
                    null,
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                return(new StorageCopyState(this.destFile.CopyState));
            }
            else if (null != this.SourceBlob)
            {
                await this.destFile.StartCopyAsync(
                    this.SourceBlob.GenerateCopySourceUri(),
                    null,
                    null,
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destFile.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceBlob.Properties.Length;
                    copyState.BytesCopied = this.SourceBlob.Properties.Length;
                }
                return(copyState);
            }
            else
            {
                await this.destFile.StartCopyAsync(
                    this.SourceFile.GenerateCopySourceUri(),
                    null,
                    null,
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destFile.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceFile.Properties.Length;
                    copyState.BytesCopied = this.SourceFile.Properties.Length;
                }
                return(copyState);
            }
        }
        protected override async Task <StorageCopyState> DoStartCopyAsync()
        {
            AccessCondition destAccessCondition = Utils.GenerateConditionWithCustomerCondition(this.destLocation.AccessCondition);

            // To copy from source to blob, DataMovement Library should overwrite destination's properties and meta datas.
            // Clear destination's meta data here to avoid using destination's meta data.
            // Please reference to https://docs.microsoft.com/en-us/rest/api/storageservices/Copy-Blob.
            this.destBlob.Metadata.Clear();

            if (null != this.SourceUri)
            {
                await this.destBlob.StartCopyAsync(
                    this.SourceUri,
                    null,
                    destAccessCondition,
                    Utils.GenerateBlobRequestOptions(this.destLocation.BlobRequestOptions),
                    Utils.GenerateOperationContext(this.TransferContext),
                    this.CancellationToken);

                return(new StorageCopyState(this.destBlob.CopyState));
            }
            else if (null != this.SourceBlob)
            {
                AccessCondition sourceAccessCondition =
                    AccessCondition.GenerateIfMatchCondition(this.SourceBlob.Properties.ETag);

                await this.destBlob.StartCopyAsync(
                    this.SourceBlob.GenerateCopySourceUri(),
                    sourceAccessCondition,
                    destAccessCondition,
                    Utils.GenerateBlobRequestOptions(this.destLocation.BlobRequestOptions),
                    Utils.GenerateOperationContext(this.TransferContext),
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destBlob.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceBlob.Properties.Length;
                    copyState.BytesCopied = this.SourceBlob.Properties.Length;
                }
                return(copyState);
            }
            else
            {
                if (BlobType.BlockBlob == this.destBlob.BlobType)
                {
                    await(this.destBlob as CloudBlockBlob).StartCopyAsync(
                        this.SourceFile.GenerateCopySourceUri(),
                        null,
                        destAccessCondition,
                        Utils.GenerateBlobRequestOptions(this.destLocation.BlobRequestOptions),
                        Utils.GenerateOperationContext(this.TransferContext),
                        this.CancellationToken);

                    var copyState = new StorageCopyState(this.destBlob.CopyState);

                    if (copyState.Status == StorageCopyStatus.Success)
                    {
                        copyState.TotalBytes  = this.SourceFile.Properties.Length;
                        copyState.BytesCopied = this.SourceFile.Properties.Length;
                    }
                    return(copyState);
                }
                else if (BlobType.PageBlob == this.destBlob.BlobType)
                {
                    throw new InvalidOperationException(Resources.AsyncCopyFromFileToPageBlobNotSupportException);
                }
                else if (BlobType.AppendBlob == this.destBlob.BlobType)
                {
                    throw new InvalidOperationException(Resources.AsyncCopyFromFileToAppendBlobNotSupportException);
                }
                else
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  Resources.NotSupportedBlobType,
                                  this.destBlob.BlobType));
                }
            }
        }
        protected override async Task <StorageCopyState> DoStartCopyAsync()
        {
            // To copy from source to blob, DataMovement Library should overwrite destination's properties and meta datas.
            // Clear destination's meta data here to avoid using destination's meta data.
            // Please reference to https://docs.microsoft.com/en-us/rest/api/storageservices/copy-file.
            this.destFile.Metadata.Clear();

            OperationContext operationContext = Utils.GenerateOperationContext(this.TransferContext);

            if (null != this.SourceUri)
            {
                await this.destFile.StartCopyAsync(
                    this.SourceUri,
                    null,
                    null,
                    default(FileCopyOptions),
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                return(new StorageCopyState(this.destFile.CopyState));
            }
            else if (null != this.SourceBlob)
            {
                await this.destFile.StartCopyAsync(
                    this.SourceBlob.GenerateCopySourceUri(),
                    null,
                    null,
                    default(FileCopyOptions),
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destFile.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceBlob.Properties.Length;
                    copyState.BytesCopied = this.SourceBlob.Properties.Length;
                }
                return(copyState);
            }
            else
            {
                var             transfer        = this.TransferJob.Transfer;
                FileCopyOptions fileCopyOptions = new FileCopyOptions();

                if (transfer.PreserveSMBAttributes)
                {
                    fileCopyOptions.PreserveCreationTime   = transfer.PreserveSMBAttributes;
                    fileCopyOptions.PreserveLastWriteTime  = transfer.PreserveSMBAttributes;
                    fileCopyOptions.PreserveNtfsAttributes = transfer.PreserveSMBAttributes;
                    fileCopyOptions.SetArchive             = false;
                }

                fileCopyOptions.PreservePermissions = (transfer.PreserveSMBPermissions != PreserveSMBPermissions.None);

                await this.destFile.StartCopyAsync(
                    this.SourceFile.GenerateCopySourceUri(fileCopyOptions.PreservePermissions),
                    null,
                    null,
                    fileCopyOptions,
                    Utils.GenerateFileRequestOptions(this.destLocation.FileRequestOptions),
                    operationContext,
                    this.CancellationToken);

                var copyState = new StorageCopyState(this.destFile.CopyState);

                if (copyState.Status == StorageCopyStatus.Success)
                {
                    copyState.TotalBytes  = this.SourceFile.Properties.Length;
                    copyState.BytesCopied = this.SourceFile.Properties.Length;
                }
                return(copyState);
            }
        }