Compartir a través de


ISimpleSyncProviderConcurrencyConflictResolver Interfaz

Representa un solucionador de conflictos personalizado que administra los conflictos de simultaneidad, como por ejemplo cuando el mismo elemento se actualiza en la réplica local y se elimina en la réplica remota.

Espacio de nombres:  Microsoft.Synchronization.SimpleProviders
Ensamblado:  Microsoft.Synchronization.SimpleProviders (en Microsoft.Synchronization.SimpleProviders.dll)

Sintaxis

'Declaración
Public Interface ISimpleSyncProviderConcurrencyConflictResolver
'Uso
Dim instance As ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver
public interface class ISimpleSyncProviderConcurrencyConflictResolver
type ISimpleSyncProviderConcurrencyConflictResolver =  interface end
public interface ISimpleSyncProviderConcurrencyConflictResolver

Notas

Para obtener más información sobre conflictos de simultaneidad, vea Controlar conflictos en proveedores simples.

Ejemplos

En este ejemplo, las directivas de administración de conflictos de simultaneidad y restricción se mantienen como valor predeterminado de ApplicationDefined. Esto significa que la aplicación se registrará para los eventos ItemConstraint y ItemConflicting, y especificará una acción para resolver conflictos si se producen durante el procesamiento de sincronización. Para obtener más información, vea Controlar conflictos en proveedores simples. Para consultar este código en el contexto de una aplicación completa, vea la aplicación "Sync101 using Simple Sync Provider" que está disponible en Sync Framework SDK y en Code Gallery. En el ejemplo de código siguiente se muestran los controladores de eventos que se especifican en el constructor de MyFullEnumerationSimpleSyncProvider.

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

En el ejemplo de código siguiente se muestran los controladores de eventos que establecen las acciones de resolución de conflictos en 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

En el ejemplo de código siguiente se muestra el método ResolveUpdateUpdateConflict que se implementa para responder a una acción de resolución de Merge en un conflicto de simultaneidad:

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

Vea también

Referencia

ISimpleSyncProviderConcurrencyConflictResolver Miembros

Microsoft.Synchronization.SimpleProviders Espacio de nombres