Exemplo n.º 1
0
        private static TransferLocation GetSourceTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
                AzureBlobDirectoryLocation azureBlobDirLocation = dirLocation as AzureBlobDirectoryLocation;
                AzureBlobEntry             azureBlobEntry       = entry as AzureBlobEntry;

                AzureBlobLocation azureBlobLocation = new AzureBlobLocation(azureBlobEntry.Blob);
                azureBlobLocation.BlobRequestOptions = azureBlobDirLocation.BlobRequestOptions;

                return(azureBlobLocation);

            case TransferLocationType.AzureFileDirectory:
                AzureFileDirectoryLocation azureFileDirLocation = dirLocation as AzureFileDirectoryLocation;
                AzureFileEntry             azureFileEntry       = entry as AzureFileEntry;

                AzureFileLocation azureFileLocation = new AzureFileLocation(azureFileEntry.File);
                azureFileLocation.FileRequestOptions = azureFileDirLocation.FileRequestOptions;

                return(azureFileLocation);

            case TransferLocationType.LocalDirectory:
                FileEntry fileEntry = entry as FileEntry;

                return(new FileLocation(fileEntry.FullPath));

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
Exemplo n.º 2
0
 private static void UpdateCredentials(TransferLocation dirLocation, TransferLocation subLocation)
 {
     if (dirLocation.Type == TransferLocationType.AzureBlobDirectory)
     {
         AzureBlobDirectoryLocation blobDirectoryLocation = dirLocation as AzureBlobDirectoryLocation;
         (subLocation as AzureBlobLocation).UpdateCredentials(blobDirectoryLocation.BlobDirectory.ServiceClient.Credentials);
     }
     else if (dirLocation.Type == TransferLocationType.AzureFileDirectory)
     {
         AzureFileDirectoryLocation fileDirectoryLocation = dirLocation as AzureFileDirectoryLocation;
         (subLocation as AzureFileLocation).UpdateCredentials(fileDirectoryLocation.FileDirectory.ServiceClient.Credentials);
     }
 }
Exemplo n.º 3
0
        private TransferLocation GetDestinationTransferLocation(TransferLocation dirLocation, TransferEntry entry)
        {
            string destRelativePath = this.nameResolver.ResolveName(entry);

            switch (dirLocation.Type)
            {
            case TransferLocationType.AzureBlobDirectory:
            {
                AzureBlobDirectoryLocation blobDirLocation = dirLocation as AzureBlobDirectoryLocation;
                BlobType destBlobType = this.BlobType;

                AzureBlobEntry sourceBlobEntry = entry as AzureBlobEntry;
                if (sourceBlobEntry != null)
                {
                    // if source is Azure blob storage, source and destination blob share the same blob type
                    destBlobType = sourceBlobEntry.Blob.BlobType;
                }

                CloudBlob blob = null;
                switch (destBlobType)
                {
                case Blob.BlobType.BlockBlob:
                case Blob.BlobType.Unspecified:
                    blob = blobDirLocation.BlobDirectory.GetBlockBlobReference(destRelativePath);
                    break;

                case Blob.BlobType.PageBlob:
                    blob = blobDirLocation.BlobDirectory.GetPageBlobReference(destRelativePath);
                    break;

                case Blob.BlobType.AppendBlob:
                    blob = blobDirLocation.BlobDirectory.GetAppendBlobReference(destRelativePath);
                    break;
                }

                AzureBlobLocation retLocation = new AzureBlobLocation(blob);
                retLocation.BlobRequestOptions = blobDirLocation.BlobRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.AzureFileDirectory:
            {
                AzureFileDirectoryLocation fileDirLocation = dirLocation as AzureFileDirectoryLocation;
                CloudFile file = fileDirLocation.FileDirectory.GetFileReference(destRelativePath);
                CreateParentDirectoryIfNotExists(file);

                AzureFileLocation retLocation = new AzureFileLocation(file);
                retLocation.FileRequestOptions = fileDirLocation.FileRequestOptions;
                return(retLocation);
            }

            case TransferLocationType.LocalDirectory:
            {
                DirectoryLocation localDirLocation = dirLocation as DirectoryLocation;
                string            path             = Path.Combine(localDirLocation.DirectoryPath, destRelativePath);
                CreateParentDirectoryIfNotExists(path);

                return(new FileLocation(path));
            }

            default:
                throw new ArgumentException("TransferLocationType");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureBlobEnumerator" /> class.
 /// </summary>
 /// <param name="location">Azure blob directory location.</param>
 public AzureBlobEnumerator(AzureBlobDirectoryLocation location)
 {
     this.location = location;
 }
        /// <summary>
        /// Download an Azure blob directory from Azure Blob Storage.
        /// </summary>
        /// <param name="sourceBlobDir">The <see cref="CloudBlobDirectory"/> that is the source Azure blob directory.</param>
        /// <param name="destPath">Path to the destination directory</param>
        /// <param name="options">A <see cref="DownloadDirectoryOptions"/> object that specifies additional options for the operation.</param>
        /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
        /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
        public static Task DownloadDirectoryAsync(CloudBlobDirectory sourceBlobDir, string destPath, DownloadDirectoryOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            AzureBlobDirectoryLocation sourceLocation = new AzureBlobDirectoryLocation(sourceBlobDir);
            DirectoryLocation destLocation = new DirectoryLocation(destPath);
            AzureBlobEnumerator sourceEnumerator = new AzureBlobEnumerator(sourceLocation);
            if (options != null)
            {
                sourceEnumerator.SearchPattern = options.SearchPattern;
                sourceEnumerator.Recursive = options.Recursive;
                sourceEnumerator.IncludeSnapshots = options.IncludeSnapshots;

                BlobRequestOptions requestOptions = Transfer_RequestOptions.DefaultBlobRequestOptions;
                requestOptions.DisableContentMD5Validation = options.DisableContentMD5Validation;
                sourceLocation.BlobRequestOptions = requestOptions;
            }

            return DownloadDirectoryInternalAsync(sourceLocation, destLocation, sourceEnumerator, context, cancellationToken);
        }
        /// <summary>
        /// Upload a directory to Azure Blob Storage.
        /// </summary>
        /// <param name="sourcePath">Path to the source directory</param>
        /// <param name="destBlobDir">The <see cref="CloudBlobDirectory"/> that is the destination Azure blob directory.</param>
        /// <param name="options">An <see cref="UploadDirectoryOptions"/> object that specifies additional options for the operation.</param>
        /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
        /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
        public static Task UploadDirectoryAsync(string sourcePath, CloudBlobDirectory destBlobDir, UploadDirectoryOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            DirectoryLocation sourceLocation = new DirectoryLocation(sourcePath);
            AzureBlobDirectoryLocation destLocation = new AzureBlobDirectoryLocation(destBlobDir);
            FileEnumerator sourceEnumerator = new FileEnumerator(sourceLocation);
            if (options != null)
            {
                sourceEnumerator.SearchPattern = options.SearchPattern;
                sourceEnumerator.Recursive = options.Recursive;
            }

            return UploadDirectoryInternalAsync(sourceLocation, destLocation, sourceEnumerator, options, context, cancellationToken);
        }
        /// <summary>
        /// Copy an Azure file directory to an Azure blob directory.
        /// </summary>
        /// <param name="sourceFileDir">The <see cref="CloudFileDirectory"/> that is the source Azure file directory.</param>
        /// <param name="destBlobDir">The <see cref="CloudBlobDirectory"/> that is the destination Azure blob directory.</param>
        /// <param name="isServiceCopy">A flag indicating whether the copy is service-side asynchronous copy or not.
        /// If this flag is set to true, service-side asychronous copy will be used; if this flag is set to false,
        /// file is downloaded from source first, then uploaded to destination.</param>
        /// <param name="options">A <see cref="CopyDirectoryOptions"/> object that specifies additional options for the operation.</param>
        /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
        /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
        public static Task CopyDirectoryAsync(CloudFileDirectory sourceFileDir, CloudBlobDirectory destBlobDir, bool isServiceCopy, CopyDirectoryOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            AzureFileDirectoryLocation sourceLocation = new AzureFileDirectoryLocation(sourceFileDir);
            AzureBlobDirectoryLocation destLocation = new AzureBlobDirectoryLocation(destBlobDir);
            AzureFileEnumerator sourceEnumerator = new AzureFileEnumerator(sourceLocation);
            if (options != null)
            {
                TransferManager.CheckSearchPatternOfAzureFileSource(options);

                sourceEnumerator.SearchPattern = options.SearchPattern;
                sourceEnumerator.Recursive = options.Recursive;
            }

            return CopyDirectoryInternalAsync(sourceLocation, destLocation, isServiceCopy, sourceEnumerator, options, context, cancellationToken);
        }
        /// <summary>
        /// Copy an Azure blob directory to another Azure blob directory.
        /// </summary>
        /// <param name="sourceBlobDir">The <see cref="CloudBlobDirectory"/> that is the source Azure blob directory.</param>
        /// <param name="destBlobDir">The <see cref="CloudBlobDirectory"/> that is the destination Azure blob directory.</param>
        /// <param name="isServiceCopy">A flag indicating whether the copy is service-side asynchronous copy or not.
        /// If this flag is set to true, service-side asychronous copy will be used; if this flag is set to false,
        /// file is downloaded from source first, then uploaded to destination.</param>
        /// <param name="options">A <see cref="CopyDirectoryOptions"/> object that specifies additional options for the operation.</param>
        /// <param name="context">A <see cref="TransferContext"/> object that represents the context for the current operation.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> object to observe while waiting for a task to complete.</param>
        /// <returns>A <see cref="Task"/> object that represents the asynchronous operation.</returns>
        public static Task CopyDirectoryAsync(CloudBlobDirectory sourceBlobDir, CloudBlobDirectory destBlobDir, bool isServiceCopy, CopyDirectoryOptions options, TransferContext context, CancellationToken cancellationToken)
        {
            AzureBlobDirectoryLocation sourceLocation = new AzureBlobDirectoryLocation(sourceBlobDir);
            AzureBlobDirectoryLocation destLocation = new AzureBlobDirectoryLocation(destBlobDir);
            AzureBlobEnumerator sourceEnumerator = new AzureBlobEnumerator(sourceLocation);
            if (options != null)
            {
                sourceEnumerator.SearchPattern = options.SearchPattern;
                sourceEnumerator.Recursive = options.Recursive;
                sourceEnumerator.IncludeSnapshots = options.IncludeSnapshots;
            }

            return CopyDirectoryInternalAsync(sourceLocation, destLocation, isServiceCopy, sourceEnumerator, options, context, cancellationToken);
        }