Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
Representa un solucionador de conflictos personalizado que se ocupa de los conflictos de restricción, como por ejemplo de los elementos duplicados que se insertan en varias réplicas.
Espacio de nombres: Microsoft.Synchronization.SimpleProviders
Ensamblado: Microsoft.Synchronization.SimpleProviders (en microsoft.synchronization.simpleproviders.dll)
Sintaxis
'Declaración
Public Interface ISimpleSyncProviderConstraintConflictResolver
'Uso
Dim instance As ISimpleSyncProviderConstraintConflictResolver
public interface ISimpleSyncProviderConstraintConflictResolver
public interface class ISimpleSyncProviderConstraintConflictResolver
public interface ISimpleSyncProviderConstraintConflictResolver
public interface ISimpleSyncProviderConstraintConflictResolver
Notas
Para obtener más información sobre conflictos de restricción, vea Controlar conflictos en proveedores simples.
Ejemplo
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 MergeConstraintConflict que se implementa para responder a una acción de resolución de Merge en un conflicto de restricción:
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
Vea también
Referencia
ISimpleSyncProviderConstraintConflictResolver Miembros
Microsoft.Synchronization.SimpleProviders Espacio de nombres