Class MetaFileSystemClient
Provides file system operations for the Xperiflow MetaFileSystem service.
Namespace: Workspace.XBR.Xperiflow.MetaFileSystem
Assembly: Xperiflow.dll
public class MetaFileSystemClient : IMetaFileSystemClient
Examples
Basic file operations:
// Initialize the client
var client = new MetaFileSystemClient(sessionInfo, httpClientManager, storageClient, connectionKey);
// Create a directory
await client.MakeDirectoriesAsync("data/processed", existsOk: true);
// Write a file
await client.WriteFileAsync("data/processed/results.json", jsonData, overwriteOk: true);
// Read file content
var content = await client.GetFileContentStringAsync("data/processed/results.json");
// Get file metadata
var metadata = await client.GetFileMetadataAsync("data/processed/results.json");
Console.WriteLine($"File size: {metadata.Size} bytes, created: {metadata.CreatedTime}");
// List directory contents
var directory = await client.GetDirectoryAsync("data/processed", maxDepth: 2);
foreach (var file in directory.Files)
`{
Console.WriteLine($"Found file: {file.Name}`");
}
Streaming operations for large files:
// Stream large file content
using (var stream = await client.GetFileContentStreamAsync("data/large-dataset.csv"))
{
// Process stream without loading entire file into memory
using (var reader = new StreamReader(stream))
{
string line;
while ((line = await reader.ReadLineAsync()) != null)
{
// Process each line
}
}
}
Remarks
The Workspace.XBR.Xperiflow.MetaFileSystem.MetaFileSystemClient is the standard concrete implementation of Workspace.XBR.Xperiflow.MetaFileSystem.IMetaFileSystemClient that provides connectivity to the Xperiflow MetaFileSystem service. It serves as the primary interface for file and directory operations within the Xperiflow ecosystem, offering both synchronous and asynchronous operations for data management.
Key Features:
-
Directory Management Create, delete, and query directories with support for recursive operations
-
File Operations Read, write, and delete files with support for various data formats (streams, strings, byte arrays)
-
Metadata Access Retrieve detailed metadata for files and directories including creation times, sizes, and permissions
-
Azure Blob Integration Seamless integration with Azure Blob Storage using SAS tokens for secure access
-
Error Handling Comprehensive error handling with OneStream logging and exception management
Storage Architecture:
The MetaFileSystem operates as an abstraction layer over underlying storage systems, providing a unified interface for file operations regardless of the actual storage backend (local file system, Azure Blob Storage, etc.). This design enables seamless migration between storage providers and consistent behavior across environments.
Thread Safety:
This class is designed to be thread-safe and supports concurrent operations through proper use of async/await patterns and cancellation tokens. Multiple operations can be performed simultaneously without additional synchronization.
Performance Considerations:
The client optimizes performance through streaming operations for large files and efficient metadata caching. Use streaming methods for large data transfers and consider specifying content size hints when known to improve performance.
Implements: Workspace.XBR.Xperiflow.MetaFileSystem.IMetaFileSystemClient
Methods
DirectoryExistsAsync(string, CancellationToken)
Checks if a directory exists in the Meta FileSystem at the provided path.
public Task<bool> DirectoryExistsAsync(string path, CancellationToken cancellationToken = default)
Returns
Task<System.Boolean>
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path to the directory. If the directory path. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
GetDirectoryMetadataAsync(string, bool, CancellationToken)
Retrieves only the metadata of a directory (no subdirectories or subfiles) from the Meta FileSystem.
public Task<IDirectoryMetadata?> GetDirectoryMetadataAsync(string path, bool errorWhenDoesNotExist = true, CancellationToken cancellationToken = default)
Returns
Task
< Workspace.XBR.Xperiflow.MetaFileSystem.IDirectoryMetadata >
DirectoryMetadata
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path to the folder. If the folder path does not exist, an error will be thrown. |
System.Boolean | errorWhenDoesNotExist | Whether or not to throw an error when the directory does not exist. Defaults to true. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
GetDirectoryAsync(string, int?, bool, bool, CancellationToken)
Retrieves a directory and its subcontents (other file and folders metdata) from the Meta FileSystem.
public Task<IDirectoryContent?> GetDirectoryAsync(string path, int? maxDepth = 1, bool includeDirectories = true, bool errorWhenDoesNotExist = true, CancellationToken cancellationToken = default)
Returns
Task
< Workspace.XBR.Xperiflow.MetaFileSystem.IDirectoryContent >
DirectoryContent: This holds accessors to files and directory subcontents.
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path to the folder. If the folder path does not exist, an error will be thrown. |
System.Nullable<System.Int32> | maxDepth | The max depth of subcontents to grab. Defaults to 1 level deep of subcontents. Set to -1 or null to grab all subcontents. |
System.Boolean | includeDirectories | Whether or not to include subfolders in the subcontents. Defaults to true. |
System.Boolean | errorWhenDoesNotExist | Whether or not to throw an error when the directory does not exist. Defaults to true. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
MakeDirectoriesAsync(string, bool, CancellationToken)
Makes one or more directories in the Meta FileSystem at the provided path.
Note that this method is subject to runtime checks that may not allow the creation of directories in certain locations.
public Task MakeDirectoriesAsync(string path, bool existsOk = false, CancellationToken cancellationToken = default)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The directory path to create. |
System.Boolean | existsOk | Controls whether or not to throw an error if the directory already exists. Defaults to false. |
System.Threading.CancellationToken | cancellationToken |
RemoveDirectoryAsync(string, bool, bool, CancellationToken)
Removes a directory from the MetaFileSystem. This method is not recursive in that it will only remove the last directory in the path. It also expects that the directory is empty.
Note that this method is subject to runtime checks that may not allow removing a directory in certain locations.
public Task RemoveDirectoryAsync(string path, bool recursive = false, bool errorWhenDoesNotExist = true, CancellationToken cancellationToken = default)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The directory path to remove. |
System.Boolean | recursive | Whether or not to attempt to recursively remove the directory and its all of its subcontents. Defaults to false. |
System.Boolean | errorWhenDoesNotExist | Whether or not to throw an error when the directory in the path does not exist. Defaults to true. |
System.Threading.CancellationToken | cancellationToken |
FileExistsAsync(string, CancellationToken)
Checks if a file exists in the Meta FileSystem at the provided path.
public Task<bool> FileExistsAsync(string path, CancellationToken cancellationToken = default)
Returns
Task<System.Boolean>
bool: true means the file does exist.
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path. Ex: folderA/folderB/filename.txt |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
GetFileMetadataAsync(string, bool, CancellationToken)
Retrieves the metadata of a file (not the raw content of the file) from the Meta FileSystem.
public Task<IFileMetadata?> GetFileMetadataAsync(string path, bool errorWhenDoesNotExist = true, CancellationToken cancellationToken = default)
Returns
Task
< Workspace.XBR.Xperiflow.MetaFileSystem.IFileMetadata >
FileMetadata
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path. ex: folderA/folderB/filename.txt |
System.Boolean | errorWhenDoesNotExist | Whether or not to throw an error when the file does not exist. Defaults to true. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
GetFileContentStreamAsync(string, int?, CancellationToken)
Delegates the retrieval of file contents to a Stream object.
public Task<Stream> GetFileContentStreamAsync(string path, int? contentSize = -1, CancellationToken cancellationToken = default)
Returns
Task<System.IO.Stream>
Stream
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path. ex: folderA/folderB/filename.txt |
System.Nullable<System.Int32> | contentSize | The amount of content in bytes to pull back from the stream. Default to -1 which means that all the content will be retrieved. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
GetFileContentStringAsync(string, int?, CancellationToken)
Retrieve the file contents to a string object.
public Task<string> GetFileContentStringAsync(string path, int? contentSize = -1, CancellationToken cancellationToken = default)
Returns
Task<System.String>
string
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path. ex: folderA/folderB/filename.txt |
System.Nullable<System.Int32> | contentSize | The amount of content in bytes to pull back from the stream. Default to -1 which means that all the content will be retrieved. |
System.Threading.CancellationToken | cancellationToken |
GetFileContentByteArrayAsync(string, int?, CancellationToken)
Retrieve the file contents to a byte array.
public Task<byte[]> GetFileContentByteArrayAsync(string path, int? contentSize = -1, CancellationToken cancellationToken = default)
Returns
Task<System.Byte[]>
byte[]
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path. ex: folderA/folderB/filename.txt |
System.Nullable<System.Int32> | contentSize | The amount of content in bytes to pull back from the stream. Default to -1 which means that all the content will be retrieved. |
System.Threading.CancellationToken | cancellationToken |
WriteFileAsync(string, Stream, bool, CancellationToken)
Writes a file to the Meta FileSystem using a stream object.
Note that this method is subject to runtime checks that may not allow writing a file in certain locations.
public Task WriteFileAsync(string path, Stream payload, bool overwriteOk = false, CancellationToken cancellationToken = default)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path to write to. Note that if the file path does not have directories that exist, an error will be thrown. |
System.IO.Stream | payload | The file payload to write. |
System.Boolean | overwriteOk | Controls whether or not to overwrite the file if it already exists. Defaults to false. If false, an error will be thrown if the file already exists. |
System.Threading.CancellationToken | cancellationToken |
WriteFileAsync(string, byte[], bool, CancellationToken)
Writes a file to the Meta FileSystem using a byte array.
public Task WriteFileAsync(string path, byte[] payload, bool overwriteOk = false, CancellationToken cancellationToken = default)
Remarks
Note that this method is subject to runtime checks that may not allow writing a file in certain locations.
Returns
System.Threading.Tasks.Task
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path to write to. Note that if the file path does not have directories that exist, an error will be thrown. |
System.Byte[] | payload | The file payload to write. |
System.Boolean | overwriteOk | Controls whether or not to overwrite the file if it already exists. Defaults to false. If false, an error will be thrown if the file already exists. |
System.Threading.CancellationToken | cancellationToken |
WriteFileAsync(string, string, bool, CancellationToken)
Writes a file to the Meta FileSystem using a string payload.
Note that this method is subject to runtime checks that may not allow writing a file in certain locations.
public Task WriteFileAsync(string path, string payload, bool overwriteOk = false, CancellationToken cancellationToken = default)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file path to write to. Note that if the file path does not have directories that exist, an error will be thrown. |
System.String | payload | The file payload to write. |
System.Boolean | overwriteOk | Controls whether or not to overwrite the file if it already exists. Defaults to false. If false, an error will be thrown if the file already exists. |
System.Threading.CancellationToken | cancellationToken |
RemoveFileAsync(string, bool, CancellationToken)
Removes a file from the MetaFileSystem.
Note that this method is subject to runtime checks that may not allow removing a file in certain locations.
public Task RemoveFileAsync(string path, bool errorWhenDoesNotExist = true, CancellationToken cancellationToken = default)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name |
---|---|
System.String | path |
System.Boolean | errorWhenDoesNotExist |
System.Threading.CancellationToken | cancellationToken |
Implements
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object,System.Object)
System.Object.GetHashCode
System.Object.GetType
System.Object.MemberwiseClone
System.Object.ReferenceEquals(System.Object,System.Object)
System.Object.ToString