Class FileSystemAssetRepository
- Namespace
- Tudormobile.IronLedgerLib
- Assembly
- Tudormobile.IronLedgerLib.dll
An IAssetRepository implementation that stores each asset as a JSON file and an optional Markdown notes file under a configurable root directory.
public class FileSystemAssetRepository : IAssetRepository
- Inheritance
-
FileSystemAssetRepository
- Implements
- Inherited Members
Remarks
Each asset is stored in its own subdirectory named after Id:
{dataPath}/
{assetId}/
asset.json
notes.md
Constructors
FileSystemAssetRepository(string, IIronLedgerSerializer)
Initializes a new instance of the FileSystemAssetRepository class.
public FileSystemAssetRepository(string dataPath, IIronLedgerSerializer serializer)
Parameters
dataPathstringThe root directory under which asset folders are stored.
serializerIIronLedgerSerializerThe serializer used to read and write asset JSON files.
Methods
DeleteAsync(string, CancellationToken)
Deletes the asset record and its associated notes for the given identifier.
public Task DeleteAsync(string assetId, CancellationToken cancellationToken = default)
Parameters
assetIdstringThe unique asset identifier to delete.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
ExistsAsync(AssetRecord, CancellationToken)
Determine if a record currently exists in the repository.
public Task<bool> ExistsAsync(AssetRecord asset, CancellationToken cancellationToken = default)
Parameters
assetAssetRecordThe asset record to check.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
GetAllAsync(CancellationToken)
Retrieves all stored asset records.
public Task<IReadOnlyList<AssetRecord>> GetAllAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<IReadOnlyList<AssetRecord>>
A read-only list of all stored AssetRecord instances.
GetAllIdentifiersAsync(CancellationToken)
Asynchronously retrieves all available asset identifiers.
public Task<IReadOnlyList<string>> GetAllIdentifiersAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task<IReadOnlyList<string>>
A read-only list of strings containing all identifiers. The list will be empty if no identifiers are available.
GetAsync(string, CancellationToken)
Retrieves a single asset record by its identifier.
public Task<AssetRecord?> GetAsync(string assetId, CancellationToken cancellationToken = default)
Parameters
assetIdstringThe unique asset identifier (see Id).
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<AssetRecord>
The AssetRecord if found; otherwise null.
GetNotesAsync(string, CancellationToken)
Retrieves the markdown notes associated with an asset.
public Task<string> GetNotesAsync(string assetId, CancellationToken cancellationToken = default)
Parameters
assetIdstringThe unique asset identifier.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
SaveAsync(AssetRecord, CancellationToken)
Persists an asset record, creating or overwriting any existing record with the same identifier.
public Task SaveAsync(AssetRecord asset, CancellationToken cancellationToken = default)
Parameters
assetAssetRecordThe asset record to save.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
SaveNotesAsync(string, string, CancellationToken)
Persists markdown notes for an asset, creating or overwriting any existing notes.
public Task SaveNotesAsync(string assetId, string markdown, CancellationToken cancellationToken = default)
Parameters
assetIdstringThe unique asset identifier.
markdownstringThe markdown text to save.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.