Example #1
0
        public void TestCopyE2E()
        {
            var sourceTempFilePath = Path.GetTempFileName();
            var destTempFilePath   = Path.GetTempFileName();

            try
            {
                string fileName   = UploadFromString("CopyThis", 1);
                var    sourceUri  = PathToFile(fileName);
                string copyToFile = $"/{_defaultFolderName}/testFile2.txt";
                var    destUri    = PathToFile(copyToFile);
                _fileSystem.Copy(sourceUri, destUri);
                _adlsClient.BulkDownload(sourceUri.AbsolutePath, sourceTempFilePath);
                _adlsClient.BulkDownload(destUri.AbsolutePath, destTempFilePath);
                FileSystemTestUtilities.HaveSameContent(sourceTempFilePath, destTempFilePath);
            }
            finally
            {
                try
                {
                    File.Delete(sourceTempFilePath);
                }
                finally
                {
                    File.Delete(destTempFilePath);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Copies the remote file to a local file.
        /// </summary>
        /// <exception cref="IOException">If copy process encounters any exceptions</exception>
        public void CopyToLocal(Uri remoteFileUri, string localFileName)
        {
            TransferStatus status;

            try
            {
                status = _adlsClient.BulkDownload(remoteFileUri.AbsolutePath, localFileName); // throws KeyNotFoundException
            }
            catch (Exception ex)
            {
                throw new IOException($"Error in bulk download from {remoteFileUri} to {localFileName}", ex);
            }
            if (status.EntriesFailed.Count != 0)
            {
                throw new IOException($"{status.EntriesFailed.Count} entries did not get transferred correctly");
            }
        }
        // Bulk upload and download
        private static void RunFileTransfer(AdlsClient client)
        {
            Directory.CreateDirectory(localFileTransferPath);
            var fileName = localFileTransferPath + @"\testUploadFile.txt";

            Console.WriteLine("Creating the test file to upload:");
            using (var stream = new StreamWriter(new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite)))
            {
                stream.WriteLine("Hello I am the first line of upload.");
                stream.WriteLine("Hello I am the second line of upload.");
            }
            var destFile = remoteFileTransferPath + "/testremoteUploadFile.txt";

            Console.WriteLine("Upload of the file:");
            client.BulkUpload(fileName, destFile, 1); // Source and destination could also be directories
            using (var readStream = new StreamReader(client.GetReadStream(destFile)))
            {
                string line;
                while ((line = readStream.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }
            var localDestFile = localFileTransferPath + @"\testlocalDownloadFile.txt";

            Console.WriteLine("Download of the uploaded file:");
            client.BulkDownload(destFile, localDestFile, 1); // Source and destination could also be directories
            using (var stream = new StreamReader(File.OpenRead(localDestFile)))
            {
                string line;
                while ((line = stream.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }
            Directory.Delete(localFileTransferPath, true);
            client.DeleteRecursive(remoteFileTransferPath);
        }
Example #4
0
        /// <summary>
        /// Copies the remote file to a local file.
        /// </summary>
        /// <exception cref="IOException">If copy process encounters any exceptions</exception>
        public void CopyToLocal(Uri remoteFileUri, string localFileName)
        {
            TransferStatus status;

            try
            {
                status = _adlsClient.BulkDownload(remoteFileUri.AbsolutePath, localFileName); // throws KeyNotFoundException
            }
            catch (Exception ex)
            {
                throw new IOException($"Error in bulk download from {remoteFileUri} to {localFileName}", ex);
            }
            if (status.EntriesFailed.Count != 0)
            {
                var failedEntriesBuilder = new StringBuilder();
                for (int i = 0; i < status.EntriesFailed.Count && i < 50; i++)
                {
                    var entry = status.EntriesFailed[i];
                    failedEntriesBuilder.Append($"Entry {entry.EntryName} failed with error message {entry.Errors}. ");
                }
                throw new IOException($"{status.EntriesFailed.Count} entries failed to download. {failedEntriesBuilder.ToString()}");
            }
        }