Freigeben über


SaveChangeContext.RecordConstraintConflictForItem-Methode (SyncId, ConstraintConflictReason)

Meldet, dass beim Versuch des Zielanbieters, die Änderung für das Zielreplikat zu übernehmen, ein Einschränkungskonflikt aufgetreten ist, und gibt die Element-ID des in Konflikt stehenden Zielelements an.

Namespace: Microsoft.Synchronization
Assembly: Microsoft.Synchronization (in microsoft.synchronization.dll)

Syntax

'Declaration
Public Sub RecordConstraintConflictForItem ( _
    conflictingItemId As SyncId, _
    reason As ConstraintConflictReason _
)
'Usage
Dim instance As SaveChangeContext
Dim conflictingItemId As SyncId
Dim reason As ConstraintConflictReason

instance.RecordConstraintConflictForItem(conflictingItemId, reason)
public void RecordConstraintConflictForItem (
    SyncId conflictingItemId,
    ConstraintConflictReason reason
)
public:
void RecordConstraintConflictForItem (
    SyncId^ conflictingItemId, 
    ConstraintConflictReason reason
)
public void RecordConstraintConflictForItem (
    SyncId conflictingItemId, 
    ConstraintConflictReason reason
)
public function RecordConstraintConflictForItem (
    conflictingItemId : SyncId, 
    reason : ConstraintConflictReason
)

Parameter

  • conflictingItemId
    Die Element-ID des Zielelements, das mit der zu übernehmenden Änderung in Konflikt steht.
  • reason
    Der Grund für das Auftreten des Konflikts.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentNullException

conflictingItemId ist NULL.

SyncInvalidOperationException

Für dieses Objekt wurde bereits ein Einschränkungskonflikt oder ein behebbarer Fehler festgelegt.

Beispiel

Im folgenden Beispiel wird überprüft, ob ein neues Element im Elementspeicher erstellt werden kann. Wenn das Element nicht erstellt werden kann, wird ein Einschränkungskonflikt aufgezeichnet. Der Beispielcode stammt aus einer Implementierung von SaveChangeWithChangeUnits.

Case SaveChangeAction.Create
    If True Then
        ' Create a new item. Report a constraint conflict if one occurs.
        Try
            Dim constraintReason As ConstraintConflictReason
            Dim conflictingItemId As SyncId = Nothing
            ' Check if the item can be created or if it causes a constraint conflict.
            If _ContactStore.CanCreateContact(change, DirectCast(context.ChangeData, String()), constraintReason, conflictingItemId) Then
                ' No conflict, so create the item.
                _ContactStore.CreateContactFromSync(change, DirectCast(context.ChangeData, String()))
            Else
                ' A constraint conflict occurred, so report this to the change applier.
                context.RecordConstraintConflictForItem(conflictingItemId, constraintReason)
            End If
        Catch ex As Exception
            ' Some other error occurred, so exclude this item for the rest of the session.
            Dim errData As New RecoverableErrorData(ex)
            context.RecordRecoverableErrorForItem(errData)
        End Try
        Exit Select
    End If
case SaveChangeAction.Create:
{
    // Create a new item. Report a constraint conflict if one occurs.
    try
    {
        ConstraintConflictReason constraintReason;
        SyncId conflictingItemId;
        // Check if the item can be created or if it causes a constraint conflict.
        if (_ContactStore.CanCreateContact(change, (string[])context.ChangeData, out constraintReason, out conflictingItemId))
        {
            // No conflict, so create the item.
            _ContactStore.CreateContactFromSync(change, (string[])context.ChangeData);
        }
        else
        {
            // A constraint conflict occurred, so report this to the change applier.
            context.RecordConstraintConflictForItem(conflictingItemId, constraintReason);
        }
    }
    catch (Exception ex)
    {
        // Some other error occurred, so exclude this item for the rest of the session.
        RecoverableErrorData errData = new RecoverableErrorData(ex);
        context.RecordRecoverableErrorForItem(errData);
    }
    break;
}

Siehe auch

Verweis

SaveChangeContext-Klasse
SaveChangeContext-Member
Microsoft.Synchronization-Namespace