共用方式為


KnowledgeSyncProvider.ProcessChangeBatch 方法

在衍生類別中覆寫時,透過偵測衝突並將變更套用至項目存放區,處理一組變更。

命名空間: Microsoft.Synchronization
組件: Microsoft.Synchronization (在 microsoft.synchronization.dll)

語法

'宣告
Public MustOverride Sub ProcessChangeBatch ( _
    resolutionPolicy As ConflictResolutionPolicy, _
    sourceChanges As ChangeBatch, _
    changeDataRetriever As Object, _
    syncCallbacks As SyncCallbacks, _
    sessionStatistics As SyncSessionStatistics _
)
'用途
Dim instance As KnowledgeSyncProvider
Dim resolutionPolicy As ConflictResolutionPolicy
Dim sourceChanges As ChangeBatch
Dim changeDataRetriever As Object
Dim syncCallbacks As SyncCallbacks
Dim sessionStatistics As SyncSessionStatistics

instance.ProcessChangeBatch(resolutionPolicy, sourceChanges, changeDataRetriever, syncCallbacks, sessionStatistics)
public abstract void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy,
    ChangeBatch sourceChanges,
    Object changeDataRetriever,
    SyncCallbacks syncCallbacks,
    SyncSessionStatistics sessionStatistics
)
public:
virtual void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy, 
    ChangeBatch^ sourceChanges, 
    Object^ changeDataRetriever, 
    SyncCallbacks^ syncCallbacks, 
    SyncSessionStatistics^ sessionStatistics
) abstract
public abstract void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy, 
    ChangeBatch sourceChanges, 
    Object changeDataRetriever, 
    SyncCallbacks syncCallbacks, 
    SyncSessionStatistics sessionStatistics
)
public abstract function ProcessChangeBatch (
    resolutionPolicy : ConflictResolutionPolicy, 
    sourceChanges : ChangeBatch, 
    changeDataRetriever : Object, 
    syncCallbacks : SyncCallbacks, 
    sessionStatistics : SyncSessionStatistics
)

參數

  • resolutionPolicy
    當這個方法套用變更時要使用的衝突解決原則。
  • sourceChanges
    要在本機套用之來源提供者的變更批次。
  • changeDataRetriever
    可用來擷取變更資料的物件。它可以是 IChangeDataRetriever 物件或提供者特有的物件。
  • syncCallbacks
    在變更套用期間接收事件通知的物件。
  • sessionStatistics
    追蹤變更統計資料。若為使用自訂變更套用的提供者,就必須使用變更套用的結果來更新這個物件。

備註

當來源變更包含變更單位變更時,目的地提供者必須判斷哪些變更單位版本 (如果有的話) 要包含在傳送至變更套用者的目的地版本批次中。這項決定會取決於來源提供者的變更類型,以及項目是否在目的地複寫上標示為已刪除。如需詳細資訊,請參閱同步處理變更單位

範例

下列範例會取得變更批次中所有項目的目的地版本,並且建立 NotifyingChangeApplier 物件並用它來處理衝突偵測和變更套用。

public override void ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)
{
    // Use the metadata store to get the local versions of changes received from the source provider.
    IEnumerable<ItemChange> destVersions = _itemStore.ContactReplicaMetadata.GetLocalVersions(sourceChanges);

    // Use a NotifyingChangeApplier object to process the changes. Note that this object is passed as the INotifyingChangeApplierTarget
    // object that will be called to apply changes to the item store.
    NotifyingChangeApplier changeApplier = new NotifyingChangeApplier(IdFormats);
    changeApplier.ApplyChanges(resolutionPolicy, sourceChanges, (IChangeDataRetriever)changeDataRetriever, destVersions,
        _itemStore.ContactReplicaMetadata.GetKnowledge(), _itemStore.ContactReplicaMetadata.GetForgottenKnowledge(), 
        this, _sessionContext, syncCallbacks);
}

下列範例會顯示在上一則範例中呼叫的 GetLocalVersions 方法。這則範例會列舉來源變更批次中的變更,並且建立目的地版本的清單。

public override IEnumerable<ItemChange> GetLocalVersions(ChangeBatch sourceChanges)
{
    List<ItemChange> localVersions = new List<ItemChange>();

    // Enumerate the source changes and retrieve the destination version for each source change. 
    foreach (ItemChange srcItem in sourceChanges)
    {
        ItemChange localVer;

        // When the source item exists in the destination metadata store, retrieve the destination version of the item.
        if (_items.ContainsKey(srcItem.ItemId))
        {
            XmlItemMetadata localMeta = _items[srcItem.ItemId];
            ChangeKind kind = (localMeta.IsDeleted) ? ChangeKind.Deleted : ChangeKind.Update;
            localVer = new ItemChange(IdFormats, ReplicaId, srcItem.ItemId, kind, localMeta.CreationVersion, localMeta.ChangeVersion);
        }
        // When the source item does not exist in the destination metadata store, create a new change with unknown
        // version information.
        else
        {
            localVer = new ItemChange(IdFormats, ReplicaId, srcItem.ItemId, ChangeKind.UnknownItem, SyncVersion.UnknownVersion, SyncVersion.UnknownVersion);
        }

        localVersions.Add(localVer);
    }

    return localVersions;
}

請參閱

參考

KnowledgeSyncProvider 類別
KnowledgeSyncProvider 成員
Microsoft.Synchronization 命名空間