Partager via


Classe SyncAgent

L'objet SyncAgent gère la synchronisation.

Espace de noms :  Microsoft.Synchronization
Assembly :  Microsoft.Synchronization.Data (dans Microsoft.Synchronization.Data.dll)

Syntaxe

'Déclaration
Public Class SyncAgent _
    Implements IDisposable
'Utilisation
Dim instance As SyncAgent
public class SyncAgent : IDisposable
public ref class SyncAgent : IDisposable
type SyncAgent =  
    class
        interface IDisposable
    end
public class SyncAgent implements IDisposable

Notes

SyncAgent parcourt chacune des tables à synchroniser et appelle le fournisseur de synchronisation client afin de récupérer les modifications et de les appliquer à la base de données client. Il appelle ensuite le fournisseur de synchronisation serveur afin de récupérer les modifications et de les appliquer à la base de données serveur.

Exemples

L'exemple de code suivant crée une classe qui dérive de SyncAgent. La classe instancie un fournisseur de synchronisation client et un fournisseur de synchronisation serveur, crée un groupe de synchronisation, puis ajoute la table Customer. Lors de l'ajout de la table, la direction de la synchronisation et une option de création de table sont également spécifiées. Pour afficher ce code dans le contexte d'un exemple complet, consultez Procédure : échanger des modifications de données incrémentielles bidirectionnelles entre un client et un serveur.

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

Hiérarchie d'héritage

System. . :: . .Object
  Microsoft.Synchronization..::..SyncAgent

Sécurité des threads

Tous les membres publics static (Shared dans Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi

Référence

Membres SyncAgent

Espace de noms Microsoft.Synchronization