PulseSharp.Sync.Server
Device to cloud sync: the ASP.NET Core endpoint on the server.
Generated from the XML documentation of
PulseSharp.Sync.Server.
PulseSharpSyncEndpointExtensions
public static class PulseSharpSyncEndpointExtensionsMaps the endpoint of PulseSharp sync in an ASP.NET Core app.
MapPulseSharpSync(IEndpointRouteBuilder, string)
Maps the sync endpoint that devices call. Add the sync server first with PulseSharpSyncServerExtensions.UseSyncServer.
| Parameter | Description |
|---|---|
endpoints | The app's endpoints. |
pattern | The address of the endpoint. The default is /pulse/sync. |
Returns: A builder for the endpoint, for example to add .RequireAuthorization().
Throws InvalidOperationException when the sync server was not added, or the store can't sync.
PulseSharpSyncServerExtensions
public static class PulseSharpSyncServerExtensionsAdds the server side of PulseSharp sync.
UseSyncServer(PulseSharpBuilder, Action<SyncServerOptions>)
Lets devices sync with this app: they send the events they emit, and receive this app's events. Map the endpoint with app.MapPulseSharpSync().
| Parameter | Description |
|---|---|
pulse | The PulseSharp builder. |
configure | Says which nodes may sync and what they may receive. |
Returns: The builder.
Throws InvalidOperationException when no node is allowed, or the sync server is added twice.
Example
builder.Services.AddPulseSharp(pulse =>
{
pulse.UsePostgreSql(connectionString);
pulse.Node = "cloud";
pulse.UseSyncServer(server => server.AllowNode("till-1", tillKey).PushStreams(node => [$"Sale-{node}-"]));
});
app.MapPulseSharpSync();SyncServerOptions
public sealed class SyncServerOptionsWho may sync with this server and what they may receive. Set them in pulse.UseSyncServer(server => { ... }).
Every request must be from a known node: one with a key from SyncServerOptions.AllowNode, or a signed-in user that SyncServerOptions.NodeFrom turns into a node name. A node may only send events it emitted itself. By default it receives every event it did not emit; SyncServerOptions.AllowNode and SyncServerOptions.PullStreams narrow that down.
MaxBatchSize
The most events one request may carry. The default is 1000.
AllowNode(string, string, string[])
Lets a node sync with a key, for example a till that sets sync.ApiKey in pulse.UseSync(...).
| Parameter | Description |
|---|---|
node | The node's name: the pulse.Node of that app. |
apiKey | The node's secret key. Keep it out of source code, for example in configuration. |
pullStreams | The stream name prefixes this node may receive, for example Product-. None means every event it did not emit. |
Returns: These options.
Example
server.AllowNode("till-1", configuration["Tills:till-1"]!, "Product-", "Price-");NodeFrom(Func<ClaimsPrincipal, string>)
Lets signed-in users sync, for apps that already authenticate devices (for example with tokens).
| Parameter | Description |
|---|---|
node | Returns the node name of a signed-in user, or null when the user may not sync. |
Returns: These options.
Example
server.NodeFrom(user => user.FindFirst("device")?.Value);PullStreams(Func<string, IReadOnlyList<string>>)
Limits what each node may receive, by stream name prefix. Used for nodes that SyncServerOptions.AllowNode gave no prefixes.
| Parameter | Description |
|---|---|
allowedStreams | Returns the prefixes a node may receive. An empty list means nothing. |
Returns: These options.
Example
server.PullStreams(node => [$"Store-{StoreOf(node)}-", "Product-"]);PushStreams(Func<string, IReadOnlyList<string>>)
Says which streams each device may write. A device that sends an event for any other stream has that event refused (the server logs a warning and the device logs one too); its other events are saved as usual. This keeps a device from writing into streams that belong to the server or to another device. The names are prefixes.
| Parameter | Description |
|---|---|
allowedStreams | Gets a node's name and returns the stream name prefixes it may write. |
Returns: These options.
Example
server.PushStreams(node => [$"Sale-{node}-"]);PushAnyStream()
Lets every device write every stream. Only choose this when you trust all devices completely: a device could then write into streams that belong to the server, for example a price list.
Returns: These options.