Пример #1
0
        public async Task PathClient_CanGetParentDirectoryClient_WithAccountSAS()
        {
            // Arrange
            var parentDirName = DataLakeClientBuilder.GetNewDirectoryName();

            await using DisposingFileSystem test = await DataLakeClientBuilder.GetNewFileSystem();

            var fileName = DataLakeClientBuilder.GetNewFileName();
            DataLakeFileClient fileClient = InstrumentClient(
                GetServiceClient_AccountSas()
                .GetFileSystemClient(test.FileSystem.Name)
                .GetRootDirectoryClient()
                .GetSubDirectoryClient(parentDirName)
                .GetFileClient(fileName));
            await fileClient.CreateAsync();

            // Act
            DataLakeDirectoryClient parentDirClient = fileClient.GetParentDirectoryClient();
            // make sure that client is functional
            var dirProperties = await parentDirClient.GetPropertiesAsync();

            // Assert
            Assert.AreEqual(fileClient.Path.GetParentPath(), parentDirClient.Path);
            Assert.AreEqual(fileClient.AccountName, parentDirClient.AccountName);
            Assert.IsNotNull(dirProperties);
        }
        public async Task RenameAsync()
        {
            // Make StorageSharedKeyCredential to pass to the serviceClient
            string storageAccountName = StorageAccountName;
            string storageAccountKey  = StorageAccountKey;
            Uri    serviceUri         = StorageAccountBlobUri;
            StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);

            // Create DataLakeServiceClient using StorageSharedKeyCredentials
            DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);

            // Get a reference to a filesystem named "sample-filesystem-rename" and then create it
            DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-rename"));
            await filesystem.CreateAsync();

            try
            {
                // Create a DataLake Directory to rename it later
                DataLakeDirectoryClient directoryClient = filesystem.GetDirectoryClient(Randomize("sample-directory"));
                await directoryClient.CreateAsync();

                // Rename directory with new path/name and verify by making a service call (e.g. GetProperties)
                DataLakeDirectoryClient renamedDirectoryClient = await directoryClient.RenameAsync("sample-directory2");

                PathProperties directoryPathProperties = await renamedDirectoryClient.GetPropertiesAsync();

                // Delete the sample directory using the new path/name
                await filesystem.DeleteDirectoryAsync("sample-directory2");

                // Create a DataLake file.
                DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file"));
                await fileClient.CreateAsync();

                // Rename file with new path/name and verify by making a service call (e.g. GetProperties)
                DataLakeFileClient renamedFileClient = await fileClient.RenameAsync("sample-file2");

                PathProperties pathProperties = await renamedFileClient.GetPropertiesAsync();

                // Delete the sample directory using the new path/name
                await filesystem.DeleteFileAsync("sample-file2");
            }
            finally
            {
                // Clean up after the test when we're finished
                await filesystem.DeleteAsync();
            }
        }
        public async Task GetPropertiesAsync()
        {
            // Make StorageSharedKeyCredential to pass to the serviceClient
            string storageAccountName = StorageAccountName;
            string storageAccountKey  = StorageAccountKey;
            Uri    serviceUri         = StorageAccountBlobUri;
            StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);

            // Create DataLakeServiceClient using StorageSharedKeyCredentials
            DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);

            // Get a reference to a filesystem named "sample-filesystem-rename" and then create it
            DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem"));
            await filesystem.CreateAsync();

            try
            {
                // Create a DataLake Directory to rename it later
                DataLakeDirectoryClient directoryClient = filesystem.GetDirectoryClient(Randomize("sample-directory"));
                await directoryClient.CreateAsync();

                // Get Properties on a Directory
                PathProperties directoryPathProperties = await directoryClient.GetPropertiesAsync();

                // Create a DataLake file
                DataLakeFileClient fileClient = filesystem.GetFileClient(Randomize("sample-file"));
                await fileClient.CreateAsync();

                // Get Properties on a File
                PathProperties filePathProperties = await fileClient.GetPropertiesAsync();
            }
            finally
            {
                // Clean up after the test when we're finished
                await filesystem.DeleteAsync();
            }
        }