1

我已经实现了一个FullEnumerationSimpleSyncProvider似乎没有处理冲突的方法。

在构造函数中,我设置了以下属性:

this.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.ApplicationDefined;
this.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.ApplicationDefined;

this.ItemConstraint += new EventHandler<SimpleSyncItemConstraintEventArgs>(OnItemConstraint);
this.ItemConflicting += new EventHandler<SimpleSyncItemConflictingEventArgs>(OnItemConflicting);

我的约束和冲突事件处理程序:

void OnItemConstraint(object sender, SimpleSyncItemConstraintEventArgs e)
{
    e.SetResolutionAction(ConstraintConflictResolutionAction.Merge);
}

void OnItemConflicting(object sender, SimpleSyncItemConflictingEventArgs e)
{
    e.SetResolutionAction(ConflictResolutionAction.Merge);
}

但是,当我在 InsertItem() 中报告冲突时,永远不会调用约束/冲突事件处理程序。

public override void InsertItem(
        object itemData, 
        IEnumerable<SyncId> changeUnitsToCreate, 
        RecoverableErrorReportingContext recoverableErrorReportingContext, 
        out ItemFieldDictionary keyAndUpdatedVersion, 
        out bool commitKnowledgeAfterThisItem) {

            // ...snip...

            // Check if it is already there --- name collision
            if (itemAlreadyExists)
            {
                recoverableErrorReportingContext.RecordConstraintError(ConstructDictionary(item.ID));
                keyAndUpdatedVersion = null;
                commitKnowledgeAfterThisItem = false;

                return;
            }

            // ...snip...
}

我想在调用同步框架时会在退出RecordConstraintError后调用适当的事件处理程序。InsertItem

任何见解将不胜感激!

4

1 回答 1

0

如果您正在处理并发冲突并将 SetResolutionAction 设置为 ConflictResolutionAction.Merge,那么您的提供程序需要实现 ISimpleSyncProviderConcurrencyConflictResolver 接口(ResolveUpdateUpdateConflict、ResolveLocalDeleteRemoteUpdateConflict 和 ResolveLocalUpdateRemoteDeleteConflict。)

如果您正在处理约束冲突并将 ConstraintConflictResolutionAction 设置为 Merge、RenameDestination 或 RenameSource,那么您的提供者需要实现 ISimpleSyncProviderConstraintConflictResolver 接口。

Microsoft Sync Framework 简单提供程序 - 并发冲突处理

于 2012-04-14T02:58:43.537 回答