ReplicaMetadata.GetFilteredChangeBatch 方法
在派生类中重写时,获取包含某些项的项元数据的变更批,这些项为不包含在来自目标提供程序的指定知识中的项和指定的筛选器所接受的项。
命名空间: Microsoft.Synchronization.MetadataStorage
程序集: Microsoft.Synchronization.MetadataStorage(在 microsoft.synchronization.metadatastorage.dll 中)
语法
声明
Public MustOverride Function GetFilteredChangeBatch ( _
batchSize As UInteger, _
destinationKnowledge As SyncKnowledge, _
filterInfo As FilterInfo, _
filterCallback As ItemFilterCallback _
) As ChangeBatch
用法
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
参数
- batchSize
要创建的批的大小。
- destinationKnowledge
来自目标提供程序的知识。
- filterInfo
用于控制哪些项包含在变更批中的筛选器信息。
- filterCallback
为确定是否应将项添加到该批而调用的委托。
返回值
一个包含某些项的项元数据的变更批,这些项为不包含在来自目标提供程序的指定知识中的项和指定的筛选器所接受的项。
异常
异常类型 | 条件 |
---|---|
对象已释放或未正确初始化。 |
|
batchSize 为 0。 |
|
destinationKnowledge 为 null 引用(在 Visual Basic 中为 Nothing),或 filterInfo 为 null 引用(在 Visual Basic 中为 Nothing)。 |
备注
此方法可帮助同步提供程序在指定了筛选同步的情况下实现其 GetChangeBatch 方法。
在向批添加每一项之前将调用 filterCallback 委托。如果该委托返回 true,则该项将被添加到批;否则,不添加该项。
在提供程序调用此方法之前,它们必须确保元数据存储区中的版本反映了包括删除在内的所有本地变更。其实现方法为通过显式元数据维护传递来枚举项并更新其元数据。
可通过 SqlMetadataStore 获得的此类的实现按照全局 ID 的顺序将变更添加到变更批中。
可通过 SqlMetadataStore 获得的此类的实现在不再有变更要发送时,将返回的变更批的 IsLastBatch 设置为 true。
实施者注意事项: 若要帮助使用全局 ID 排序且能够使用范围的提供程序,则应枚举变更,并按照全局 ID 的顺序将变更添加到变更批中。返回的变更批中的第一个变更会开始一个新范围。 如果在此批之后再无变更要发送,则必须将返回的变更批的 IsLastBatch 设置为 true,否则 Sync Framework 将再次调用 GetChangeBatch 来检索另一个变更批。
示例
下面的示例创建 ItemListFilterInfo 对象,并使用它以及 ReplicaMetadata.ItemFilterCallback 的实现检索筛选的变更批。还包括 ReplicaMetadata.ItemFilterCallback 的实现。
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);
}
请参阅
参考
ReplicaMetadata 类
ReplicaMetadata 成员
Microsoft.Synchronization.MetadataStorage 命名空间