Пример #1
0
 private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destChannel, BlobBaseClient srcBlob, BlobBaseClient destBlob)
 {
     try
     {
         Uri srcBlobUriWithCredentail = null;
         if (Channel != null && destChannel != null &&
             Channel.StorageContext != null && destChannel.StorageContext != null &&
             Channel.StorageContext.StorageAccountName == destChannel.StorageContext.StorageAccountName &&
             Channel.StorageContext.StorageAccount.Credentials.IsToken)
         {
             // if inside same account, source blob can be anonumous
             srcBlobUriWithCredentail = srcBlob.Uri;
         }
         else
         {
             srcBlobUriWithCredentail = srcBlob.GenerateUriWithCredentials(Channel.StorageContext);
         }
         await StartCopyFromUri(taskId, destChannel, srcBlobUriWithCredentail, destBlob).ConfigureAwait(false);
     }
     catch (StorageException ex)
     {
         if (0 == string.Compare(ex.Message, BlobTypeMismatch, StringComparison.OrdinalIgnoreCase))
         {
             // Current use error message to decide whether it caused by blob type mismatch,
             // We should ask xscl to expose an error code for this..
             // Opened workitem 1487579 to track this.
             throw new InvalidOperationException(Resources.DestinationBlobTypeNotMatch);
         }
         else
         {
             throw;
         }
     }
 }
Пример #2
0
        private void CopyBlobSync(IStorageBlobManagement destChannel, BlobBaseClient srcCloudBlob, BlobBaseClient destCloudBlob)
        {
            Track2Models.BlobType srcBlobType = Util.GetBlobType(srcCloudBlob, true).Value;
            if (srcBlobType != Track2Models.BlobType.Block)
            {
                throw new ArgumentException(string.Format("The cmdlet currently only support souce blob and destination blob are both block blob. The source blob type is {0}.", srcBlobType));
            }

            if (srcCloudBlob is BlobClient)
            {
                srcCloudBlob = Util.GetTrack2BlobClientWithType(srcCloudBlob, Channel.StorageContext, srcBlobType, ClientOptions);
            }
            if (destCloudBlob is BlobClient)
            {
                destCloudBlob = Util.GetTrack2BlobClientWithType(destCloudBlob, destChannel.StorageContext, srcBlobType, ClientOptions);
            }

            Func <long, Task> taskGenerator = (taskId) => CopyFromUri(taskId, destChannel, srcCloudBlob.GenerateUriWithCredentials(Channel.StorageContext), destCloudBlob);

            RunTask(taskGenerator);
        }