SimpleSyncProvider.InsertItem 方法
在派生类中重写时,由 Sync Framework 运行时调用以便将某一项插入目标存储区中。
命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)
语法
声明
Public MustOverride Sub InsertItem ( _
itemData As Object, _
changeUnitsToCreate As IEnumerable(Of SyncId), _
recoverableErrorReportingContext As RecoverableErrorReportingContext, _
<OutAttribute> ByRef keyAndUpdatedVersion As ItemFieldDictionary, _
<OutAttribute> ByRef commitKnowledgeAfterThisItem As Boolean _
)
用法
Dim instance As SimpleSyncProvider
Dim itemData As Object
Dim changeUnitsToCreate As IEnumerable(Of SyncId)
Dim recoverableErrorReportingContext As RecoverableErrorReportingContext
Dim keyAndUpdatedVersion As ItemFieldDictionary
Dim commitKnowledgeAfterThisItem As Boolean
instance.InsertItem(itemData, changeUnitsToCreate, recoverableErrorReportingContext, keyAndUpdatedVersion, commitKnowledgeAfterThisItem)
public abstract void InsertItem (
Object itemData,
IEnumerable<SyncId> changeUnitsToCreate,
RecoverableErrorReportingContext recoverableErrorReportingContext,
out ItemFieldDictionary keyAndUpdatedVersion,
out bool commitKnowledgeAfterThisItem
)
public:
virtual void InsertItem (
Object^ itemData,
IEnumerable<SyncId^>^ changeUnitsToCreate,
RecoverableErrorReportingContext^ recoverableErrorReportingContext,
[OutAttribute] ItemFieldDictionary^% keyAndUpdatedVersion,
[OutAttribute] bool% commitKnowledgeAfterThisItem
) abstract
public abstract void InsertItem (
Object itemData,
IEnumerable<SyncId> changeUnitsToCreate,
RecoverableErrorReportingContext recoverableErrorReportingContext,
/** @attribute OutAttribute() */ /** @ref */ ItemFieldDictionary keyAndUpdatedVersion,
/** @attribute OutAttribute() */ /** @ref */ boolean commitKnowledgeAfterThisItem
)
JScript does not support passing value-type arguments by reference.
参数
- itemData
特定于提供程序的格式的项数据。
- changeUnitsToCreate
一个包含要为某一项插入的变更单位的 SyncId 对象。如果未指定任何变更单位,该参数应为 Null(非空)。
- recoverableErrorReportingContext
一个 RecoverableErrorReportingContext 对象,该对象用于报告在尝试插入某一项期间发生的可恢复错误。
- keyAndUpdatedVersion
返回要插入的项的键和更新的版本属性。如果返回值无效,则 Sync Framework 运行时将引发 ArgumentOutOfRangeException,这将结束该会话。
- commitKnowledgeAfterThisItem
返回在完成了对指定项的处理后 Sync Framework 运行时是否应将知识提交到元数据存储区。
备注
在 Sync Framework 检测到并加载了来自源的变更后,它必须将这些变更和相应的元数据变更应用于目标副本。位于目标的元数据变更由 Sync Framework 处理,但应用数据变更是特定于存储区的,应通过实现以下方法来处理:DeleteItem、InsertItem 和 UpdateItem。
示例
下面的代码示例演示此方法的实现,该方法将插入应用于内存中的示例数据存储区。ItemTransfer
是一种简单的传输机制,当从源加载变更和将变更应用于目标时使用。若要在完整应用程序的上下文中查看此代码,请参见"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
请参阅
参考
SimpleSyncProvider 类
SimpleSyncProvider 成员
Microsoft.Synchronization.SimpleProviders 命名空间