コード例 #1
0
        private CloudBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, BlobType blobType)
        {
            NameUtil.ValidateContainerName(destContainerName);
            NameUtil.ValidateBlobName(destBlobName);

            CloudBlobContainer container = destChannel.GetContainerReference(destContainerName);
            CloudBlob          destBlob  = null;

            if (BlobType.PageBlob == blobType)
            {
                destBlob = container.GetPageBlobReference(destBlobName);
            }
            else if (BlobType.BlockBlob == blobType)
            {
                destBlob = container.GetBlockBlobReference(destBlobName);
            }
            else if (BlobType.AppendBlob == blobType)
            {
                destBlob = container.GetAppendBlobReference(destBlobName);
            }
            else
            {
                throw new ArgumentException(String.Format(Resources.InvalidBlobType, blobType, destBlobName));
            }

            return(destBlob);
        }
コード例 #2
0
        /// <summary>
        /// Start copy using transfer mangager by source uri
        /// </summary>
        /// <param name="uri">source uri</param>
        /// <param name="destContainer">Destination CloudBlobContainer object</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainer.Name);
            NameUtil.ValidateBlobName(destBlobName);

            CloudBlob sourceBlob   = new CloudBlob(uri);
            BlobType  destBlobType = BlobType.BlockBlob;

            try
            {
                await sourceBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);

                //When the source Uri is a file Uri, will get BlobType.Unspecified, and should use block blob in destination
                if (sourceBlob.BlobType != BlobType.Unspecified)
                {
                    destBlobType = sourceBlob.BlobType;
                }
            }
            catch (StorageException)
            {
                //use block blob by default
                destBlobType = BlobType.BlockBlob;
            }
            CloudBlob destBlob = GetDestBlob(destChannel, destContainer.Name, destBlobName, destBlobType);

            await this.StartCopyFromUri(taskId, destChannel, uri, destBlob);
        }
コード例 #3
0
        /// <summary>
        /// Start copy using transfer mangager by source uri
        /// </summary>
        /// <param name="uri">source uri</param>
        /// <param name="destContainer">Destination CloudBlobContainer object</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainer.Name);
            NameUtil.ValidateBlobName(destBlobName);

            await this.StartCopyFromUri(taskId, destChannel, uri, destContainer.GetBlockBlobReference(destBlobName));
        }
コード例 #4
0
        /// <summary>
        /// Start copy using transfer mangager by source uri
        /// </summary>
        /// <param name="uri">source uri</param>
        /// <param name="destContainer">Destination CloudBlobContainer object</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private async Task StartCopyInTransferManager(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainer.Name);
            NameUtil.ValidateBlobName(destBlobName);
            Dictionary <string, string> BlobPath = new Dictionary <string, string>()
            {
                { "Container", destContainer.Name },
                { "Blob", destBlobName }
            };

            DataMovementUserData data = new DataMovementUserData()
            {
                Data    = BlobPath,
                TaskId  = taskId,
                Channel = destChannel,
                Record  = null
            };

            TransferJob startCopyJob = new TransferJob(
                new TransferLocation(uri),
                new TransferLocation(destContainer.GetBlockBlobReference(destBlobName)),
                TransferMethod.AsyncCopyInAzureStorageWithoutMonitor);

            await this.EnqueueStartCopyJob(startCopyJob, data);
        }
コード例 #5
0
        private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, BlobBaseClient sourceBlob, BlobBaseClient destBlob)
        {
            NameUtil.ValidateBlobName(sourceBlob.Name);
            NameUtil.ValidateContainerName(destBlob.BlobContainerName);
            NameUtil.ValidateBlobName(destBlob.Name);

            await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob).ConfigureAwait(false);
        }
コード例 #6
0
        /// <summary>
        /// Get blob with copy status by CloudBlob object
        /// </summary>
        /// <param name="blob">CloudBlob object</param>
        /// <returns>CloudBlob object</returns>
        private CloudBlob GetCloudBlobObject(CloudBlob blob)
        {
            NameUtil.ValidateBlobName(blob.Name);

            ValidateBlobType(blob);

            return(blob);
        }
コード例 #7
0
        /// <summary>
        /// Start copy using transfer mangager by source CloudBlob object
        /// </summary>
        /// <param name="blob">Source CloudBlob object</param>
        /// <param name="destContainer">Destination CloudBlobContainer object</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, CloudBlob sourceBlob, CloudBlob destBlob)
        {
            NameUtil.ValidateBlobName(sourceBlob.Name);
            NameUtil.ValidateContainerName(destBlob.Container.Name);
            NameUtil.ValidateBlobName(destBlob.Name);

            await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob);
        }
コード例 #8
0
        private void CopyBlobSync(IStorageBlobManagement SrcChannel, IStorageBlobManagement destChannel, string srcContainerName, string srcBlobName, string destContainerName, string destBlobName)
        {
            NameUtil.ValidateBlobName(srcBlobName);
            NameUtil.ValidateContainerName(srcContainerName);

            BlobBaseClient srcBlobBaseClient = Util.GetTrack2BlobServiceClient(SrcChannel.StorageContext, ClientOptions).GetBlobContainerClient(srcContainerName).GetBlobBaseClient(srcBlobName);

            this.CopyBlobSync(destChannel, srcBlobBaseClient, destContainerName, destBlobName);
        }
コード例 #9
0
        private BlobBaseClient GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, global::Azure.Storage.Blobs.Models.BlobType?blobType)
        {
            NameUtil.ValidateContainerName(destContainerName);
            NameUtil.ValidateBlobName(destBlobName);

            BlobContainerClient container = AzureStorageContainer.GetTrack2BlobContainerClient(destChannel.GetContainerReference(destContainerName), destChannel.StorageContext, ClientOptions);
            BlobBaseClient      destBlob  = Util.GetTrack2BlobClient(container, destBlobName, destChannel.StorageContext, null, null, null, ClientOptions, blobType is null ? global::Azure.Storage.Blobs.Models.BlobType.Block : blobType.Value);

            return(destBlob);
        }
        private CloudPageBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainerName);
            NameUtil.ValidateBlobName(destBlobName);

            CloudBlobContainer container = destChannel.GetContainerReference(destContainerName);
            CloudPageBlob      destBlob  = container.GetPageBlobReference(destBlobName);

            return(destBlob);
        }
コード例 #11
0
        /// <summary>
        /// Stop copy operation by CloudBlobContainer
        /// </summary>
        /// <param name="container">CloudBlobContainer object</param>
        /// <param name="blobName">Blob name</param>
        /// <param name="copyId">Copy id</param>
        private async Task StopCopyBlob(long taskId, IStorageBlobManagement localChannel, CloudBlobContainer container, string blobName, string copyId)
        {
            NameUtil.ValidateBlobName(blobName);
            NameUtil.ValidateContainerName(container.Name);

            AccessCondition    accessCondition = null;
            BlobRequestOptions options         = RequestOptions;
            CloudBlob          blob            = GetBlobReferenceFromServerWithContainer(localChannel, container, blobName, accessCondition, options, OperationContext);

            await StopCopyBlob(taskId, localChannel, blob, copyId).ConfigureAwait(false);
        }
コード例 #12
0
        /// <summary>
        /// Get blob with copy status by CloudBlobContainer object
        /// </summary>
        /// <param name="container">CloudBlobContainer object</param>
        /// <param name="blobName">Blob name</param>
        /// <returns>CloudBlob object</returns>
        private CloudBlob GetCloudBlobObject(CloudBlobContainer container, string blobName)
        {
            AccessCondition    accessCondition = null;
            BlobRequestOptions options         = RequestOptions;

            NameUtil.ValidateBlobName(blobName);
            NameUtil.ValidateContainerName(container.Name);

            CloudBlob blob = GetBlobReferenceFromServerWithContainer(Channel, container, blobName, accessCondition, options, OperationContext);

            return(GetCloudBlobObject(blob));
        }
コード例 #13
0
        private void CopyBlobSync(IStorageBlobManagement destChannel, BlobBaseClient srcBlobBaseClient, string destContainerName, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainerName);
            if (string.IsNullOrEmpty(destBlobName))
            {
                destBlobName = srcBlobBaseClient.Name;
            }
            else
            {
                NameUtil.ValidateBlobName(destBlobName);
            }
            BlobBaseClient destBlob = this.GetDestBlob(destChannel, destContainerName, destBlobName, Util.GetBlobType(srcBlobBaseClient));

            this.CopyBlobSync(destChannel, srcBlobBaseClient, destBlob);
        }
コード例 #14
0
        /// <summary>
        /// Start copy operation by container name and blob name
        /// </summary>
        /// <param name="srcContainerName">Source container name</param>
        /// <param name="srcBlobName">Source blob name</param>
        /// <param name="destContainer">Destinaion container name</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private void StartCopyBlob(IStorageBlobManagement SrcChannel, IStorageBlobManagement destChannel, string srcContainerName, string srcBlobName, string destContainerName, string destBlobName)
        {
            NameUtil.ValidateBlobName(srcBlobName);
            NameUtil.ValidateContainerName(srcContainerName);

            if (string.IsNullOrEmpty(destBlobName))
            {
                destBlobName = srcBlobName;
            }

            AccessCondition    accessCondition = null;
            BlobRequestOptions options         = RequestOptions;
            CloudBlobContainer container       = SrcChannel.GetContainerReference(srcContainerName);
            CloudBlob          blob            = GetBlobReferenceFromServerWithContainer(SrcChannel, container, srcBlobName, accessCondition, options, OperationContext);

            this.StartCopyBlob(destChannel, blob, destContainerName, destBlobName);
        }
        /// <summary>
        /// Start copy using transfer mangager by source uri
        /// </summary>
        /// <param name="uri">source uri</param>
        /// <param name="destContainer">Destination CloudBlobContainer object</param>
        /// <param name="destBlobName">Destination blob name</param>
        /// <returns>Destination CloudBlob object</returns>
        private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChannel, Uri uri, CloudBlobContainer destContainer, string destBlobName)
        {
            NameUtil.ValidateContainerName(destContainer.Name);
            NameUtil.ValidateBlobName(destBlobName);

            CloudPageBlob sourceBlob = new CloudPageBlob(uri);
            //try
            //{
            await sourceBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);

            VerifyIncrementalCopySourceBlob(sourceBlob);

            //}
            //catch (StorageException)
            //{
            //    //The source blob don't have read permission
            //    //We should no block the copy in this case,
            //}
            CloudPageBlob destBlob = GetDestBlob(destChannel, destContainer.Name, destBlobName);

            await this.StartCopyFromUri(taskId, destChannel, uri, destBlob);
        }
コード例 #16
0
        private void StartCopyFromBlob()
        {
            CloudBlob blob = null;
            string    sourceBlobRelativeName = null;

            if (null != this.SrcBlob)
            {
                blob = this.SrcBlob;
                sourceBlobRelativeName = blob.Name;
            }
            else
            {
                CloudBlobContainer srcContainer = null;

                if (null != this.SrcContainer)
                {
                    srcContainer = this.SrcContainer;
                }
                else
                {
                    NameUtil.ValidateContainerName(this.SrcContainerName);
                    srcContainer = this.blobChannel.GetContainerReference(this.SrcContainerName);
                }
                NameUtil.ValidateBlobName(this.SrcBlobName);
                blob = srcContainer.GetBlobReference(this.SrcBlobName);
                sourceBlobRelativeName = this.SrcBlobName;
            }

            CloudFile destFile = GetDestFile();

            Func <long, Task> taskGenerator = (taskId) => StartAsyncCopy(
                taskId,
                destFile,
                () => this.ConfirmOverwrite(blob.SnapshotQualifiedUri.ToString(), destFile.SnapshotQualifiedUri.ToString()),
                () => destFile.StartCopyAsync(blob.GenerateCopySourceBlob(), null, null, this.RequestOptions, this.OperationContext));

            this.RunTask(taskGenerator);
        }