共用方式為


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
abstract GetChangeBatch : 
        batchSize:uint32 * 
        destinationKnowledge:SyncKnowledge * 
        changeDataRetriever:Object byref -> ChangeBatch 
public abstract function GetChangeBatch(
    batchSize : uint, 
    destinationKnowledge : SyncKnowledge, 
    changeDataRetriever : Object
) : ChangeBatch

參數

傳回值

型別:Microsoft.Synchronization. . :: . .ChangeBatch
變更批次,其中包含目的地提供者之指定知識內未包含之項目的項目中繼資料。不能為 nullNothingnullptrunitnull 參考 (在 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 命名空間