Partager via


GetChangeBatch méthode

En cas de substitution dans une classe dérivée, obtient un lot de modifications qui contient les métadonnées d'élément pour les éléments qui ne sont pas contenus dans la connaissance spécifiée du fournisseur de destination.

Espace de noms :  Microsoft.Synchronization
Assembly :  Microsoft.Synchronization (dans Microsoft.Synchronization.dll)

Syntaxe

'Déclaration
Public MustOverride Function GetChangeBatch ( _
    batchSize As UInteger, _
    destinationKnowledge As SyncKnowledge, _
    <OutAttribute> ByRef changeDataRetriever As Object _
) As ChangeBatch
'Utilisation
Dim instance As KnowledgeSyncProvider
Dim batchSize As UInteger
Dim destinationKnowledge As SyncKnowledge
Dim changeDataRetriever As Object
Dim returnValue As ChangeBatch

returnValue = instance.GetChangeBatch(batchSize, _
    destinationKnowledge, changeDataRetriever)
public abstract ChangeBatch GetChangeBatch(
    uint batchSize,
    SyncKnowledge destinationKnowledge,
    out Object changeDataRetriever
)
public:
virtual ChangeBatch^ GetChangeBatch(
    unsigned int batchSize, 
    SyncKnowledge^ destinationKnowledge, 
    [OutAttribute] Object^% changeDataRetriever
) abstract
abstract GetChangeBatch : 
        batchSize:uint32 * 
        destinationKnowledge:SyncKnowledge * 
        changeDataRetriever:Object byref -> ChangeBatch 
public abstract function GetChangeBatch(
    batchSize : uint, 
    destinationKnowledge : SyncKnowledge, 
    changeDataRetriever : Object
) : ChangeBatch

Paramètres

  • changeDataRetriever
    Type : System. . :: . .Object%
    Retourne un objet qui peut être utilisé pour récupérer des données de modification. Il peut s'agir d'un objet IChangeDataRetriever ou d'un objet spécifique au fournisseur.

Valeur de retour

Type : Microsoft.Synchronization. . :: . .ChangeBatch
Lot de modifications qui contient les métadonnées d'élément pour les éléments qui ne sont pas contenus dans la connaissance spécifiée du fournisseur de destination. Ne peut pas être une valeur Null.

Notes

La même modification n'apparaîtra pas dans plusieurs lots.

S'il reste moins de modifications que le nombre spécifié par batchSize, un lot plus petit sera retourné.

Si cette méthode est appelée alors qu'il ne reste aucune modification, InvalidOperationException est levée.

Remarques à l'attention des implémenteurs

S'il n'y a plus de modifications à envoyer après ce lot, vous devez affecter à la propriété IsLastBatch la valeur True sur le lot de modifications retourné. Sinon, Sync Framework appelle de nouveau la méthode GetChangeBatch pour récupérer un autre lot de modifications.

Exemples

L'exemple suivant obtient un lot de modifications du magasin des métadonnées.

public override ChangeBatch GetChangeBatch(uint batchSize, SyncKnowledge destinationKnowledge, out object changeDataRetriever)
{
    // Return this object as the IChangeDataRetriever object that is called to retrieve item data.
    changeDataRetriever = this;

    // Call the metadata store to get a batch of changes.
    return _itemStore.ContactReplicaMetadata.GetChangeBatch(batchSize, destinationKnowledge);
}

L'exemple suivant affiche la méthode GetChangeBatch qui est appelée dans l'exemple précédent. Cet exemple crée un objet ChangeBatch et démarre un groupe ordonné. Il ajoute un élément au groupe ordonné lorsque l'élément n'est pas contenu dans la connaissance de destination.

public override ChangeBatch GetChangeBatch(uint batchSize, SyncKnowledge destinationKnowledge)
{
    // The destination knowledge must be converted to be compatible with the source replica
    // before it can be used.
    SyncKnowledge mappedDestKnowledge = _knowledge.MapRemoteKnowledgeToLocal(destinationKnowledge);

    // Create a new change batch, initialized by using the current knowledge of the source replica
    // and a new ForgottenKnowledge object.
    ChangeBatch changeBatch = new ChangeBatch(IdFormats, GetKnowledge(), new ForgottenKnowledge());

    // Start a group of changes in the change batch. The group is ordered by item ID.
    // _getChangeBatchCurrent is 0 the first time GetChangeBatch is called, and is used to track the
    // position in the metadata store for subsequent calls to GetChangeBatch.
    changeBatch.BeginOrderedGroup(_items.Values[_getChangeBatchCurrent].GlobalId);

    // itemsAdded is incremented each time a change is added to the change batch. When itemsAdded
    // is greater than the requested batch size, enumeration stops and the change batch is returned.
    int itemsAdded = 0;

    ItemMetadata itemMeta;

    // Enumerate items and add a change to the change batch if it is not contained in the 
    // destination knowledge.
    // _items is a SortedList that contains ItemMetadata objects that are ordered by item ID.
    for (; itemsAdded <= batchSize && _getChangeBatchCurrent < _items.Count; _getChangeBatchCurrent++)
    {
        itemMeta = _items.Values[_getChangeBatchCurrent];
        ChangeKind kind = (itemMeta.IsDeleted) ? ChangeKind.Deleted : ChangeKind.Update;
        ItemChange change = new ItemChange(IdFormats, ReplicaId, itemMeta.GlobalId, kind, itemMeta.CreationVersion, 
            itemMeta.ChangeVersion);

        // If the change is not contained in the destination knowledge, add it to the change batch.
        if (!mappedDestKnowledge.Contains(change))
        {
            changeBatch.AddChange(change);
            itemsAdded++;
        }
    }

    // End the group of changes in the change batch. Pass the current source knowledge.
    changeBatch.EndOrderedGroup(_items.Values[_getChangeBatchCurrent - 1].GlobalId, _knowledge);

    // When all items in the metadata store have been enumerated, set this batch as the
    // last batch.
    if (_getChangeBatchCurrent == _items.Count)
    {
        changeBatch.SetLastBatch();
    }

    return changeBatch;
}

Voir aussi

Référence

KnowledgeSyncProvider Classe

Membres KnowledgeSyncProvider

Espace de noms Microsoft.Synchronization