Condividi tramite


Classe SyncAgent

L'oggetto SyncAgent coordina la sincronizzazione.

Spazio dei nomi: Microsoft.Synchronization
Assembly: Microsoft.Synchronization.Data (in microsoft.synchronization.data.dll)

Sintassi

'Dichiarazione
Public Class SyncAgent
    Implements IDisposable
'Utilizzo
Dim instance As SyncAgent
public class SyncAgent : IDisposable
public ref class SyncAgent : IDisposable
public class SyncAgent implements IDisposable
public class SyncAgent implements IDisposable

Osservazioni

L'oggetto SyncAgent scorre in ciclo ciascuna delle tabelle da sincronizzare e chiama il provider di sincronizzazione client per recuperare e applicare le modifiche al database client. Chiama quindi il provider di sincronizzazione server per recuperare e applicare le modifiche al database server.

Esempio

Nell'esempio di codice seguente viene creata una classe che deriva da SyncAgent. La classe crea un'istanza di un provider di sincronizzazione client e di un provider di sincronizzazione server, crea un gruppo di sincronizzazione e aggiunge la tabella Customer. Durante l'aggiunta della tabella vengono anche specificate la direzione di sincronizzazione e l'opzione di creazione tabella. Per visualizzare questo codice nel contesto di un esempio completo, vedere Procedura: scambiare le modifiche incrementali bidirezionali ai dati tra un client e un 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

Gerarchia di ereditarietà

System.Object
  Microsoft.Synchronization.SyncAgent

Thread Safety

Tutti i membri statici pubblici (Shared in Visual Basic) di questo tipo sono thread safe. I membri di istanza non hanno garanzia di essere thread safe.

Vedere anche

Riferimento

Membri SyncAgent
Spazio dei nomi Microsoft.Synchronization