Exemplo n.º 1
0
        // Create a sample hierarchical directory tree using async operations
        private static async Task CreateDirRecursiveAsync(DataLakeFileSystemClient client, string path, int recursLevel, int noDirEntries, int noFileEntries)
        {
            await client.CreateDirectoryAsync(path);

            byte[]   writeData = Encoding.UTF8.GetBytes("This is the first line.\n");
            string[] str       = path.Split('/');
            char     nextLevel = str[str.Length - 1][0];

            nextLevel++;
            for (int i = 0; i < noFileEntries; i++)
            {
                DataLakeFileClient file = client.GetFileClient(path + "/" + nextLevel + i + "File.txt");

                using (var stream = new MemoryStream(writeData))
                {
                    file.Upload(stream, true);
                }
            }
            if (recursLevel == 0)
            {
                return;
            }

            string newPath = path + "/";

            for (int i = 0; i < noDirEntries; i++)
            {
                await CreateDirRecursiveAsync(client, newPath + nextLevel + i, recursLevel - 1, noDirEntries, noFileEntries);
            }
        }
Exemplo n.º 2
0
        public async Task <DataLakeDirectoryClient> CreateUserDirectory(User user)
        {
            if (FileSystemClient.GetDirectoryClient(user.id) == null)
            {
                var result = await FileSystemClient.CreateDirectoryAsync(user.id);

                return(result);
            }
            return(null);
        }
        // </Snippet_GetContainer>

        #endregion

        #region create a directory

        // ---------------------------------------------------------
        // Create directory
        //----------------------------------------------------------

        // <Snippet_CreateDirectory>
        public async Task <DataLakeDirectoryClient> CreateDirectory
            (DataLakeServiceClient serviceClient, string fileSystemName)
        {
            DataLakeFileSystemClient fileSystemClient =
                serviceClient.GetFileSystemClient(fileSystemName);

            DataLakeDirectoryClient directoryClient =
                await fileSystemClient.CreateDirectoryAsync("my-directory");

            return(await directoryClient.CreateSubDirectoryAsync("my-subdirectory"));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates new directory.
 /// </summary>
 /// <param name="path">Path of folder to create new directory.</param>
 /// <param name="name">Name of new folder.</param>
 /// <returns></returns>
 public async Task CreateDirectoryAsync(string path, string name)
 {
     if (path == "/")
     {
         await dataLakeClient.CreateDirectoryAsync(name);
     }
     else
     {
         await GetDirectoryClient(path).CreateSubDirectoryAsync(name);
     }
 }
        public async Task ListAsync()
        {
            // 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-listasync" and then create it
            DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-list"));
            await filesystem.CreateAsync();

            try
            {
                // Upload a couple of directories so we have something to list
                await filesystem.CreateDirectoryAsync("sample-directory1");

                await filesystem.CreateDirectoryAsync("sample-directory2");

                await filesystem.CreateDirectoryAsync("sample-directory3");

                // List all the directories
                List <string> names = new List <string>();
                await foreach (PathItem pathItem in filesystem.GetPathsAsync())
                {
                    names.Add(pathItem.Name);
                }
                Assert.AreEqual(3, names.Count);
                Assert.Contains("sample-directory1", names);
                Assert.Contains("sample-directory2", names);
                Assert.Contains("sample-directory3", names);
            }
            finally
            {
                // Clean up after the test when we're finished
                await filesystem.DeleteAsync();
            }
        }
        public async Task TraverseAsync()
        {
            // Create a temporary Lorem Ipsum file on disk that we can upload
            string originalPath = CreateTempFile(SampleFileContent);

            // 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-traverseasync" and then create it
            DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-traverse"));

            await filesystem.CreateAsync();

            try
            {
                // Create a bunch of directories and files within the directories
                DataLakeDirectoryClient first = await filesystem.CreateDirectoryAsync("first");

                await first.CreateSubDirectoryAsync("a");

                await first.CreateSubDirectoryAsync("b");

                DataLakeDirectoryClient second = await filesystem.CreateDirectoryAsync("second");

                await second.CreateSubDirectoryAsync("c");

                await second.CreateSubDirectoryAsync("d");

                await filesystem.CreateDirectoryAsync("third");

                DataLakeDirectoryClient fourth = await filesystem.CreateDirectoryAsync("fourth");

                DataLakeDirectoryClient deepest = await fourth.CreateSubDirectoryAsync("e");

                // Upload a DataLake file named "file"
                DataLakeFileClient file = deepest.GetFileClient("file");
                await file.CreateAsync();

                using (FileStream stream = File.OpenRead(originalPath))
                {
                    await file.AppendAsync(stream, 0);
                }

                // Keep track of all the names we encounter
                List <string> names = new List <string>();
                await foreach (PathItem pathItem in filesystem.GetPathsAsync(recursive: true))
                {
                    names.Add(pathItem.Name);
                }

                // Verify we've seen everything
                Assert.AreEqual(10, names.Count);
                Assert.Contains("first", names);
                Assert.Contains("second", names);
                Assert.Contains("third", names);
                Assert.Contains("fourth", names);
                Assert.Contains("first/a", names);
                Assert.Contains("first/b", names);
                Assert.Contains("second/c", names);
                Assert.Contains("second/d", names);
                Assert.Contains("fourth/e", names);
                Assert.Contains("fourth/e/file", names);
            }
            finally
            {
                // Clean up after the test when we're finished
                await filesystem.DeleteAsync();
            }
        }
        public async Task CreateDirectory(DataLakeFileSystemClient fileSystemClient, string nameDirectory)
        {
            await fileSystemClient.CreateDirectoryAsync(nameDirectory + "/Distributor");

            await GetAzureFolder();
        }