You are here: Advanced Replication Strategies > Events

Events

Often you need more information about the replication process or even need to intervene it. dRS allows the registration of a event listener in order to perform such tasks.

When you create the replication session you can pass such a listener instance. The listener will be called for each object which is replicated.

class LogReplicationListener : IReplicationEventListener
{
    public void OnReplicate(IReplicationEvent replicationEvent)
    {
        IObjectState stateInDesktop = replicationEvent.StateInProviderA();
        if (stateInDesktop.IsNew())
        {
            Console.WriteLine("Object '{0}' is new on desktop database",
                stateInDesktop.GetObject());
        }
        if (stateInDesktop.WasModified())
        {
            Console.WriteLine("Object '{0}' was modified on desktop database", 
                stateInDesktop.GetObject());
        }
    }
}
AdvancedReplicationExamples.cs: The ReplicationEventListener for informations about the replication process
Private Class LogReplicationListener
    Implements IReplicationEventListener
    Public Sub OnReplicate(ByVal replicationEvent As IReplicationEvent) _
                                    Implements IReplicationEventListener.OnReplicate
        Dim stateInDesktop As IObjectState = replicationEvent.StateInProviderA()
        If stateInDesktop.IsNew() Then
            Console.WriteLine("Object '{0}' is new on desktop database", _
                              stateInDesktop.GetObject())
        End If
        If stateInDesktop.WasModified() Then
            Console.WriteLine("Object '{0}' was modified on desktop database", _
                              stateInDesktop.GetObject())
        End If
    End Sub
End Class
AdvancedReplicationExamples.vb: The ReplicationEventListener for informations about the replication process
IReplicationSession replicationSession 
    = Replication.Begin(desktopRelicationPartner,mobileRelicationPartner,new LogReplicationListener());
AdvancedReplicationExamples.cs: Register a listener for information about the replication process
Dim logReplicationListener As IReplicationEventListener = New LogReplicationListener()

Dim replicationSession As IReplicationSession _
    = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider, logReplicationListener)
AdvancedReplicationExamples.vb: Register a listener for information about the replication process