Exemplo n.º 1
0
        private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, CloudBlob destBlob)
        {
            bool destExist = true;

            try
            {
                await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
            }
            catch (StorageException ex)
            {
                if (ex.IsNotFoundException())
                {
                    destExist = false;
                }
                else
                {
                    throw;
                }
            }

            if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
            {
                string copyId;
                if (pageBlobTier == null)
                {
                    copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                }
                else
                {
                    copyId = await destChannel.StartCopyAsync((CloudPageBlob)destBlob, srcUri, pageBlobTier.Value, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                }
                this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
                this.WriteCloudBlobObject(taskId, destChannel, destBlob);
            }
        }
Exemplo n.º 2
0
        private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, CloudBlob destBlob)
        {
            if (UseTrack2Sdk())
            {
                BlobClient destBlobClient = AzureStorageBlob.GetTrack2BlobClient(destBlob, destChannel.StorageContext, this.ClientOptions);
                await StartCopyFromUri(taskId, destChannel, srcUri, destBlobClient).ConfigureAwait(false);

                return;
            }
            else // use track1 SDK
            {
                bool destExist = true;
                try
                {
                    await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                }
                catch (StorageException ex)
                {
                    if (ex.IsNotFoundException())
                    {
                        destExist = false;
                    }
                    else
                    {
                        throw;
                    }
                }

                ValidateBlobTier(destBlob.BlobType, pageBlobTier, standardBlobTier, rehydratePriority);

                if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
                {
                    string copyId;

                    //Clean the Metadata of the destination Blob object, or the source metadata won't overwirte the dest blob metadata. See https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob
                    destBlob.Metadata.Clear();

                    // The Blob Type and Blob Tier must match, since already checked they are match at the begin of ExecuteCmdlet().
                    if (pageBlobTier != null)
                    {
                        copyId = await destChannel.StartCopyAsync((CloudPageBlob)destBlob, srcUri, pageBlobTier.Value, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                    }
                    else if (standardBlobTier != null || rehydratePriority != null)
                    {
                        copyId = await destChannel.StartCopyAsync(destBlob, srcUri, standardBlobTier, rehydratePriority, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                    }

                    this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
                    this.WriteCloudBlobObject(taskId, destChannel, destBlob);
                }
            }
        }
        private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, CloudBlob destBlob)
        {
            bool destExist = true;

            try
            {
                await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
            }
            catch (StorageException ex)
            {
                if (ex.IsNotFoundException())
                {
                    destExist = false;
                }
                else
                {
                    throw;
                }
            }

            if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
            {
                string copyId;

                //Clean the Metadata of the destination Blob object, or the source metadata won't overwirte the dest blob metadata. See https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob
                destBlob.Metadata.Clear();

                if (pageBlobTier == null)
                {
                    copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                }
                else
                {
                    copyId = await destChannel.StartCopyAsync((CloudPageBlob)destBlob, srcUri, pageBlobTier.Value, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                }
                this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
                this.WriteCloudBlobObject(taskId, destChannel, destBlob);
            }
        }
        private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, CloudBlob destBlob)
        {

            bool destExist = true;
            try
            {
                await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
            }
            catch (StorageException ex)
            {
                if (ex.IsNotFoundException())
                {
                    destExist = false;
                }
                else
                {
                    throw;
                }
            }

            if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
            {
                string copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
                this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
                this.WriteCloudBlobObject(taskId, destChannel, destBlob);
            }
        }