Class ResourceProviderResourceReferenceStore<T>
- Namespace
- FoundationaLLM.Common.Services.ResourceProviders
- Assembly
- FoundationaLLM.Common.dll
Maintains a collection of resource references used by FoundationaLLM resource providers.
public class ResourceProviderResourceReferenceStore<T> where T : ResourceReference
Type Parameters
T
The type of resource reference kept in the store.
- Inheritance
-
ResourceProviderResourceReferenceStore<T>
- Inherited Members
- Extension Methods
Constructors
ResourceProviderResourceReferenceStore(IResourceProviderService, IStorageService, ILogger, CancellationToken)
Maintains a collection of resource references used by FoundationaLLM resource providers.
public ResourceProviderResourceReferenceStore(IResourceProviderService resourceProvider, IStorageService resourceProviderStorageService, ILogger logger, CancellationToken cancellationToken = default)
Parameters
resourceProvider
IResourceProviderServiceThe IResourceProviderService resource provider service that uses the reference store.
resourceProviderStorageService
IStorageServiceThe IStorageService used by the resource provider.
logger
ILoggerThe ILogger service used by the resource provider.
cancellationToken
CancellationTokenThe CancellationToken used by the resource provider to signal the need to cancel operations.
Properties
DefaultResourceName
Gets the name of the default resource (if any).
public string? DefaultResourceName { get; }
Property Value
Methods
AddResourceReference(T)
Adds a resource reference to the store.
public Task AddResourceReference(T resourceReference)
Parameters
resourceReference
TThe resource reference to add.
Returns
AddResourceReferences(IEnumerable<T>)
Adds a resource reference to the store.
public Task AddResourceReferences(IEnumerable<T> resourceReferences)
Parameters
resourceReferences
IEnumerable<T>The list of resource references to add.
Returns
DeleteResourceReference(T)
Deletes a resource reference from the store.
public Task DeleteResourceReference(T resourceReference)
Parameters
resourceReference
TThe name of the resource to delete.
Returns
Exceptions
GetAllResourceReferences<T1>()
Gets all resource references of type T1 in the store.
public Task<IEnumerable<T>> GetAllResourceReferences<T1>() where T1 : ResourceBase
Returns
- Task<IEnumerable<T>>
A List<T> containing all the resource references of the specified type.
Type Parameters
T1
Remarks
This method is not safe in scenarios where multiple instances of a resource provider are running at the same time.
GetResourceReference(string)
Gets a resource reference by the unique name of the resource.
public Task<T?> GetResourceReference(string resourceName)
Parameters
resourceName
stringThe name of the resource.
Returns
- Task<T>
GetResourceReferences(IEnumerable<string>)
Gets the resource references for the specified resource names.
public Task<IEnumerable<T>> GetResourceReferences(IEnumerable<string> resourceNames)
Parameters
resourceNames
IEnumerable<string>The list of resource names for which the references should be retrieved.
Returns
- Task<IEnumerable<T>>
GetResourceReferences(Func<T, bool>)
Filters the resource references in the store based on the predicate.
public Task<IEnumerable<T>> GetResourceReferences(Func<T, bool> predicate)
Parameters
Returns
- Task<IEnumerable<T>>
Remarks
This method is not safe in scenarios where multiple instances of a resource provider are running at the same time.
LoadResourceReferences()
Loads the resource references from the storage service.
public Task LoadResourceReferences()
Returns
PurgeResourceReference(T)
public Task PurgeResourceReference(T resourceReference)
Parameters
resourceReference
T
Returns
Exceptions
SetDefaultResourceName(T)
Sets the default resource name on the store.
public Task SetDefaultResourceName(T resourceReference)
Parameters
resourceReference
TThe resource reference to set as the default.
Returns
TryGetResourceReference(string)
Attempts to get a resource reference by the unique name of the resource.
public Task<(bool Success, bool Deleted, T? ResourceReference)> TryGetResourceReference(string resourceName)
Parameters
resourceName
stringThe name of the resource.
Returns
- Task<(bool Success, bool Deleted, T ResourceReference)>
A tuple containing a boolean value (Success) indicating whether the resource reference was successfully retrieved, a boolean value (Deleted) indicating whether the resource is deleted (and not purged), and the resource reference itself (ResourceReference).
Remarks
When Success is false
, the ResourceReference will be null
.
This means that the resource reference was not found in the store.
When Success is true
, the ResourceReference will contain the reference to the resource.
This means that the resource reference is either valid or it has been logically deleted.
Callers should check the Deleted value to determine whether the resource was logically deleted.