RecoverableErrorReportingContext.RecordConstraintError 方法
记录尝试对某项应用变更时出现的约束错误。用于描述处于与变更的约束冲突中的本地项。
命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)
语法
声明
Public Sub RecordConstraintError ( _
conflictingItemKey As ItemFieldDictionary _
)
用法
Dim instance As RecoverableErrorReportingContext
Dim conflictingItemKey As ItemFieldDictionary
instance.RecordConstraintError(conflictingItemKey)
public void RecordConstraintError (
ItemFieldDictionary conflictingItemKey
)
public:
void RecordConstraintError (
ItemFieldDictionary^ conflictingItemKey
)
public void RecordConstraintError (
ItemFieldDictionary conflictingItemKey
)
public function RecordConstraintError (
conflictingItemKey : ItemFieldDictionary
)
参数
- conflictingItemKey
要记录的约束错误的项的键。
异常
异常类型 | 条件 |
---|---|
由于出现约束冲突,提供程序推迟了正在应用的变更,直到下一个同步会话。 |
|
出现了多个约束错误,对于不再有效的对象报告了约束错误,或者约束错误策略不允许恢复约束错误。 |
备注
以后将在同步会话中重新应用或解决该变更。有关约束冲突的更多信息,请参见为简单提供程序处理冲突。
示例
下面的代码示例演示 InsertItem 方法的实现,该方法将插入应用于内存中的示例数据存储区。如果无法应用插入,则此方法记录一个约束错误。若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider"
应用程序(可从 Sync Framework SDK 和 Code Gallery 获得)。
public override void InsertItem(object itemData,
IEnumerable<SyncId> changeUnitsToCreate,
RecoverableErrorReportingContext recoverableErrorReportingContext,
out ItemFieldDictionary keyAndUpdatedVersion,
out bool commitKnowledgeAfterThisItem)
{
ItemTransfer transfer = (ItemTransfer)itemData;
ItemData dataCopy = new ItemData(transfer.ItemData);
// Check for duplicates, and record a constraint error if a duplicate is detected.
if (!_store.Contains(transfer.Id))
{
_store.CreateItem(dataCopy, transfer.Id);
keyAndUpdatedVersion = _store.CreateItemFieldDictionary(transfer.Id);
}
else
{
recoverableErrorReportingContext.RecordConstraintError(_store.CreateItemFieldDictionary(transfer.Id));
keyAndUpdatedVersion = null;
}
commitKnowledgeAfterThisItem = false;
}
Public Overrides Sub InsertItem(ByVal itemData As Object, ByVal changeUnitsToCreate As IEnumerable(Of SyncId), ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, ByRef keyAndUpdatedVersion As ItemFieldDictionary, ByRef commitKnowledgeAfterThisItem As Boolean)
Dim transfer As ItemTransfer = DirectCast(itemData, ItemTransfer)
Dim dataCopy As New ItemData(transfer.ItemData)
' Check for duplicates, and record a constraint error if a duplicate is detected.
If Not _store.Contains(transfer.Id) Then
_store.CreateItem(dataCopy, transfer.Id)
keyAndUpdatedVersion = _store.CreateItemFieldDictionary(transfer.Id)
Else
recoverableErrorReportingContext.RecordConstraintError(_store.CreateItemFieldDictionary(transfer.Id))
keyAndUpdatedVersion = Nothing
End If
commitKnowledgeAfterThisItem = False
End Sub
请参阅
参考
RecoverableErrorReportingContext 类
RecoverableErrorReportingContext 成员
Microsoft.Synchronization.SimpleProviders 命名空间