Classe SyncAgent

O objeto SyncAgent organiza a sincronização.

Namespace: Microsoft.Synchronization
Assembly: Microsoft.Synchronization.Data (em microsoft.synchronization.data.dll)

Sintaxe

'Declaração
Public Class SyncAgent
    Implements IDisposable
'Uso
Dim instance As SyncAgent
public class SyncAgent : IDisposable
public ref class SyncAgent : IDisposable
public class SyncAgent implements IDisposable
public class SyncAgent implements IDisposable

Comentários

O SyncAgent forma um loop através de cada tabela a ser sincronizada e chama o provedor de sincronização do cliente para recuperar e aplicar alterações no banco de dados do cliente. Em seguida, chama o provedor de sincronização do servidor para recuperar e aplicar as alterações no banco de dados do servidor.

Exemplo

O exemplo de código a seguir cria uma classe derivada de SyncAgent. A classe instancia um provedor de sincronização do cliente e um do servidor, cria um grupo de sincronização e adiciona a tabela Customer. Quando a tabela é adicionada, também são especificadas a direção de sincronização e uma opção de criação de tabela. Para exibir esse código no contexto de um exemplo completo, consulte Como trocar alterações de dados incrementais bidirecionais entre um cliente e um servidor.

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

Hierarquia de herança

System.Object
  Microsoft.Synchronization.SyncAgent

Segurança de thread

Qualquer membro estático público (Compartilhado no Visual Basic) deste tipo é protegido por thread. Não há garantia de que qualquer membro de instância esteja protegido por thread.

Consulte também

Referência

Membros SyncAgent
Namespace Microsoft.Synchronization