PulseSharp.Sync
Device to cloud sync: the client that runs on the device.
Generated from the XML documentation of
PulseSharp.Sync.
IPulseSync
public interface IPulseSyncShows how sync is going and starts a sync on request, for example from a "Sync now" button.
Status
The result of the last sync.
SyncNow(CancellationToken)
Syncs at once instead of waiting for the next interval. Never throws when the server can't be reached: the returned status says what happened.
| Parameter | Description |
|---|---|
cancellationToken | Cancels the sync. |
Returns: The status after the sync.
StatusChanged()
Raised whenever the status changes: after every sync, and when events are saved or sent so that SyncStatus.Waiting changes. It runs on a background thread, so a UI must switch to its own thread. An exception in a subscriber is logged and does not affect sync.
PulseSharpSyncExtensions
public static class PulseSharpSyncExtensionsAdds device to cloud sync to PulseSharp.
UseSync(PulseSharpBuilder, Action<SyncOptions>)
Sends the events this app emits to a server, and receives the server's events, whenever the server can be reached. The app keeps working offline; nothing is lost or sent twice.
| Parameter | Description |
|---|---|
pulse | The PulseSharp builder. |
configure | Sets the server address and the other options. |
Returns: The builder.
Throws InvalidOperationException when sync is added twice, or an option is not valid.
Sync runs in the background. Inject IPulseSync to show its status or to sync at once. Run sync in one app instance per node.
Example
pulse.UseSync(sync =>
{
sync.Server = new Uri("https://cloud.example.com/pulse/sync");
sync.ApiKey = apiKey;
sync.PullStreams.Add("Product-");
});SyncOptions
public sealed class SyncOptionsHow this app syncs its events with a server. Set them in pulse.UseSync(sync => { ... }).
Server
The address of the server's sync endpoint, for example https://cloud.example.com/pulse/sync. Required.
ApiKey
The key the server gave this node, sent with every request. Leave it empty when SyncOptions.Authorize signs requests another way.
Push
Whether this node sends the events it emits to the server. The default is true.
Pull
Whether this node receives the server's events. The default is true.
PullStreams
Receive only the events whose stream name starts with one of these prefixes, for example Product-. Empty means every event the server allows this node to receive.
Interval
How often to sync while online. While the server can't be reached, the wait grows up to a minute (or this interval, when it is longer). The default is 5 seconds.
BatchSize
How many events one request carries. Larger backlogs are sent in several requests. The default is 200.
Authorize
Changes every request before it is sent, for example to add a bearer token. Optional.
HttpHandler
The HTTP handler to send requests with, for example one with a proxy or client certificate. Optional.
SyncStatus
public sealed record SyncStatusThe result of the last sync.
| Parameter | Description |
|---|---|
Online | Whether the last sync reached the server and finished. |
LastSyncedAt | When a sync last finished, or null when none has yet. |
LastError | Why the last sync failed, or null when it succeeded. |
Waiting | How many events saved on this device the server has not confirmed yet. It also counts events that were saved while the app was offline or before it was last started. |
SyncStatus(bool, DateTimeOffset?, string, int)
The result of the last sync.
| Parameter | Description |
|---|---|
Online | Whether the last sync reached the server and finished. |
LastSyncedAt | When a sync last finished, or null when none has yet. |
LastError | Why the last sync failed, or null when it succeeded. |
Waiting | How many events saved on this device the server has not confirmed yet. It also counts events that were saved while the app was offline or before it was last started. |
Online
Whether the last sync reached the server and finished.
LastSyncedAt
When a sync last finished, or null when none has yet.
LastError
Why the last sync failed, or null when it succeeded.
Waiting
How many events saved on this device the server has not confirmed yet. It also counts events that were saved while the app was offline or before it was last started.