Share via


SimpleSyncProvider.UpdateItem メソッド

派生クラスでオーバーライドされると、同期先のストア内の項目を更新するために Sync Framework ランタイムによって呼び出されます。

名前空間: 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
public abstract void UpdateItem (
    Object itemData, 
    IEnumerable<SyncId> changeUnitsToUpdate, 
    ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    /** @attribute OutAttribute() */ /** @ref */ ItemFieldDictionary keyAndUpdatedVersion, 
    /** @attribute OutAttribute() */ /** @ref */ boolean commitKnowledgeAfterThisItem
)
JScript does not support passing value-type arguments by reference.

パラメーター

  • itemData
    プロバイダー固有形式の項目のデータ。
  • changeUnitsToUpdate
    項目に対して更新する変更単位を含む SyncId オブジェクト。変更単位を指定しない場合は、パラメーターを null (空ではない) に設定する必要があります。
  • keyAndExpectedVersion
    更新される項目のキー プロパティと想定されるバージョン プロパティ。プロバイダーはオプティミスティック同時実行制御チェックを実行して、同期先の項目のバージョンが keyAndExpectedVersion の値に対応していることを確認する必要があります。このチェックが失敗した場合、プロバイダーは、RecoverableErrorReportingContext オブジェクトを使用して、復旧可能なエラーを報告する必要があります。
  • recoverableErrorReportingContext
    項目を更新しようとしたときに発生した復旧可能なエラーを報告するための RecoverableErrorReportingContext オブジェクト。
  • keyAndUpdatedVersion
    更新された項目のキー プロパティと更新されたバージョン プロパティを返します。戻り値が有効でない場合、Sync Framework ランタイムは ArgumentOutOfRangeException をスローし、その結果、セッションが終了します。
  • commitKnowledgeAfterThisItem
    指定した項目に関する処理の完了後に Sync Framework ランタイムがナレッジをメタデータ ストアにコミットする必要があるかどうかを示す値を返します。

解説

同期元の変更を検出して読み込んだ後、Sync Framework は、これらの変更および対応するメタデータの変更を同期先のレプリカに適用する必要があります。同期先におけるメタデータの変更は Sync Framework によって処理されます。ただし、データの変更を適用することはストアに固有の処理であり、DeleteItem メソッド、InsertItem メソッド、および 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 名前空間