Class RecoverOrDiscardUnsyncedChangesHandler
A client reset strategy that attempts to automatically recover any unsynchronized changes. If that fails, this handler falls back to the discard unsynced changes strategy.
Namespace: Realms.Sync.ErrorHandling
Assembly: Realm.dll
Syntax
public sealed class RecoverOrDiscardUnsyncedChangesHandler : ClientResetHandlerBase
Remarks
The automatic recovery fails when a client that is configured for recovery is flagged on the server "as not allowed to execute automatic recovery". In this situation this strategy falls back to the discard unsynced one. To reiterate what it does: it discards all the unsynced local changes and uses the latest realm that is available on the remote sync server. You can read more about the automatic merge rules at Client Resets - .NET SDK. The automatic recovery mechanism creates write transactions meaning that all the changes that take place are properly propagated through the standard Realm's change notifications. The RecoverOrDiscardUnsyncedChangesHandler strategy supplies four callbacks: OnBeforeReset, OnAfterRecovery, OnAfterDiscard and ManualResetFallback. OnBeforeReset, is invoked just before the client reset happens. OnAfterRecovery, is invoke if and only if an automatic client reset succeeded. The callback is never called if the automatic client reset fails. OnAfterDiscard is invoked if and only if an automatic client reset failed and instead the discard unsynced one succeeded. The callback is never called if the discard unsynced client reset fails. ManualResetFallback is invoked whenever an error occurs in either of the recovery strategies and the system needs to fallback to a manual mode. The overall recommendation for using this strategy is that using the three available callbacks should only be considered when:
- The user needs to be notified (in OnBeforeReset) of an incoming potential data loss of unsynced data as a result of a merge or a complete discard of unsynced local changes
- The user needs to be notified (in OnAfterRecovery or OnAfterDiscard) that the reset process has completed
- Advanced use cases for data-sensitive applications where the developer wants to recover in the most appropriate way the unsynced data
- Backup the whole realm before the client reset happens (in OnBeforeReset). Such backup could, for example, be used to restore the unsynced data (see 3.)
Properties
| Edit this page View SourceManualResetFallback
Gets or sets the callback triggered when an error has occurred that makes the operation unable to complete, for example in the case of a destructive schema change.
Declaration
public ClientResetHandlerBase.ClientResetCallback? ManualResetFallback { get; set; }
Property Value
Type | Description |
---|---|
ClientResetHandlerBase.ClientResetCallback | Callback invoked if automatic Client Reset handling fails. |
OnAfterDiscard
Gets or sets the callback that indicates that the discard unsynced changes fallback for a Client Reset just happened.
Declaration
public ClientResetHandlerBase.AfterResetCallback? OnAfterDiscard { get; set; }
Property Value
Type | Description |
---|---|
ClientResetHandlerBase.AfterResetCallback | Callback invoked right after a Client Reset that fell back to discard unsynced changes. |
Remarks
When a Client Reset with automatic recovery is attempted but the client is not allowed to use such strategy by the server, then a Client Reset is re-tried with the fallback discard unsynced changes strategy. If this second attempt succeeds, the OnAfterDiscard callback is called.
OnAfterRecovery
Gets or sets the callback that indicates that an automatic Client Reset just happened.
Declaration
public ClientResetHandlerBase.AfterResetCallback? OnAfterRecovery { get; set; }
Property Value
Type | Description |
---|---|
ClientResetHandlerBase.AfterResetCallback | Callback invoked right after a Client Reset. |
OnBeforeReset
Gets or sets the callback that indicates a Client Reset is about to happen.
Declaration
public ClientResetHandlerBase.BeforeResetCallback? OnBeforeReset { get; set; }
Property Value
Type | Description |
---|---|
ClientResetHandlerBase.BeforeResetCallback | Callback invoked right before a Client Reset. |