Delen via


ReplicaMetadata.GetFilteredChangeBatch Method

When overridden in a derived class, gets a change batch that contains item metadata for items that are not contained in the specified knowledge from the destination provider and that are accepted by the specified filter.

Namespace: Microsoft.Synchronization.MetadataStorage
Assembly: Microsoft.Synchronization.MetadataStorage (in microsoft.synchronization.metadatastorage.dll)

Syntax

'Declaration
Public MustOverride Function GetFilteredChangeBatch ( _
    batchSize As UInteger, _
    destinationKnowledge As SyncKnowledge, _
    filterInfo As FilterInfo, _
    filterCallback As ItemFilterCallback _
) As ChangeBatch
'Usage
Dim instance As ReplicaMetadata
Dim batchSize As UInteger
Dim destinationKnowledge As SyncKnowledge
Dim filterInfo As FilterInfo
Dim filterCallback As ItemFilterCallback
Dim returnValue As ChangeBatch

returnValue = instance.GetFilteredChangeBatch(batchSize, destinationKnowledge, filterInfo, filterCallback)
public abstract ChangeBatch GetFilteredChangeBatch (
    uint batchSize,
    SyncKnowledge destinationKnowledge,
    FilterInfo filterInfo,
    ItemFilterCallback filterCallback
)
public:
virtual ChangeBatch^ GetFilteredChangeBatch (
    unsigned int batchSize, 
    SyncKnowledge^ destinationKnowledge, 
    FilterInfo^ filterInfo, 
    ItemFilterCallback^ filterCallback
) abstract
public abstract ChangeBatch GetFilteredChangeBatch (
    UInt32 batchSize, 
    SyncKnowledge destinationKnowledge, 
    FilterInfo filterInfo, 
    ItemFilterCallback filterCallback
)
public abstract function GetFilteredChangeBatch (
    batchSize : uint, 
    destinationKnowledge : SyncKnowledge, 
    filterInfo : FilterInfo, 
    filterCallback : ItemFilterCallback
) : ChangeBatch

Parameters

  • batchSize
    The size of the batch to be created.
  • destinationKnowledge
    The knowledge from the destination provider.
  • filterInfo
    Information about the filter that controls which items are included in the change batch.
  • filterCallback
    The delegate that is called to determine whether the item should be added to the batch.

Return Value

A change batch that contains item metadata for items that are not contained in the specified knowledge from the destination provider and that are accepted by the specified filter.

Exceptions

Exception type Condition

ObjectDisposedException

The object has been disposed or was not initialized correctly.

ArgumentOutOfRangeException

batchSize is 0.

ArgumentNullException

destinationKnowledge is a null reference (Nothing in Visual Basic), or filterInfo is a null reference (Nothing in Visual Basic).

Remarks

This method helps a synchronization provider implement its GetChangeBatch method when a filtered synchronization has been specified.

The filterCallback delegate will be called before each item is added to a batch. If the delegate returns true, the item is added to the batch; otherwise, it is not added.

Before providers call this method, they must ensure that the versions in the metadata store reflect all local changes, including deletes. This is achieved through an explicit metadata maintenance pass to enumerate items and update their metadata.

The implementation of this class that is available through SqlMetadataStore adds changes to the change batch in global ID order.

The implementation of this class that is available through SqlMetadataStore sets IsLastBatch to true on the returned change batch when there are no more changes to send.

Notes to Implementers: To aid a provider that uses global ID ordering and has the ability to use ranges, changes should be enumerated and added to the change batch in global ID order. The first change in the returned change batch starts a new range. If there are no more changes to send after this batch, IsLastBatch must be set to true on the returned change batch, or Sync Framework will call GetChangeBatch again to retrieve another batch of changes.

Example

The following example creates an ItemListFilterInfo object and uses it, along with an implementation of ReplicaMetadata.ItemFilterCallback to retrieve a filtered change batch. The implementation of ReplicaMetadata.ItemFilterCallback is also included.

Public Overrides Function GetChangeBatch(ByVal batchSize As UInteger, ByVal destinationKnowledge As SyncKnowledge, ByRef changeDataRetriever As Object) As ChangeBatch
    ' Return this object as the IChangeDataRetriever object that is called to retrieve item data.
    changeDataRetriever = Me

    ' Use the metadata storage service to get a batch of changes.
    Dim retrievedBatch As ChangeBatch
    If _isFiltered Then
        ' If a filter is set, get a filtered change batch from the metadata storage service.
        ' The BirthdateFilterCallback method indicates whether an item passes the filter.
        Dim filterInfo As New ItemListFilterInfo(IdFormats)
        retrievedBatch = _ContactStore.ContactReplicaMetadata.GetFilteredChangeBatch(batchSize, destinationKnowledge, filterInfo, AddressOf BirthdateFilterCallback)
    Else
        retrievedBatch = _ContactStore.ContactReplicaMetadata.GetChangeBatch(batchSize, destinationKnowledge)
    End If

    Return retrievedBatch
End Function
Public Function BirthdateFilterCallback(ByVal itemMeta As ItemMetadata) As Boolean
    ' An item passes the filter only if its birthdate field is less than the maximum birthdate
    ' specified by the filter.
    Return (_ContactStore.ContactList(itemMeta.GlobalId).Birthdate < _maxBirthdateFilter)
End Function
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;

    // Use the metadata storage service to get a batch of changes.
    ChangeBatch retrievedBatch;
    if (_isFiltered)
    {
        // If a filter is set, get a filtered change batch from the metadata storage service.
        // The BirthdateFilterCallback method indicates whether an item passes the filter.
        ItemListFilterInfo filterInfo = new ItemListFilterInfo(IdFormats);
        retrievedBatch = _ContactStore.ContactReplicaMetadata.GetFilteredChangeBatch(batchSize, destinationKnowledge,
            filterInfo, BirthdateFilterCallback);
    }
    else
    {
        retrievedBatch = _ContactStore.ContactReplicaMetadata.GetChangeBatch(batchSize, destinationKnowledge);
    }

    return retrievedBatch;
}
public bool BirthdateFilterCallback(ItemMetadata itemMeta)
{
    // An item passes the filter only if its birthdate field is less than the maximum birthdate
    // specified by the filter.
    return (_ContactStore.ContactList[itemMeta.GlobalId].Birthdate < _maxBirthdateFilter);
}

See Also

Reference

ReplicaMetadata Class
ReplicaMetadata Members
Microsoft.Synchronization.MetadataStorage Namespace