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 命名空间