Share via


Interface ISimpleSyncProviderConcurrencyConflictResolver

Representa um resolvedor de conflitos personalizado que manipula conflitos de simultaneidade, como quando o mesmo item é atualizado na réplica local e excluído na réplica remota.

Namespace: Microsoft.Synchronization.SimpleProviders
Assembly: Microsoft.Synchronization.SimpleProviders (em microsoft.synchronization.simpleproviders.dll)

Sintaxe

'Declaração
Public Interface ISimpleSyncProviderConcurrencyConflictResolver
'Uso
Dim instance As ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver
public interface class ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver

Comentários

Para obter mais informações sobre conflitos de simultaneidade, consulte Manipulando conflitos para provedores simples.

Exemplo

Neste exemplo, as políticas para manipular conflitos relacionadas a conflitos de simultaneidade e conflitos de restrição são mantidas como o padrão de ApplicationDefined. Isso significa que o aplicativo registrará os eventos ItemConflicting e ItemConstraint e especificará uma ação para resolver conflitos se eles ocorrerem durante o processamento da sincronização. Para obter mais informações, consulte Manipulando conflitos para provedores simples. Para exibir esse código no contexto de um aplicativo completo, consulte o aplicativo "Sync101 using Simple Sync Provider" disponível no Sync Framework SDK e em Code Gallery. O exemplo de código a seguir mostra os manipuladores de eventos especificados no construtor de MyFullEnumerationSimpleSyncProvider.

this.ItemConstraint += new EventHandler<SimpleSyncItemConstraintEventArgs>(OnItemConstraint);
this.ItemConflicting += new EventHandler<SimpleSyncItemConflictingEventArgs>(OnItemConflicting);
AddHandler Me.ItemConstraint, AddressOf HandleItemConstraint

O exemplo de código a seguir mostra os manipuladores de eventos que definem as ações de resolução de conflito como Merge.

void OnItemConstraint(object sender, SimpleSyncItemConstraintEventArgs e)
{
    // Set the resolution action for constraint conflicts.
    // In this sample, the provider checks for duplicates in InsertItem, and this event would
    // fire if a duplicate occurred. 
    e.SetResolutionAction(ConstraintConflictResolutionAction.Merge);
}

void OnItemConflicting(object sender, SimpleSyncItemConflictingEventArgs e)
{
    // Set the resolution action for concurrency conflicts.
    e.SetResolutionAction(ConflictResolutionAction.Merge);
}
Private Sub HandleItemConstraint(ByVal sender As Object, ByVal e As SimpleSyncItemConstraintEventArgs)
    ' Set the resolution action for constraint conflicts. 
    ' In this sample, the provider checks for duplicates in InsertItem, and this event would 
    ' fire if a duplicate occurred. 
    e.SetResolutionAction(ConstraintConflictResolutionAction.Merge)
End Sub

Private Sub HandleItemConflicting(ByVal sender As Object, ByVal e As SimpleSyncItemConflictingEventArgs)
    ' Set the resolution action for concurrency conflicts. 
    e.SetResolutionAction(ConflictResolutionAction.Merge)
End Sub

O exemplo de código a seguir mostra o método ResolveUpdateUpdateConflict implementado para responder a uma ação de resolução Mesclar para um conflito de simultaneidade:

public void ResolveUpdateUpdateConflict(object itemData, 
    IEnumerable<SyncId> changeUnitsToMerge, 
    IEnumerable<SyncId> changeUnitsToUpdate, 
    ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out ItemFieldDictionary updatedVersion)
{
    ItemTransfer transfer = (ItemTransfer)itemData;
    ItemData dataCopy = new ItemData(transfer.ItemData);

    // Combine the conflicting data.
    ItemData mergedData = (_store.Get(transfer.Id)).Merge((ItemData)dataCopy);
    ulong timeStamp = _store.UpdateItem(transfer.Id, mergedData);

    updatedVersion = new ItemFieldDictionary();
    updatedVersion.Add(new ItemField(CUSTOM_FIELD_TIMESTAMP, typeof(ulong), timeStamp));
}
Public Sub ResolveUpdateUpdateConflict(ByVal itemData As Object, ByVal changeUnitsToMerge As IEnumerable(Of SyncId), ByVal changeUnitsToUpdate As IEnumerable(Of SyncId), ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, _
    ByRef updatedVersion As ItemFieldDictionary) Implements ISimpleSyncProviderConcurrencyConflictResolver.ResolveUpdateUpdateConflict
    Dim transfer As ItemTransfer = DirectCast(itemData, ItemTransfer)
    Dim dataCopy As New ItemData(transfer.ItemData)

    ' Combine the conflicting data. 
    Dim mergedData As ItemData = (_store.[Get](transfer.Id)).Merge(DirectCast(dataCopy, ItemData))
    Dim timeStamp As ULong = _store.UpdateItem(transfer.Id, mergedData)

    updatedVersion = New ItemFieldDictionary()
    updatedVersion.Add(New ItemField(CUSTOM_FIELD_TIMESTAMP, GetType(ULong), timeStamp))
End Sub

Consulte também

Referência

Membros ISimpleSyncProviderConcurrencyConflictResolver
Namespace Microsoft.Synchronization.SimpleProviders