Class FileStore<TName, TValue>
A file based repository for name value pairs.
Inherited Members
Namespace: Ipfs.Engine
Assembly: Ipfs.Engine.dll
Syntax
public class FileStore<TName, TValue>
where TValue : class
Type Parameters
Name | Description |
---|---|
TName | The type used for a unique name. |
TValue | The type used for the value. |
Remarks
All operations are atomic, a reader/writer lock is used.
Fields
| Improve this Doc View SourceJsonDeserialize
A function to read the JSON encoded entity from the stream.
Declaration
public static Func<Stream, TName, CancellationToken, Task<TValue>> JsonDeserialize
Field Value
Type | Description |
---|---|
Func<Stream, TName, CancellationToken, Task<TValue>> |
Remarks
This is the default Deserialize.
JsonSerialize
A function to write the JSON encoded entity to the stream.
Declaration
public static Func<Stream, TName, TValue, CancellationToken, Task> JsonSerialize
Field Value
Type | Description |
---|---|
Func<Stream, TName, TValue, CancellationToken, Task> |
Remarks
This is the default Serialize.
Properties
| Improve this Doc View SourceDeserialize
Retrieves the value from the stream.
Declaration
public Func<Stream, TName, CancellationToken, Task<TValue>> Deserialize { get; set; }
Property Value
Type | Description |
---|---|
Func<Stream, TName, CancellationToken, Task<TValue>> | Defaults to using JsonDeserialize |
Folder
The fully qualififed path to a directory that stores the name value pairs.
Declaration
public string Folder { get; set; }
Property Value
Type | Description |
---|---|
String | A fully qualified path. |
Remarks
The directory must already exist.
KeyToName
A function that converts the case insensitive key to a name.
Declaration
public Func<string, TName> KeyToName { get; set; }
Property Value
Type | Description |
---|---|
Func<String, TName> |
Names
Gets the names in the file store.
Declaration
public IEnumerable<TName> Names { get; }
Property Value
Type | Description |
---|---|
IEnumerable<TName> | A sequence of |
NameToKey
A function that converts the name to a case insensitive key name.
Declaration
public Func<TName, string> NameToKey { get; set; }
Property Value
Type | Description |
---|---|
Func<TName, String> |
Serialize
Sends the value to the stream.
Declaration
public Func<Stream, TName, TValue, CancellationToken, Task> Serialize { get; set; }
Property Value
Type | Description |
---|---|
Func<Stream, TName, TValue, CancellationToken, Task> | Defaults to using JsonSerialize. |
Values
Gets the values in the file store.
Declaration
public IEnumerable<TValue> Values { get; }
Property Value
Type | Description |
---|---|
IEnumerable<TValue> | A sequence of |
Methods
| Improve this Doc View SourceExistsAsync(TName, CancellationToken)
Determines if the name exists.
Declaration
public Task<bool> ExistsAsync(TName name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TName | name | The unique name of the entity. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<Boolean> | A task that represents the asynchronous operation. The task's result is
true if the |
GetAsync(TName, CancellationToken)
Get the value with the specified name.
Declaration
public Task<TValue> GetAsync(TName name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TName | name | The unique name of the entity. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<TValue> | A task that represents the asynchronous operation. The task's result is
a |
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | When the |
GetPath(TName)
Local file system path to the name.
Declaration
public string GetPath(TName name)
Parameters
Type | Name | Description |
---|---|---|
TName | name |
Returns
Type | Description |
---|---|
String |
LengthAsync(TName, CancellationToken)
Get's the serialised length of the entity.
Declaration
public Task<long? > LengthAsync(TName name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TName | name | The unique name of the entity. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<Nullable<Int64>> | A task that represents the asynchronous operation. The task's result is a nullable long. |
Remarks
Return a null when the name
does not exist.
PutAsync(TName, TValue, CancellationToken)
Put the value with the specified name.
Declaration
public Task PutAsync(TName name, TValue value, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TName | name | The unique name of the entity. |
TValue | value | The entity. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
Remarks
If name
already exists, it's value is overwriten.
The file is deleted if an exception is encountered.
RemoveAsync(TName, CancellationToken)
Remove the value with the specified name.
Declaration
public Task RemoveAsync(TName name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TName | name | The unique name of the entity. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
Remarks
A non-existent name
does nothing.
TryGetAsync(TName, CancellationToken)
Try to get the value with the specified name.
Declaration
public Task<TValue> TryGetAsync(TName name, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TName | name | The unique name of the entity. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<TValue> | A task that represents the asynchronous operation. The task's result is
a |