This topic has not yet been rated - Rate this topic

SimpleSyncProvider.UpdateItem Method

SQL Server 2008 R2

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)
public abstract void UpdateItem (
	Object itemData,
	IEnumerable<SyncId> changeUnitsToUpdate,
	ItemFieldDictionary keyAndExpectedVersion,
	RecoverableErrorReportingContext recoverableErrorReportingContext,
	out ItemFieldDictionary keyAndUpdatedVersion,
	out bool commitKnowledgeAfterThisItem
)
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.

Parameters

itemData

Data for the item in provider-specific format.

changeUnitsToUpdate

A SyncId object that contains the change units to update for an item. The parameter should be null (not empty) if no change units are specified.

keyAndExpectedVersion

The key and expected version properties of the item to be updated. The provider must perform an optimistic concurrency check to verify that the version of the item on the destination corresponds to the values found in keyAndExpectedVersion. If this check fails, provider should report a recoverable error by using a RecoverableErrorReportingContext object.

recoverableErrorReportingContext

A RecoverableErrorReportingContext object that is used to report recoverable errors that occur during attempts to update an item.

keyAndUpdatedVersion

Returns the key and updated version properties of the updated items. If the return value is not valid, the Sync Framework runtime throws ArgumentOutOfRangeException, which ends the session.

commitKnowledgeAfterThisItem

Returns whether the Sync Framework runtime should commit knowledge to the metadata store after processing is complete for the specified item.

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.

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;
}

Did you find this helpful?
(1500 characters remaining)