共用方式為


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
abstract InsertItem : 
        itemData:Object * 
        changeUnitsToCreate:IEnumerable<SyncId> * 
        recoverableErrorReportingContext:RecoverableErrorReportingContext * 
        keyAndUpdatedVersion:ItemFieldDictionary byref * 
        commitKnowledgeAfterThisItem:bool byref -> unit 
public abstract function InsertItem(
    itemData : Object, 
    changeUnitsToCreate : IEnumerable<SyncId>, 
    recoverableErrorReportingContext : RecoverableErrorReportingContext, 
    keyAndUpdatedVersion : ItemFieldDictionary, 
    commitKnowledgeAfterThisItem : boolean
)

參數

  • commitKnowledgeAfterThisItem
    型別:System. . :: . .Boolean%
    傳回 Sync Framework 執行階段是否應該在指定之項目的處理完成之後,將知識認可至中繼資料存放區。

備註

在 Sync Framework 偵測到來源中的變更並加以載入後,它必須將這些變更和對應的中繼資料變更套用到目的地複寫。目的地的中繼資料變更是由 Sync Framework 所處理,但是套用資料變更是存放區特定的動作,而且會藉由實作下列方法:DeleteItem、InsertItem 和 UpdateItem 來加以處理。

範例

下列程式碼範例示範這個方法的實作,此方法會將插入套用到記憶體中的範例資料存放區。ItemTransfer 是一種簡單的傳輸機制,使用於從來源載入變更及將變更套用到目的地的情況。若要在完整應用程式的內容中檢視這段程式碼,請參閱 Sync Framework SDK 及 Code Gallery 中的 "Sync101 using Simple Sync Provider" 應用程式。

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 命名空間