共用方式為


UpdateItem 方法

命名空間:  Microsoft.Synchronization.SimpleProviders
組件:  Microsoft.Synchronization.SimpleProviders (在 Microsoft.Synchronization.SimpleProviders.dll 中)

語法

'宣告
Public MustOverride Sub UpdateItem ( _
    itemData As Object, _
    changeUnitsToUpdate As IEnumerable(Of SyncId), _
    keyAndExpectedVersion As ItemFieldDictionary, _
    recoverableErrorReportingContext As RecoverableErrorReportingContext, _
    <OutAttribute> ByRef keyAndUpdatedVersion As ItemFieldDictionary, _
    <OutAttribute> ByRef commitKnowledgeAfterThisItem As Boolean _
)
'用途
Dim instance As SimpleSyncProvider
Dim itemData As Object
Dim changeUnitsToUpdate As IEnumerable(Of SyncId)
Dim keyAndExpectedVersion As ItemFieldDictionary
Dim recoverableErrorReportingContext As RecoverableErrorReportingContext
Dim keyAndUpdatedVersion As ItemFieldDictionary
Dim commitKnowledgeAfterThisItem As Boolean

instance.UpdateItem(itemData, changeUnitsToUpdate, _
    keyAndExpectedVersion, recoverableErrorReportingContext, _
    keyAndUpdatedVersion, commitKnowledgeAfterThisItem)
public abstract void UpdateItem(
    Object itemData,
    IEnumerable<SyncId> changeUnitsToUpdate,
    ItemFieldDictionary keyAndExpectedVersion,
    RecoverableErrorReportingContext recoverableErrorReportingContext,
    out ItemFieldDictionary keyAndUpdatedVersion,
    out bool commitKnowledgeAfterThisItem
)
public:
virtual void UpdateItem(
    Object^ itemData, 
    IEnumerable<SyncId^>^ changeUnitsToUpdate, 
    ItemFieldDictionary^ keyAndExpectedVersion, 
    RecoverableErrorReportingContext^ recoverableErrorReportingContext, 
    [OutAttribute] ItemFieldDictionary^% keyAndUpdatedVersion, 
    [OutAttribute] bool% commitKnowledgeAfterThisItem
) abstract
abstract UpdateItem : 
        itemData:Object * 
        changeUnitsToUpdate:IEnumerable<SyncId> * 
        keyAndExpectedVersion:ItemFieldDictionary * 
        recoverableErrorReportingContext:RecoverableErrorReportingContext * 
        keyAndUpdatedVersion:ItemFieldDictionary byref * 
        commitKnowledgeAfterThisItem:bool byref -> unit 
public abstract function UpdateItem(
    itemData : Object, 
    changeUnitsToUpdate : IEnumerable<SyncId>, 
    keyAndExpectedVersion : ItemFieldDictionary, 
    recoverableErrorReportingContext : RecoverableErrorReportingContext, 
    keyAndUpdatedVersion : ItemFieldDictionary, 
    commitKnowledgeAfterThisItem : boolean
)

參數

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

備註

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

範例

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

public override void UpdateItem(object itemData, 
    IEnumerable<SyncId> changeUnitsToUpdate, 
    ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out ItemFieldDictionary keyAndUpdatedVersion, 
    out bool commitKnowledgeAfterThisItem)
{
    ItemTransfer transfer = (ItemTransfer)itemData;
    ItemData dataCopy = new ItemData(transfer.ItemData);

    IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion;
    ulong idToUpdate = (ulong)expectedFields[CUSTOM_FIELD_ID].Value;

    if (_store.Contains(idToUpdate))
    {
        ulong timeStamp = _store.UpdateItem(idToUpdate, dataCopy);
        keyAndUpdatedVersion = _store.CreateItemFieldDictionary(transfer.Id);
    }
    else
    {
        // If the item to update 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")));
        keyAndUpdatedVersion = null;
    }
    commitKnowledgeAfterThisItem = false;
}
Public Overrides Sub UpdateItem(ByVal itemData As Object, ByVal changeUnitsToUpdate As IEnumerable(Of SyncId), ByVal keyAndExpectedVersion As ItemFieldDictionary, 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)

    Dim expectedFields As IDictionary(Of UInteger, ItemField) = DirectCast(keyAndExpectedVersion, IDictionary(Of UInteger, ItemField))
    Dim idToUpdate As ULong = CULng(expectedFields(CUSTOM_FIELD_ID).Value)

    If _store.Contains(idToUpdate) Then
        Dim timeStamp As ULong = _store.UpdateItem(idToUpdate, dataCopy)
        keyAndUpdatedVersion = _store.CreateItemFieldDictionary(transfer.Id)
    Else
        ' If the item to update 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")))
        keyAndUpdatedVersion = Nothing
    End If
    commitKnowledgeAfterThisItem = False
End Sub

請參閱

參考

SimpleSyncProvider類別

SimpleSyncProvider 成員

Microsoft.Synchronization.SimpleProviders 命名空間