KnowledgeSyncProvider.GetChangeBatch 方法
在派生类中重写时,获取包含某些项的项元数据的变更批,这些项不包含在来自目标提供程序的指定知识中。
命名空间: Microsoft.Synchronization
程序集: Microsoft.Synchronization(在 microsoft.synchronization.dll 中)
语法
声明
Public MustOverride Function GetChangeBatch ( _
batchSize As UInteger, _
destinationKnowledge As SyncKnowledge, _
<OutAttribute> ByRef changeDataRetriever As Object _
) As ChangeBatch
用法
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
public abstract ChangeBatch GetChangeBatch (
UInt32 batchSize,
SyncKnowledge destinationKnowledge,
/** @attribute OutAttribute() */ /** @ref */ Object changeDataRetriever
)
JScript does not support passing value-type arguments by reference.
参数
- batchSize
要包含在变更批中的变更数。
- destinationKnowledge
来自目标提供程序的知识。此知识必须先通过调用源知识中的 MapRemoteKnowledgeToLocal 进行映射,然后才能用于变更枚举。
- changeDataRetriever
返回一个可用于检索变更数据的对象。可以是 IChangeDataRetriever 对象,也可以是提供程序特定的对象。
返回值
包含某些项的项元数据的变更批,这些项不包含在来自目标提供程序的指定知识中。不能是 null 引用(在 Visual Basic 中为 Nothing)。
备注
相同的变更不会出现在多个批中。
如果剩余的变更数小于 batchSize 指定的变更数,则返回较小的批。
如果在已无变更的情况下调用此方法,则引发 InvalidOperationException。
实施者注意事项: 如果在此批之后再无变更要发送,则必须将返回的变更批的 IsLastBatch 设置为 true。否则,Sync Framework 将再次调用 GetChangeBatch 来检索另一个变更批。
示例
以下示例从元数据存储区中获取变更批。
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);
}
以下示例说明上一个示例中调用的 GetChangeBatch
方法。此示例创建一个 ChangeBatch 对象并启动一个有序组。当某一项不包含在目标知识中时,此示例会将该项添加到有序组。
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;
}
请参阅
参考
KnowledgeSyncProvider 类
KnowledgeSyncProvider 成员
Microsoft.Synchronization 命名空间