Share via


SyncCallbacks.ItemConstraint Evento

Se produce cuando se notifica un conflicto de restricción, para los conflictos de colisión cuando la directiva de resolución de conflictos de colisión está establecida en ApplicationDefined y para todos los conflictos de restricción que no son de colisión.

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

Sintaxis

'Declaración
Public Event ItemConstraint As EventHandler(Of ItemConstraintEventArgs)
'Uso
Dim instance As SyncCallbacks
Dim handler As EventHandler(Of ItemConstraintEventArgs)

AddHandler instance.ItemConstraint, handler
public event EventHandler<ItemConstraintEventArgs> ItemConstraint
public:
event EventHandler<ItemConstraintEventArgs^>^ ItemConstraint {
    void add (EventHandler<ItemConstraintEventArgs^>^ value);
    void remove (EventHandler<ItemConstraintEventArgs^>^ value);
}
/** @event */
public void add_ItemConstraint (EventHandler<ItemConstraintEventArgs> value)

/** @event */
public void remove_ItemConstraint (EventHandler<ItemConstraintEventArgs> value)
JScript supports the use of events, but not the declaration of new ones.

Notas

Una aplicación puede utilizar esta notificación para realizar la resolución de conflictos personalizada de conflictos de restricción. Para lograrlo, la aplicación inspecciona y procesa el contenido del objeto ItemConstraintEventArgs que se envía al controlador de eventos y, a continuación, establece la acción de resolución de conflictos llamando a SetResolutionAction antes de volver de este método.

Cuando la propiedad ConstraintConflictReason del objeto ItemConstraintEventArgs está establecida en un valor distinto de Collision, la acción de resolución se debe establecer en SkipChange o SaveConflict.

Ejemplo

En el ejemplo siguiente se implementa un controlador para el evento ItemConstraint. El controlador muestra los elementos en conflicto al usuario y establece la acción de resolución de conflictos de restricción en función de la respuesta del usuario.

Private Sub HandleItemConstraint(ByVal sender As [Object], ByVal args As ItemConstraintEventArgs)
    If ConstraintConflictReason.Collision = args.ConstraintConflictReason Then
        ' Display the two items that are in conflict and solicit a resolution from the user.
        Dim srcContact As New Contact(DirectCast(args.SourceChangeData, String()))
        Dim destContact As New Contact(DirectCast(args.DestinationChangeData, String()))
        Dim msg As String = ("Source change is " & srcContact.ToString() & vbLf & "Destination change is ") & destContact.ToString() & vbLf & "Click Yes to rename the source change and apply it." & vbLf & "Click No to rename the destination item and apply the source change." & vbLf & "Click Cancel to delete the destination item and apply the source change."
        Dim ccDlg As New ConstraintConflictDlg(msg)
        ccDlg.ShowDialog()

        ' Set the resolution action based on the user's response.
        args.SetResolutionAction(ccDlg.Resolution)
    Else
        args.SetResolutionAction(ConstraintConflictResolutionAction.SaveConflict)
    End If
End Sub
void HandleItemConstraint(Object sender, ItemConstraintEventArgs args)
{
    if (ConstraintConflictReason.Collision == args.ConstraintConflictReason)
    {
        // Display the two items that are in conflict and solicit a resolution from the user.
        Contact srcContact = new Contact((string[])args.SourceChangeData);
        Contact destContact = new Contact((string[])args.DestinationChangeData);
        string msg = "Source change is " + srcContact.ToString() +
                   "\nDestination change is " + destContact.ToString() +
                   "\nClick Yes to rename the source change and apply it." +
                   "\nClick No to rename the destination item and apply the source change." +
                   "\nClick Cancel to delete the destination item and apply the source change.";
        ConstraintConflictDlg ccDlg = new ConstraintConflictDlg(msg);
        ccDlg.ShowDialog();

        // Set the resolution action based on the user's response.
        args.SetResolutionAction(ccDlg.Resolution);
    }
    else 
    {
        args.SetResolutionAction(ConstraintConflictResolutionAction.SaveConflict);
    }
}

Vea también

Referencia

SyncCallbacks Clase
SyncCallbacks Miembros
Microsoft.Synchronization Espacio de nombres

Conceptos

Detectar y resolver conflictos de restricción