48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
namespace Salmon.Core.Depth;
|
|
|
|
public abstract class Persistence
|
|
{
|
|
/// <summary>
|
|
/// Must be thread safe
|
|
/// Must return immediately
|
|
/// </summary>
|
|
/// <param name="key">May not be null</param>
|
|
/// <param name="value"></param>
|
|
public virtual void PushStateChange(string subject, string predicate, object? value, DateTime when)
|
|
{
|
|
Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
var old = await GetLastValue(subject, predicate);
|
|
if(old != value)
|
|
|
|
await RegisterStateChange(subject, predicate, when, value);
|
|
}catch (Exception ex)
|
|
{
|
|
ExceptionCatched(ex);
|
|
}
|
|
}).ConfigureAwait(false);
|
|
}
|
|
|
|
public abstract Task<object?> GetLastValue(string subject, string predicate);
|
|
public abstract IAsyncEnumerable<Triplet> GetState();
|
|
protected abstract Task RegisterStateChange(string subject, string predicate, DateTime when, object? value);
|
|
|
|
public abstract Task RegisterEvent(Event e);
|
|
public abstract Task<Event?> GetEvent(string id);
|
|
public abstract IAsyncEnumerable<Event> GetEvents(
|
|
string? subject = null,
|
|
DateTime? from = null,
|
|
DateTime? to = null,
|
|
int? limit = null,
|
|
int? offset = null,
|
|
Event.ValenceType? valenceType = null,
|
|
Dictionary<string, object>? filters = null);
|
|
|
|
protected virtual void ExceptionCatched(Exception e)
|
|
{
|
|
Console.WriteLine(e.ToString());
|
|
}
|
|
}
|