Callback Handlers

To receive callbacks, you must register a CallBackHandler with the generated database class, the entity class, or both. You can create a handler by extending the DefaultCallbackHandler class, or by implementing the interface, ICallbackHandler.

In your handler, override the particular callback you want to use (for example, OnImport). The callback is executed in the thread that is performing the action (for example, import). When you receive the callback, the particular activity is already complete.

Note: Message-based synchronization and replication-based synchronization share the same CallbackHandler interface. Some of the callbacks are applicable to message-based synchronization only or to replication-based synchronization only, while others are shared by both.

Callbacks in the CallbackHandler interface include:

namespace Sybase.Persistence
{
    /// <summary>
    /// Call back interface which would get called based on event.
    /// </summary>
    /// <remarks>
    /// MBS and RBS share the same CallbackHandler interface. 
    /// Some of the callbacks are applicable to MBS only or RBS only, others are common.
    /// Please see the method comments for the details.
    /// </remarks>
    public interface ICallbackHandler
    {
        /// <summary>
        /// Called when a import message successfully applies to databases.
        /// <param name="mbo">The Mobile Business Object was just imported.</param>
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnImport(object o);

        /// <summary>
        /// Called when login fails.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnLoginFailure();
        
        /// <summary>
        /// Called when login succeeds.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnLoginSuccess();        

        /// <summary>
        /// Called when a replay request fails
        /// <param name="mbo">The Mobile Business Object to replay.</param>
        /// </summary>
        void OnReplayFailure(object o);

        /// <summary>
        /// Called when a replay request succeeds
        /// <param name="mbo">The Mobile Business Object to replay.</param>
        /// </summary>
        void OnReplaySuccess(object o);

        /// <summary>
        /// Called when a backend search fails
        /// <param name="mbo">The backend search object</param>
        /// </summary>
        void OnSearchFailure(object o);

        /// <summary>
        /// Called when a backend search succeeds
        /// <param name="mbo">The backend search object</param>
        /// </summary>
        void OnSearchSuccess(object o);

        /// <summary>
        /// Called when subscribe succeeds
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnSubscribeSuccess();

        /// <summary>
        /// Called when subscribe fails
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnSubscribeFailure();
        
        /// <summary>
        /// Called when last import message has already been processed successfully regarding subscribe\resume\recover request.
        /// </summary>      
        /// <remarks>MBS only</remarks>        
        void OnImportSuccess();

        /// <summary>
        /// Called when unsubscribe succeeds.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnUnsubscribeSuccess();

        /// <summary>
        /// Called when unsubscribe fails.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnUnsubscribeFailure();

        /// <summary>
        /// Called when suspend subscription succeeds.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnSuspendSubscriptionSuccess();

        /// <summary>
        /// Called when suspend subscription fails.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnSuspendSubscriptionFailure();

        /// <summary>
        /// Called when resume subscription succeeds.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnResumeSubscriptionSuccess();

        /// <summary>
        /// Called when resume subscription fails.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnResumeSubscriptionFailure();

        /// <summary>
        /// Called when recover succeeds.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnRecoverSuccess();

        /// <summary>
        /// Called when recover fails.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnRecoverFailure();

        /// <summary>
        /// Called when reset succeeds.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnResetSuccess();

        /// <summary>
        /// Called at the specified status of the synchronization.
        /// <param name="groups">a list of synchronization groups.</param>
        /// <param name="context">synchronization context.</param>
        /// </summary>
        /// <remarks>RBS only</remarks>
        SynchronizationAction OnSynchronize(Sybase.Collections.GenericList<Sybase.Persistence.ISynchronizationGroup> groups, SynchronizationContext context);
        
        /// <summary>
        /// Called if the synchronization failed.
        /// </summary>
        /// <param name="groups">a list of synchronization groups.</param>
        /// <remarks>RBS only</remarks>
        void OnSynchronizeFailure(Sybase.Collections.GenericList<Sybase.Persistence.ISynchronizationGroup> groups);

        /// <summary>
        /// Called if synchronization succeed.
        /// </summary>
        /// <param name="groups">a list of synchronization groups.</param>
        /// <remarks>RBS only</remarks>
        void OnSynchronizeSuccess(Sybase.Collections.GenericList<Sybase.Persistence.ISynchronizationGroup> groups);

        /// <summary>
        /// Called when subscription end.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnSubscriptionEnd();
        

        /// <summary>
        /// Other callbacks in this interface (whose names begin with "on") are invoked inside a database transaction. If the transaction will be rolled back due to an unexpected exception, then this operation will be called with the exception (before rollback occurs).
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnMessageException(System.Exception ex);

        /// <summary>
        /// Other callbacks in this interface (whose names begin with "on") are invoked inside a database transaction. If the transaction is successfully committed, then this operation will be invoked after commit.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnTransactionCommit();

        /// <summary>
        /// Other callbacks in this interface (whose names begin with "on") are invoked inside a database transaction. If the transaction is rolled back, then this operation will be invoked after rollback.
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnTransactionRollback();

        /// <summary>
        /// Called before applying an import message to database.
        /// <param name="mbo">The Mobile Business Object to be imported.</param>
        /// </summary>
        /// <remarks>MBS only</remarks>
        void BeforeImport(object o);        

        /// <summary>
        /// Called when device storage is critically low
        /// </summary>
        /// <remarks>MBS only</remarks>
        void OnStorageSpaceLow();

        /// <summary>
        /// Called when device storage becomes sufficient again.
        /// </summary>        
        /// <remarks>MBS only</remarks>
        void OnStorageSpaceRecovered();

 
        /// <summary>
        /// This method will be invoked when the device status has changed
        /// </summary>
        /// <param name="status_1">The current device connection status</param>
        /// <param name="type_2">The current device connection type</param>
        /// <param name="errorCode">The connection error code</param>
        /// <param name="errorMessage">The connection error message</param>  
        void OnConnectionStatusChange(int status_1, int type_2, int errorCode, string errorMessage);
    }
}

This code example shows how to create and register a handler to receive callbacks:

public class MyCallbackHandler : DefaultCallbackHandler
{
    // implementation
}

CallbackHandler handler = new MyCallbackHandler();
MyDatabase.RegisterCallbackHandler(handler);
//or Customer.RegisterCallbackHandler(handler);