次の方法で共有


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 メソッドを実装することによって行います。

次のコード例では、メモリ内のサンプル データ ストアに削除を適用するこのメソッドの実装を示します。完全なアプリケーションのコンテキストでこのコードを表示するには、Sync Framework SDK やCode Galleryから入手できる "Sync101 using Simple Sync Provider" アプリケーションを参照してください。

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