Partager via


Interface ISimpleSyncProviderConstraintConflictResolver

Représente un outil de résolution des conflits personnalisé qui gère les conflits de contraintes, tels que les insertions d'éléments en double dans plusieurs réplicas.

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

Syntaxe

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

Notes

Pour plus d'informations sur les conflits de contraintes, 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 MergeConstraintConflict implémentée pour répondre à une action de résolution Merge (fusion) pour un conflit de contraintes :

public void MergeConstraintConflict(object itemData, 
    ConflictVersionInformation conflictVersionInformation, 
    IEnumerable<SyncId> changeUnitsToMerge, 
    ItemFieldDictionary localConflictingItem, 
    ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out ItemFieldDictionary updatedKeyAndVersion)
{
    ItemTransfer transfer = (ItemTransfer)itemData;
    ItemData dataCopy = new ItemData(transfer.ItemData);

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

    // We are doing a merge so we must delete the old conflicting item from our store.
    ulong idConflicting = (ulong)localConflictingItem[CUSTOM_FIELD_ID].Value;

    _store.DeleteItem(idConflicting);

    // Now create the new merged data in the store.
    if (_store.Contains(transfer.Id))
    {
        _store.UpdateItem(transfer.Id, dataCopy);
    }
    else
    {
        _store.CreateItem(mergedData, transfer.Id);
    }

    updatedKeyAndVersion = _store.CreateItemFieldDictionary(transfer.Id);
}
Public Sub MergeConstraintConflict(ByVal itemData As Object, ByVal conflictVersionInformation As ConflictVersionInformation, ByVal changeUnitsToMerge As IEnumerable(Of SyncId), ByVal localConflictingItem As ItemFieldDictionary, ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, _
ByRef updatedKeyAndVersion As ItemFieldDictionary) Implements ISimpleSyncProviderConstraintConflictResolver.MergeConstraintConflict
    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))

    ' We are doing a merge so we must delete the old conflicting item from our store. 
    Dim idConflicting As ULong = CULng(localConflictingItem(CUSTOM_FIELD_ID).Value)

    _store.DeleteItem(idConflicting)

    ' Now create the new merged data in the store. 
    If _store.Contains(transfer.Id) Then
        _store.UpdateItem(transfer.Id, dataCopy)
    Else
        _store.CreateItem(mergedData, transfer.Id)
    End If

    updatedKeyAndVersion = _store.CreateItemFieldDictionary(transfer.Id)
End Sub

Voir aussi

Référence

Membres ISimpleSyncProviderConstraintConflictResolver

Espace de noms Microsoft.Synchronization.SimpleProviders