Skip to content

Commit fbe1981

Browse files
committed
take out common functions
1 parent 61630f5 commit fbe1981

File tree

1 file changed

+78
-70
lines changed

1 file changed

+78
-70
lines changed

src/Storage/Storage/Blob/Cmdlet/CopyAzureStorageBlob.cs

Lines changed: 78 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
2424
using Microsoft.WindowsAzure.Commands.Storage.Common;
2525
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2626
using System;
27+
using System.Collections.Generic;
2728
using System.Management.Automation;
2829
using System.Security.Permissions;
2930
using System.Threading.Tasks;
@@ -380,6 +381,29 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
380381
BlobBaseClient srcBlobClient= new BlobBaseClient(srcUri, ClientOptions);
381382
Track2Models.BlobProperties srcProperties = srcBlobClient.GetProperties(cancellationToken: this.CmdletCancellationToken).Value;
382383

384+
Track2Models.BlobHttpHeaders httpHeaders = new Track2Models.BlobHttpHeaders
385+
{
386+
ContentType = srcProperties.ContentType,
387+
ContentLanguage = srcProperties.ContentLanguage,
388+
ContentHash = srcProperties.ContentHash,
389+
ContentDisposition = srcProperties.ContentDisposition,
390+
ContentEncoding = srcProperties.ContentEncoding
391+
};
392+
393+
IDictionary<string, string> blobTags = null;
394+
395+
try
396+
{
397+
blobTags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
398+
}
399+
catch (global::Azure.RequestFailedException)
400+
{
401+
if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
402+
{
403+
return;
404+
}
405+
}
406+
383407
//Prepare progress handler
384408
string activity = String.Format("Copy Blob {0} to {1}", srcBlobClient.Name, destBlob.Name);
385409
string status = "Prepare to Copy Blob";
@@ -401,28 +425,21 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
401425
PageBlobClient destPageBlob = (PageBlobClient)Util.GetTrack2BlobClientWithType(destBlob, destChannel.StorageContext, Track2Models.BlobType.Page, ClientOptions);
402426

403427
Track2Models.PageBlobCreateOptions pageBlobCreateOptions = new Track2Models.PageBlobCreateOptions();
404-
Track2Models.BlobHttpHeaders httpHeaders = new Track2Models.BlobHttpHeaders
405-
{
406-
ContentType = srcProperties.ContentType,
407-
ContentLanguage = srcProperties.ContentLanguage,
408-
ContentHash = srcProperties.ContentHash,
409-
ContentDisposition = srcProperties.ContentDisposition,
410-
ContentEncoding = srcProperties.ContentEncoding
411-
};
412428
pageBlobCreateOptions.HttpHeaders = httpHeaders;
413429
pageBlobCreateOptions.Metadata = srcProperties.Metadata;
414-
415-
try
416-
{
417-
pageBlobCreateOptions.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
418-
}
419-
catch (global::Azure.RequestFailedException)
420-
{
421-
if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
422-
{
423-
return;
424-
}
425-
}
430+
pageBlobCreateOptions.Tags = blobTags ?? null;
431+
432+
//try
433+
//{
434+
// pageBlobCreateOptions.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
435+
//}
436+
//catch (global::Azure.RequestFailedException)
437+
//{
438+
// if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
439+
// {
440+
// return;
441+
// }
442+
//}
426443

427444
destPageBlob.Create(srcProperties.ContentLength, pageBlobCreateOptions, this.CmdletCancellationToken);
428445

@@ -444,28 +461,21 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
444461
AppendBlobClient destAppendBlob = (AppendBlobClient)Util.GetTrack2BlobClientWithType(destBlob, destChannel.StorageContext, Track2Models.BlobType.Append, ClientOptions);
445462

446463
Track2Models.AppendBlobCreateOptions appendBlobCreateOptions = new Track2Models.AppendBlobCreateOptions();
447-
Track2Models.BlobHttpHeaders appendBlobHttpHeaders = new Track2Models.BlobHttpHeaders
448-
{
449-
ContentType = srcProperties.ContentType,
450-
ContentLanguage = srcProperties.ContentLanguage,
451-
ContentEncoding = srcProperties.ContentEncoding,
452-
ContentDisposition = srcProperties.ContentDisposition,
453-
ContentHash = srcProperties.ContentHash
454-
};
455-
appendBlobCreateOptions.HttpHeaders = appendBlobHttpHeaders;
464+
appendBlobCreateOptions.HttpHeaders = httpHeaders;
456465
appendBlobCreateOptions.Metadata = srcProperties.Metadata;
457-
458-
try
459-
{
460-
appendBlobCreateOptions.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
461-
}
462-
catch (global::Azure.RequestFailedException)
463-
{
464-
if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
465-
{
466-
return;
467-
}
468-
}
466+
appendBlobCreateOptions.Tags = blobTags ?? null;
467+
468+
//try
469+
//{
470+
// appendBlobCreateOptions.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
471+
//}
472+
//catch (global::Azure.RequestFailedException)
473+
//{
474+
// if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
475+
// {
476+
// return;
477+
// }
478+
//}
469479

470480
destAppendBlob.Create(appendBlobCreateOptions, this.CmdletCancellationToken);
471481

@@ -504,18 +514,19 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
504514
}
505515
options.SourceConditions = this.BlobRequestConditions;
506516
options.Metadata = srcProperties.Metadata;
507-
508-
try
509-
{
510-
options.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
511-
}
512-
catch (global::Azure.RequestFailedException)
513-
{
514-
if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
515-
{
516-
return;
517-
}
518-
}
517+
options.Tags = blobTags ?? null;
518+
519+
//try
520+
//{
521+
// options.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
522+
//}
523+
//catch (global::Azure.RequestFailedException)
524+
//{
525+
// if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
526+
// {
527+
// return;
528+
// }
529+
//}
519530
destBlobClient.SyncCopyFromUri(srcUri, options, this.CmdletCancellationToken);
520531

521532
// Set rehydrate priority
@@ -530,29 +541,26 @@ private async Task CopyFromUri(long taskId, IStorageBlobManagement destChannel,
530541
BlockBlobClient destBlockBlob = (BlockBlobClient)Util.GetTrack2BlobClientWithType(destBlob, destChannel.StorageContext, Track2Models.BlobType.Block, ClientOptions);
531542

532543
Track2Models.CommitBlockListOptions commitBlockListOptions = new Track2Models.CommitBlockListOptions();
533-
commitBlockListOptions.HttpHeaders = new Track2Models.BlobHttpHeaders();
534-
commitBlockListOptions.HttpHeaders.ContentType = srcProperties.ContentType;
535-
commitBlockListOptions.HttpHeaders.ContentHash = srcProperties.ContentHash;
536-
commitBlockListOptions.HttpHeaders.ContentEncoding = srcProperties.ContentEncoding;
537-
commitBlockListOptions.HttpHeaders.ContentLanguage = srcProperties.ContentLanguage;
538-
commitBlockListOptions.HttpHeaders.ContentDisposition = srcProperties.ContentDisposition;
544+
commitBlockListOptions.HttpHeaders = httpHeaders;
539545
commitBlockListOptions.Metadata = srcProperties.Metadata;
546+
commitBlockListOptions.Tags = blobTags ?? null;
547+
540548
if (standardBlobTier != null)
541549
{
542550
commitBlockListOptions.AccessTier = Util.ConvertAccessTier_Track1ToTrack2(standardBlobTier);
543551
}
544552

545-
try
546-
{
547-
commitBlockListOptions.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
548-
}
549-
catch (global::Azure.RequestFailedException)
550-
{
551-
if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
552-
{
553-
return;
554-
}
555-
}
553+
//try
554+
//{
555+
// commitBlockListOptions.Tags = srcBlobClient.GetTags(cancellationToken: this.CmdletCancellationToken).Value.Tags;
556+
//}
557+
//catch (global::Azure.RequestFailedException)
558+
//{
559+
// if (!this.Force && !OutputStream.ConfirmAsync("Can't get source blob Tags, so source blob tags won't be copied to dest blob. Do you want to continue the blob copy?").Result)
560+
// {
561+
// return;
562+
// }
563+
//}
556564

557565
long blockLength = GetBlockLength(srcProperties.ContentLength);
558566
string[] blockIDs = GetBlockIDs(srcProperties.ContentLength, blockLength, destBlockBlob.Name);

0 commit comments

Comments
 (0)