Partager via


Interface ISimpleSyncProviderConcurrencyConflictResolver

Représente un outil de résolution des conflits personnalisé qui gère les conflits d'accès concurrentiel, tels que la mise à jour d'un élément sur le réplica local et sa suppression sur le réplica distant.

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

Syntaxe

'Déclaration
Public Interface ISimpleSyncProviderConcurrencyConflictResolver
'Utilisation
Dim instance As ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver
public interface class ISimpleSyncProviderConcurrencyConflictResolver
type ISimpleSyncProviderConcurrencyConflictResolver =  interface end
public interface ISimpleSyncProviderConcurrencyConflictResolver

Notes

Pour plus d'informations sur les conflits d'accès concurrentiel, consultez Gestion de conflits pour les fournisseurs simples.

Exemples

Dans cet exemple, les stratégies de gestion des conflits d'accès concurrentiel et des conflits de contraintes sont conservées comme valeurs par défaut d'ApplicationDefined. Cela signifie que l'application s'inscrira aux événements ItemConflicting et ItemConstraint et spécifiera une action visant à résoudre les conflits s'ils se produisent pendant la synchronisation. Pour plus d'informations, consultez Gestion de conflits pour les fournisseurs simples. Pour consulter ce code dans le contexte d'une application complète, consultez l'application "Sync101 using Simple Sync Provider" qui est disponible dans le Kit de développement logiciel (SDK) Sync Framework et de Code Gallery. L'exemple de code suivant illustre les gestionnaires d'événements spécifiés dans le constructeur de MyFullEnumerationSimpleSyncProvider.

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

L'exemple de code suivant illustre les gestionnaires d'événements qui définissent les actions de résolution de conflit sur 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

L'exemple de code suivant illustre la méthode ResolveUpdateUpdateConflict implémentée pour répondre à une action de résolution Merge (fusion) pour un conflit d'accès concurrentiel :

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

Voir aussi

Référence

Membres ISimpleSyncProviderConcurrencyConflictResolver

Espace de noms Microsoft.Synchronization.SimpleProviders