SimpleSyncProvider.DeleteItem 方法
在派生类中重写时,由 Sync Framework 运行时调用以便从目标存储区中删除某一项。
命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)
语法
声明
Public MustOverride Sub DeleteItem ( _
keyAndExpectedVersion As ItemFieldDictionary, _
recoverableErrorReportingContext As RecoverableErrorReportingContext, _
<OutAttribute> ByRef commitKnowledgeAfterThisItem As Boolean _
)
用法
Dim instance As SimpleSyncProvider
Dim keyAndExpectedVersion As ItemFieldDictionary
Dim recoverableErrorReportingContext As RecoverableErrorReportingContext
Dim commitKnowledgeAfterThisItem As Boolean
instance.DeleteItem(keyAndExpectedVersion, recoverableErrorReportingContext, commitKnowledgeAfterThisItem)
public abstract void DeleteItem (
ItemFieldDictionary keyAndExpectedVersion,
RecoverableErrorReportingContext recoverableErrorReportingContext,
out bool commitKnowledgeAfterThisItem
)
public:
virtual void DeleteItem (
ItemFieldDictionary^ keyAndExpectedVersion,
RecoverableErrorReportingContext^ recoverableErrorReportingContext,
[OutAttribute] bool% commitKnowledgeAfterThisItem
) abstract
public abstract void DeleteItem (
ItemFieldDictionary keyAndExpectedVersion,
RecoverableErrorReportingContext recoverableErrorReportingContext,
/** @attribute OutAttribute() */ /** @ref */ boolean commitKnowledgeAfterThisItem
)
JScript does not support passing value-type arguments by reference.
参数
- keyAndExpectedVersion
要删除的项的键和预期版本属性。提供程序必须执行开放式并发检查,以便确认目标上的项的版本是否与 keyAndExpectedVersion 中找到的值相对应。如果此检查失败,提供程序应通过使用 RecoverableErrorReportingContext 对象报告一个可恢复错误。
- recoverableErrorReportingContext
一个 RecoverableErrorReportingContext 对象,该对象用于报告在尝试删除某一项期间发生的可恢复错误。
- commitKnowledgeAfterThisItem
返回在完成了对指定项的处理后 Sync Framework 运行时是否应将知识提交到元数据存储区。
备注
在 Sync Framework 检测到并加载了来自源的变更后,它必须将这些变更和相应的元数据变更应用于目标副本。位于目标的元数据变更由 Sync Framework 处理,但应用数据变更是特定于存储区的,应通过实现以下方法来处理:DeleteItem、InsertItem 和 UpdateItem。
示例
下面的代码示例演示此方法的实现,该方法将删除应用于内存中的示例数据存储区。若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider"
应用程序(可从 Sync Framework SDK 和 Code Gallery 获得)。
public override void DeleteItem(ItemFieldDictionary keyAndExpectedVersion,
RecoverableErrorReportingContext recoverableErrorReportingContext,
out bool commitKnowledgeAfterThisItem)
{
IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion;
ulong id = (ulong)expectedFields[CUSTOM_FIELD_ID].Value;
if (_store.Contains(id))
{
_store.DeleteItem(id);
}
else
{
// If the item to delete does not exist, record an error on this change and
// continue with the rest of the session.
recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(new Exception("Item not found in the store")));
}
commitKnowledgeAfterThisItem = false;
}
Public Overrides Sub DeleteItem(ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, ByRef commitKnowledgeAfterThisItem As Boolean)
Dim expectedFields As IDictionary(Of UInteger, ItemField) = DirectCast(keyAndExpectedVersion, IDictionary(Of UInteger, ItemField))
Dim id As ULong = CULng(expectedFields(CUSTOM_FIELD_ID).Value)
If _store.Contains(id) Then
_store.DeleteItem(id)
Else
' If the item to delete does not exist, record an error on this change and
' continue with the rest of the session.
recoverableErrorReportingContext.RecordRecoverableErrorForChange(New RecoverableErrorData(New Exception("Item not found in the store")))
End If
commitKnowledgeAfterThisItem = False
End Sub
请参阅
参考
SimpleSyncProvider 类
SimpleSyncProvider 成员
Microsoft.Synchronization.SimpleProviders 命名空间