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
)
參數
- itemData
型別:System. . :: . .Object
採用提供者特有之格式的項目資料。
- changeUnitsToUpdate
型別:System.Collections.Generic. . :: . .IEnumerable< (Of < ( <'SyncId> ) > ) >
包含要針對項目更新之變更單位的 SyncId 物件。如果沒有指定任何變更單位,此參數應該是 Null (非空白)。
- keyAndExpectedVersion
型別:Microsoft.Synchronization.SimpleProviders. . :: . .ItemFieldDictionary
要更新之項目的索引鍵和預期的版本屬性。提供者必須執行開放式並行存取檢查,以便驗證目的地的項目版本會對應至 keyAndExpectedVersion 中找到的值。如果這項檢查失敗,提供者應該使用 RecoverableErrorReportingContext 物件來報告可復原的錯誤。
- recoverableErrorReportingContext
型別:Microsoft.Synchronization.SimpleProviders. . :: . .RecoverableErrorReportingContext
用來報告嘗試更新項目期間所發生之可復原錯誤的 RecoverableErrorReportingContext 物件。
- keyAndUpdatedVersion
型別:Microsoft.Synchronization.SimpleProviders. . :: . .ItemFieldDictionary%
傳回更新之項目的索引鍵和更新的版本屬性。如果傳回值無效,Sync Framework 執行階段就會擲回 ArgumentOutOfRangeException,以便結束工作階段。
- 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 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