public async Task CreateDirectoryClientAsync() { // 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-append" and then create it DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-append")); filesystem.Create(); // Create DataLakeDirectoryClient directory = filesystem.GetDirectoryClient(Randomize("sample-file")); await directory.CreateAsync(); // Verify we created one directory AsyncPageable <PathItem> response = filesystem.GetPathsAsync(); IList <PathItem> paths = await response.ToListAsync(); Assert.AreEqual(1, paths.Count); // Cleanup await filesystem.DeleteAsync(); }
public IDisposable GetNewDirectory(out DataLakeDirectoryClient directory, DataLakeServiceClient service = default, string fileSystemName = default, string directoryName = default) { IDisposable disposingFileSystem = GetNewFileSystem(out DataLakeFileSystemClient fileSystem, service, fileSystemName); directory = InstrumentClient(fileSystem.GetDirectoryClient(directoryName ?? GetNewDirectoryName())); _ = directory.CreateAsync().Result; return(disposingFileSystem); }
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 Ctor_ConnectionString_RoundTrip() { // Arrange string fileSystemName = GetNewFileSystemName(); string path = GetNewDirectoryName(); await using DisposingFileSystem test = await GetNewFileSystem(fileSystemName : fileSystemName); DataLakeDirectoryClient directoryClient = InstrumentClient(test.FileSystem.GetDirectoryClient(path)); await directoryClient.CreateAsync(); // Act string connectionString = $"DefaultEndpointsProtocol=https;AccountName={TestConfigHierarchicalNamespace.AccountName};AccountKey={TestConfigHierarchicalNamespace.AccountKey};EndpointSuffix=core.windows.net"; DataLakePathClient connStringDirectory = InstrumentClient(new DataLakePathClient(connectionString, fileSystemName, path, GetOptions())); // Assert await connStringDirectory.GetPropertiesAsync(); await connStringDirectory.GetAccessControlAsync(); }
public async Task Ctor_ConnectionString_GenerateSas() { // Arrange string fileSystemName = GetNewFileSystemName(); string path = GetNewDirectoryName(); await using DisposingFileSystem test = await GetNewFileSystem(fileSystemName : fileSystemName); DataLakeDirectoryClient directoryClient = InstrumentClient(test.FileSystem.GetDirectoryClient(path)); await directoryClient.CreateAsync(); // Act string connectionString = $"DefaultEndpointsProtocol=https;AccountName={TestConfigHierarchicalNamespace.AccountName};AccountKey={TestConfigHierarchicalNamespace.AccountKey};BlobEndpoint={TestConfigHierarchicalNamespace.BlobServiceEndpoint};FileEndpoint={TestConfigHierarchicalNamespace.FileServiceEndpoint};QueueEndpoint={TestConfigHierarchicalNamespace.QueueServiceEndpoint};TableEndpoint={TestConfigHierarchicalNamespace.TableServiceEndpoint}"; DataLakePathClient connStringDirectory = InstrumentClient(new DataLakePathClient(connectionString, fileSystemName, path, GetOptions())); Uri sasUri = connStringDirectory.GenerateSasUri(DataLakeSasPermissions.All, Recording.UtcNow.AddDays(1)); DataLakePathClient sasPathClient = InstrumentClient(new DataLakePathClient(sasUri, GetOptions())); // Assert await sasPathClient.GetPropertiesAsync(); await sasPathClient.GetAccessControlAsync(); }
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(); } }