Esempio n. 1
0
        /// <summary>
        /// Uploads a folder to the specified Data Lake Store account.
        /// </summary>
        /// <param name='accountName'>
        /// The Azure Data Lake Store account to execute filesystem operations on.
        /// </param>
        /// <param name='sourcePath'>
        /// The local source folder to upload to the Data Lake Store account.
        /// </param>
        /// <param name='destinationPath'>
        /// The Data Lake Store path (starting with '/') of the directory to upload to.
        /// </param>
        /// <param name='perFileThreadCount'>
        /// The maximum number of threads to use per file during the upload. By default, this number will be computed based on folder structure and average file size.
        /// </param>
        /// <param name='concurrentFileCount'>
        /// The maximum number of files to upload at once. By default, this number will be computed based on folder structure and number of files.
        /// </param>
        /// <param name='resume'>
        /// A switch indicating if this upload is a continuation of a previous, failed upload. Default is false.
        /// </param>
        /// <param name='overwrite'>
        /// A switch indicating this upload should overwrite the contents of the target directory if it exists. Default is false, and the upload will fast fail if the target location exists.
        /// </param>
        /// <param name='uploadAsBinary'>
        /// A switch indicating this upload should treat all data as binary, which is slightly more performant but does not ensure record boundary integrity. This is recommended for large folders of mixed binary and text files or binary only directories. Default is false
        /// </param>
        /// <param name='recurse'>
        /// A switch indicating this upload should upload the source directory recursively or just the top level. Default is false, only the top level will be uploaded.
        /// </param>
        /// <param name='progressTracker'>
        /// An optional delegate that can be used to track the progress of the upload operation asynchronously.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="AdlsErrorException">
        /// Thrown when the operation returned an invalid status code.
        /// </exception>
        /// <exception cref="TaskCanceledException">
        /// Thrown when the operation takes too long to complete or if the user explicitly cancels it.
        /// </exception>
        /// <exception cref="InvalidMetadataException">
        /// Thrown when resume metadata is corrupt or not associated with the current operation.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        /// Thrown when the source path cannot be found.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Thrown if an invalid upload is attempted or a file/folder is modified externally during the operation.
        /// </exception>
        /// <exception cref="TransferFailedException">
        /// Thrown if the transfer operation fails.
        /// </exception>
        /// <exception cref="SerializationException">
        /// Thrown when unable to deserialize the response
        /// </exception>
        /// <exception cref="ValidationException">
        /// Thrown when a required parameter is null
        /// </exception>
        public void UploadFolder(
            string accountName,
            string sourcePath,
            string destinationPath,
            int perFileThreadCount  = -1,
            int concurrentFileCount = -1,
            bool resume             = false,
            bool overwrite          = false,
            bool uploadAsBinary     = false,
            bool recurse            = false,
            IProgress <TransferFolderProgress> progressTracker = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("accountName", accountName);
                tracingParameters.Add("sourcePath", sourcePath);
                tracingParameters.Add("destinationPath", destinationPath);
                tracingParameters.Add("perFileThreadCount", perFileThreadCount);
                tracingParameters.Add("concurrentFileCount", concurrentFileCount);
                tracingParameters.Add("resume", resume);
                tracingParameters.Add("overwrite", overwrite);
                tracingParameters.Add("recurse", recurse);
                tracingParameters.Add("uploadAsBinary", uploadAsBinary);
                tracingParameters.Add("progressTracker", progressTracker);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "UploadFolder", tracingParameters);
            }

            try
            {
                var parameters = new TransferParameters(
                    inputFilePath: sourcePath,
                    targetStreamPath: destinationPath,
                    accountName: accountName,
                    perFileThreadCount: perFileThreadCount,
                    concurrentFileCount: concurrentFileCount,
                    isOverwrite: overwrite,
                    isResume: resume,
                    isRecursive: recurse,
                    isBinary: uploadAsBinary
                    );

                var transferAdapter = new DataLakeStoreFrontEndAdapter(accountName, this.Client);
                var transferClient  = new DataLakeStoreTransferClient(
                    parameters,
                    transferAdapter,
                    token: cancellationToken,
                    folderProgressTracker: progressTracker);

                transferClient.Execute();

                if (_shouldTrace)
                {
                    ServiceClientTracing.Exit(
                        _invocationId,
                        string.Format(
                            "Upload of folder to account: {0} from source location: {1}{2} to destination: {3} completed successfully.",
                            accountName,
                            sourcePath,
                            recurse ? ", recursively," : string.Empty,
                            destinationPath));
                }
            }
            catch (Exception ex)
            {
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }

                throw ex;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Downloads a file from the specified Data Lake Store account.
        /// </summary>
        /// <param name='accountName'>
        /// The Azure Data Lake Store account to execute filesystem operations on.
        /// </param>
        /// <param name='sourcePath'>
        /// The Data Lake Store path (starting with '/') of the file to download.
        /// </param>
        /// <param name='destinationPath'>
        /// The local path to download the file to. If a directory is specified, the file name will be the same as the source file name
        /// </param>
        /// <param name='threadCount'>
        /// The maximum number of threads to use during the download. By default, this number will be computed based on file size.
        /// </param>
        /// <param name='resume'>
        /// A switch indicating if this download is a continuation of a previous, failed download. Default is false.
        /// </param>
        /// <param name='overwrite'>
        /// A switch indicating this download should overwrite the the target file if it exists. Default is false, and the download will fast fail if the target file exists.
        /// </param>
        /// <param name='progressTracker'>
        /// An optional delegate that can be used to track the progress of the download operation asynchronously.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="AdlsErrorException">
        /// Thrown when the operation returned an invalid status code.
        /// </exception>
        /// <exception cref="TaskCanceledException">
        /// Thrown when the operation takes too long to complete or if the user explicitly cancels it.
        /// </exception>
        /// <exception cref="InvalidMetadataException">
        /// Thrown when resume metadata is corrupt or not associated with the current operation.
        /// </exception>
        /// <exception cref="FileNotFoundException">
        /// Thrown when the source path cannot be found.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Thrown if an invalid download is attempted or a file is modified externally during the operation.
        /// </exception>
        /// <exception cref="TransferFailedException">
        /// Thrown if the transfer operation fails.
        /// </exception>
        /// <exception cref="SerializationException">
        /// Thrown when unable to deserialize the response
        /// </exception>
        /// <exception cref="ValidationException">
        /// Thrown when a required parameter is null
        /// </exception>
        public void DownloadFile(
            string accountName,
            string sourcePath,
            string destinationPath,
            int threadCount = -1,
            bool resume     = false,
            bool overwrite  = false,
            IProgress <TransferProgress> progressTracker = null,
            CancellationToken cancellationToken          = default(CancellationToken))
        {
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("accountName", accountName);
                tracingParameters.Add("sourcePath", sourcePath);
                tracingParameters.Add("destinationPath", destinationPath);
                tracingParameters.Add("threadCount", threadCount);
                tracingParameters.Add("resume", resume);
                tracingParameters.Add("overwrite", overwrite);
                tracingParameters.Add("progressTracker", progressTracker);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "DownloadFile", tracingParameters);
            }

            try
            {
                var parameters = new TransferParameters(
                    inputFilePath: sourcePath,
                    targetStreamPath: destinationPath,
                    accountName: accountName,
                    perFileThreadCount: threadCount,
                    isOverwrite: overwrite,
                    isResume: resume,
                    isDownload: true
                    );

                var transferAdapter = new DataLakeStoreFrontEndAdapter(accountName, this.Client);
                var transferClient  = new DataLakeStoreTransferClient(
                    parameters,
                    transferAdapter,
                    cancellationToken,
                    progressTracker);

                transferClient.Execute();

                if (_shouldTrace)
                {
                    ServiceClientTracing.Exit(
                        _invocationId,
                        string.Format(
                            "Download of stream in account: {0} from source location: {1} to destination: {2} completed successfully.",
                            accountName,
                            sourcePath,
                            destinationPath));
                }
            }
            catch (Exception ex)
            {
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }

                throw ex;
            }
        }