Condividi tramite


Metodo SimpleSyncProvider.UpdateItem

Quando sottoposto a override in una classe derivata, viene chiamato dal runtime di Sync Framework per aggiornare un elemento nell'archivio di destinazione.

Spazio dei nomi: Microsoft.Synchronization.SimpleProviders
Assembly: Microsoft.Synchronization.SimpleProviders (in microsoft.synchronization.simpleproviders.dll)

Sintassi

'Dichiarazione
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 _
)
'Utilizzo
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.

Parametri

  • itemData
    Dati per l'elemento nel formato specifico del provider.
  • changeUnitsToUpdate
    Oggetto SyncId contenente le unità di modifica da aggiornare per un elemento. Il parametro deve essere Null (non vuoto) se non viene specificata alcuna unità di modifica.
  • keyAndExpectedVersion
    Proprietà della chiave e della versione prevista dell'elemento da aggiornare. Il provider deve eseguire un controllo della concorrenza ottimistica per verificare che la versione dell'elemento nella destinazione corrisponda ai valori trovati in keyAndExpectedVersion. Se questo controllo ha esito negativo, il provider deve segnalare un errore reversibile tramite un oggetto RecoverableErrorReportingContext.
  • recoverableErrorReportingContext
    Oggetto RecoverableErrorReportingContext utilizzato per segnalare errori reversibili che si verificano durante i tentativi di caricare un elemento.
  • keyAndUpdatedVersion
    Restituisce le proprietà della chiave e della versione aggiornata degli elementi aggiornati. Se il valore restituito non è valido, il runtime di Sync Framework genera ArgumentOutOfRangeException che termina la sessione.
  • commitKnowledgeAfterThisItem
    Restituisce un valore che indica se il runtime di Sync Framework deve eseguire il commit della conoscenza nell'archivio dei metadati dopo che è stata completata l'elaborazione dell'elemento specificato.

Osservazioni

Dopo che in Sync Framework sono state rilevate e caricate le modifiche dalla replica di origine, tali modifiche e le modifiche ai metadati corrispondenti devono essere applicate alla replica di destinazione. Le modifiche ai metadati nella destinazione vengono gestite da Sync Framework, ma l'applicazione delle modifiche ai dati è un'attività specifica dell'archivio e viene gestita implementando i metodi seguenti: DeleteItem, InsertItem e UpdateItem.

Esempio

Nell'esempio di codice seguente viene illustrata un'implementazione di questo metodo che applica aggiornamenti a un archivio dati di esempio in memoria. ItemTransfer è un meccanismo di trasferimento semplice utilizzato quando le modifiche vengono caricate dall'origine e applicate alla destinazione. Per visualizzare il codice nel contesto di un'applicazione completa, vedere l'applicazione "Sync101 using Simple Sync Provider" disponibile in Sync Framework SDK e in 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

Vedere anche

Riferimento

Classe SimpleSyncProvider
Membri SimpleSyncProvider
Spazio dei nomi Microsoft.Synchronization.SimpleProviders