SimpleSyncProvider.UpdateItem Method

When overridden in a derived class, called by the Sync Framework runtime to update an item in the destination store.

Namespace:  Microsoft.Synchronization.SimpleProviders
Assembly:  Microsoft.Synchronization.SimpleProviders (in Microsoft.Synchronization.SimpleProviders.dll)

Syntax

'Declaration
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 _
)
'Usage
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
)

Parameters

  • itemData
    Type: System.Object
    Data for the item in provider-specific format.
  • commitKnowledgeAfterThisItem
    Type: System.Boolean%
    Returns whether the Sync Framework runtime should commit knowledge to the metadata store after processing is complete for the specified item.

Remarks

After Sync Framework has detected and loaded changes from the source, it must apply those changes and corresponding metadata changes to the destination replica. Metadata changes at the destination are handled by Sync Framework, but applying data changes is store-specific and is handled by implementing the following methods: DeleteItem, InsertItem, and UpdateItem.

Examples

The following code example shows an implementation of this method that applies updates to an in-memory sample data store. ItemTransfer is a simple transfer mechanism that is used when changes are loaded from the source and applied to the destination. To view this code in the context of a complete application, see the "Sync101 using Simple Sync Provider" application that is available in the Sync Framework SDK and from Code Gallery.

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

See Also

Reference

SimpleSyncProvider Class

Microsoft.Synchronization.SimpleProviders Namespace