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();
            }
        }
示例#2
0
        public static async Task OnFileRenamed([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
        {
            try
            {
                var createdEvent = ((JObject)eventGridEvent.Data).ToObject <StorageBlobRenamedEventData>();

                Uri sourceFileUri = new Uri(createdEvent.SourceBlobUrl);

                DataLakeFileClient dataLakeFileClient = new DataLakeFileClient(BLOB_OUTPUT_CONNECTION_STRING, "backup", sourceFileUri.AbsolutePath);

                Uri destinationFileUri = new Uri(createdEvent.DestinationBlobUrl);

                await dataLakeFileClient.RenameAsync(destinationFileUri.AbsolutePath, "backup");
            }
            catch (Exception ex)
            {
                log.LogInformation(ex.Message);
                throw;
            }
        }