SyncAgent Class

The SyncAgent object orchestrates synchronization.

Inheritance Hierarchy

System.Object
  Microsoft.Synchronization.SyncAgent

Namespace:  Microsoft.Synchronization
Assembly:  Microsoft.Synchronization.Data (in Microsoft.Synchronization.Data.dll)

Syntax

'Declaration
Public Class SyncAgent _
    Implements IDisposable
'Usage
Dim instance As SyncAgent
public class SyncAgent : IDisposable
public ref class SyncAgent : IDisposable
type SyncAgent =  
    class
        interface IDisposable
    end
public class SyncAgent implements IDisposable

The SyncAgent type exposes the following members.

Constructors

  Name Description
Public method SyncAgent() Initializes a new instance of the SyncAgent class by using default values.
Public method SyncAgent(SyncProvider, SyncProvider) Initializes a new instance of the SyncAgent class by using local synchronization provider and remote synchronization provider parameters.

Top

Properties

  Name Description
Public property Configuration Gets a SyncConfiguration object that contains information about tables and synchronization parameters.
Public property LocalProvider Gets or sets an object derived from ClientSyncProvider that is used to communicate with the local data store.
Public property RemoteProvider Gets or sets an object derived from ServerSyncProvider that is used to communicate with the remote data store.
Public property SessionState Gets or sets a SyncSessionState object that is used to define whether the session is currently synchronizing.
Public property SyncStatistics Gets a SyncStatistics object that represents statistics for a synchronization session.

Top

Methods

  Name Description
Public method Dispose() Releases all resources used by the SyncAgent.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the SyncAgent, and optionally releases the managed resources.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Protected method OnSessionProgress Raises the SessionProgress event.
Protected method OnSessionStateChanged Raises the StateChanged event.
Public method Synchronize Synchronizes data between the local and remote data stores.
Public method ToString (Inherited from Object.)

Top

Events

  Name Description
Public event SessionProgress Occurs during synchronization: after metadata is read at the client, after metadata is written, after changes are downloaded, and after changes are uploaded.
Public event StateChanged Occurs when there is a change in the synchronization session state.

Top

Remarks

The SyncAgent loops through each of the tables to be synchronized and calls the client synchronization provider to retrieve and apply changes at the client database. Then it calls the server synchronization provider to retrieve and apply changes at the server database.

Examples

The following code example creates a class that derives from SyncAgent. The class instantiates a client synchronization provider and a server synchronization provider, creates a synchronization group, and adds the Customer table. When adding the table, synchronization direction and a table creation option are also specified. To view this code in the context of a complete example, see How to: Exchange Bidirectional Incremental Data Changes Between a Client and Server.

public class SampleSyncAgent : SyncAgent
{
    public SampleSyncAgent()
    {            
        //Instantiate a client synchronization provider and specify it
        //as the local provider for this synchronization agent.
        this.LocalProvider = new SampleClientSyncProvider();

        //Instantiate a server synchronization provider and specify it
        //as the remote provider for this synchronization agent.
        this.RemoteProvider = new SampleServerSyncProvider();

        //Create a Customer SyncGroup. This is not required
        //for the single table we are synchronizing; it is typically
        //used so that changes to multiple related tables are 
        //synchronized at the same time.
        SyncGroup customerSyncGroup = new SyncGroup("Customer");

        //Add the Customer table: specify a synchronization direction of
        //Bidirectional, and that an existing table should be dropped.
        SyncTable customerSyncTable = new SyncTable("Customer");
        customerSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
        customerSyncTable.SyncDirection = SyncDirection.Bidirectional;
        customerSyncTable.SyncGroup = customerSyncGroup;
        this.Configuration.SyncTables.Add(customerSyncTable);
    }
}
Public Class SampleSyncAgent
    Inherits SyncAgent

    Public Sub New()
        'Instantiate a client synchronization provider and specify it
        'as the local provider for this synchronization agent.
        Me.LocalProvider = New SampleClientSyncProvider()

        'Instantiate a server synchronization provider and specify it
        'as the remote provider for this synchronization agent.
        Me.RemoteProvider = New SampleServerSyncProvider()

        'Create a Customer SyncGroup. This is not required
        'for the single table we are synchronizing; it is typically
        'used so that changes to multiple related tables are 
        'synchronized at the same time.
        Dim customerSyncGroup As New SyncGroup("Customer")

        'Add the Customer table: specify a synchronization direction of
        'Bidirectional, and that an existing table should be dropped.
        Dim customerSyncTable As New SyncTable("Customer")
        customerSyncTable.CreationOption = TableCreationOption.DropExistingOrCreateNewTable
        customerSyncTable.SyncDirection = SyncDirection.Bidirectional
        customerSyncTable.SyncGroup = customerSyncGroup
        Me.Configuration.SyncTables.Add(customerSyncTable)

    End Sub 'New
End Class 'SampleSyncAgent

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.Synchronization Namespace