Implement in-process multi-dataset sync isolation across core, network, persistence, and tests
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m14s
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m14s
This commit is contained in:
@@ -14,6 +14,8 @@ public class SampleDocumentStore : SurrealDocumentStore<SampleDbContext>
|
||||
{
|
||||
private const string UsersCollection = "Users";
|
||||
private const string TodoListsCollection = "TodoLists";
|
||||
private const string LogsCollection = "Logs";
|
||||
private const string TimeseriesCollection = "Timeseries";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SampleDocumentStore"/> class.
|
||||
@@ -40,6 +42,8 @@ public class SampleDocumentStore : SurrealDocumentStore<SampleDbContext>
|
||||
{
|
||||
WatchCollection(UsersCollection, context.Users, u => u.Id);
|
||||
WatchCollection(TodoListsCollection, context.TodoLists, t => t.Id);
|
||||
WatchCollection(LogsCollection, context.Logs, entry => entry.Id);
|
||||
WatchCollection(TimeseriesCollection, context.Timeseries, point => point.Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -71,6 +75,8 @@ public class SampleDocumentStore : SurrealDocumentStore<SampleDbContext>
|
||||
{
|
||||
UsersCollection => SerializeEntity(await _context.Users.FindByIdAsync(key, cancellationToken)),
|
||||
TodoListsCollection => SerializeEntity(await _context.TodoLists.FindByIdAsync(key, cancellationToken)),
|
||||
LogsCollection => SerializeEntity(await _context.Logs.FindByIdAsync(key, cancellationToken)),
|
||||
TimeseriesCollection => SerializeEntity(await _context.Timeseries.FindByIdAsync(key, cancellationToken)),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
@@ -106,6 +112,12 @@ public class SampleDocumentStore : SurrealDocumentStore<SampleDbContext>
|
||||
TodoListsCollection => (await _context.TodoLists.FindAllAsync(cancellationToken))
|
||||
.Select(t => (t.Id, SerializeEntity(t)!.Value))
|
||||
.ToList(),
|
||||
LogsCollection => (await _context.Logs.FindAllAsync(cancellationToken))
|
||||
.Select(entry => (entry.Id, SerializeEntity(entry)!.Value))
|
||||
.ToList(),
|
||||
TimeseriesCollection => (await _context.Timeseries.FindAllAsync(cancellationToken))
|
||||
.Select(point => (point.Id, SerializeEntity(point)!.Value))
|
||||
.ToList(),
|
||||
_ => []
|
||||
};
|
||||
}
|
||||
@@ -137,6 +149,26 @@ public class SampleDocumentStore : SurrealDocumentStore<SampleDbContext>
|
||||
await _context.TodoLists.UpdateAsync(todo, cancellationToken);
|
||||
break;
|
||||
|
||||
case LogsCollection:
|
||||
var logEntry = content.Deserialize<TelemetryLogEntry>() ??
|
||||
throw new InvalidOperationException("Failed to deserialize telemetry log.");
|
||||
logEntry.Id = key;
|
||||
if (await _context.Logs.FindByIdAsync(key, cancellationToken) == null)
|
||||
await _context.Logs.InsertAsync(logEntry, cancellationToken);
|
||||
else
|
||||
await _context.Logs.UpdateAsync(logEntry, cancellationToken);
|
||||
break;
|
||||
|
||||
case TimeseriesCollection:
|
||||
var point = content.Deserialize<TimeseriesPoint>() ??
|
||||
throw new InvalidOperationException("Failed to deserialize timeseries point.");
|
||||
point.Id = key;
|
||||
if (await _context.Timeseries.FindByIdAsync(key, cancellationToken) == null)
|
||||
await _context.Timeseries.InsertAsync(point, cancellationToken);
|
||||
else
|
||||
await _context.Timeseries.UpdateAsync(point, cancellationToken);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException($"Collection '{collection}' is not supported for sync.");
|
||||
}
|
||||
@@ -152,6 +184,12 @@ public class SampleDocumentStore : SurrealDocumentStore<SampleDbContext>
|
||||
case TodoListsCollection:
|
||||
await _context.TodoLists.DeleteAsync(key, cancellationToken);
|
||||
break;
|
||||
case LogsCollection:
|
||||
await _context.Logs.DeleteAsync(key, cancellationToken);
|
||||
break;
|
||||
case TimeseriesCollection:
|
||||
await _context.Timeseries.DeleteAsync(key, cancellationToken);
|
||||
break;
|
||||
default:
|
||||
_logger.LogWarning("Attempted to remove entity from unsupported collection: {Collection}", collection);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user