ConstraintConflictReason 枚举

表示发生约束冲突的原因。

命名空间: Microsoft.Synchronization
程序集: Microsoft.Synchronization(在 microsoft.synchronization.dll 中)

语法

声明
Public Enumeration ConstraintConflictReason
用法
Dim instance As ConstraintConflictReason
public enum ConstraintConflictReason
public enum class ConstraintConflictReason
public enum ConstraintConflictReason
public enum ConstraintConflictReason

成员

  成员名称 说明
Collision 该项无法保存,原因是它与存储区中的其他项发生冲突,例如该项与现有项名称相同。提供程序必须将目标项的 ID 指定为冲突项 ID。 
Identity 对于某个项的标识,源副本和目标副本产生分歧。例如,副本 X 通过将 ID 为 id1 和 id2 的两个项合并,并将 id1 分配给合并后的项,从而解决了二者之间的抵触冲突。副本 Y 通过将 ID 分别为 id1 和 id2 的两个项中由 id1 标识的项进行重命名,并保留这两个项,从而解决了二者之间的抵触冲突。副本 X 发送由 id1 标识的合并项,以及一个指示 id2 已经合并入 id1 的合并删除逻辑。系统会检测到 id1 冲突,并作为并发冲突解决。系统检测到有关 id2 的冲突,并通过指定冲突原因 Identity,将该冲突作为标识冲突报告给同步应用程序。同步应用程序确定是通过保留源变更,还是保留目标变更来解决冲突。 
NoParent 该项无法保存到分层数据存储区中,原因是该项需要的父项在存储区中不存在。提供程序可以选择将缺失的父项的 ID 指定为冲突项 ID。 
Other 该项或变更单位违反了目标副本的某些其他约束。提供程序可以选择将发生冲突的项的 ID 指定为冲突项 ID。 

备注

目标提供程序在向变更应用方报告约束冲突时,使用 ConstraintConflictReason 的一个成员来指定约束冲突的原因。有关约束冲突的详细信息,请参阅检测和解决约束冲突

示例

下面的示例检测新创建的项是否引发约束冲突,如果引发冲突,则返回相应的约束冲突原因。

Public Function CanCreateContact(ByVal itemChange As ItemChange, ByVal changeData As String(), ByRef reason As ConstraintConflictReason, ByRef conflictingItemId As SyncId) As Boolean
    Dim canCreate As Boolean = True

    ' Create a temporary contact and see if its index values conflict with any item already in the contact store.
    Dim newContact As New Contact(changeData)
    canCreate = Not DetectIndexCollision(newContact, conflictingItemId)
    If Not canCreate Then
        ' An index collision occurred, so report a collision conflict.
        reason = ConstraintConflictReason.Collision
    Else
        ' This value won't be used because canCreate is set to true in this case.
        reason = ConstraintConflictReason.Other
    End If

    Return canCreate
End Function
public bool CanCreateContact(ItemChange itemChange, string[] changeData, out ConstraintConflictReason reason, out SyncId conflictingItemId)
{
    bool canCreate = true;

    // Create a temporary contact and see if its index values conflict with any item already in the contact store.
    Contact newContact = new Contact(changeData);
    canCreate = !DetectIndexCollision(newContact, out conflictingItemId);
    if (!canCreate)
    {
        // An index collision occurred, so report a collision conflict.
        reason = ConstraintConflictReason.Collision;
    }
    else
    {
        // This value won't be used because canCreate is set to true in this case.
        reason = ConstraintConflictReason.Other;
    }

    return canCreate;
}

请参阅

参考

Microsoft.Synchronization 命名空间