共用方式為


ISimpleSyncProviderConcurrencyConflictResolver 介面

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

語法

'宣告
Public Interface ISimpleSyncProviderConcurrencyConflictResolver
'用途
Dim instance As ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver
public interface class ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver
public interface ISimpleSyncProviderConcurrencyConflictResolver

備註

如需有關並行衝突的詳細資訊,請參閱處理簡單提供者的衝突

範例

在此範例中,並行衝突和條件約束衝突的衝突處理原則會保留為 ApplicationDefined 的預設值。這表示,應用程式將會註冊 ItemConflictingItemConstraint 事件,並指定動作來解決同步處理期間發生的衝突。如需詳細資訊,請參閱處理簡單提供者的衝突。若要在完整應用程式的內容中檢視這段程式碼,請參閱 Sync Framework SDK 及 Code Gallery 中的 "Sync101 using Simple Sync Provider" 應用程式。下列程式碼範例示範在 MyFullEnumerationSimpleSyncProvider 的建構函式中指定的事件處理常式。

this.ItemConstraint += new EventHandler<SimpleSyncItemConstraintEventArgs>(OnItemConstraint);
this.ItemConflicting += new EventHandler<SimpleSyncItemConflictingEventArgs>(OnItemConflicting);
AddHandler Me.ItemConstraint, AddressOf HandleItemConstraint

下列程式碼範例示範事件處理常式如何將衝突解決動作設定為 Merge

void OnItemConstraint(object sender, SimpleSyncItemConstraintEventArgs e)
{
    // Set the resolution action for constraint conflicts.
    // In this sample, the provider checks for duplicates in InsertItem, and this event would
    // fire if a duplicate occurred. 
    e.SetResolutionAction(ConstraintConflictResolutionAction.Merge);
}

void OnItemConflicting(object sender, SimpleSyncItemConflictingEventArgs e)
{
    // Set the resolution action for concurrency conflicts.
    e.SetResolutionAction(ConflictResolutionAction.Merge);
}
Private Sub HandleItemConstraint(ByVal sender As Object, ByVal e As SimpleSyncItemConstraintEventArgs)
    ' Set the resolution action for constraint conflicts. 
    ' In this sample, the provider checks for duplicates in InsertItem, and this event would 
    ' fire if a duplicate occurred. 
    e.SetResolutionAction(ConstraintConflictResolutionAction.Merge)
End Sub

Private Sub HandleItemConflicting(ByVal sender As Object, ByVal e As SimpleSyncItemConflictingEventArgs)
    ' Set the resolution action for concurrency conflicts. 
    e.SetResolutionAction(ConflictResolutionAction.Merge)
End Sub

下列程式碼範例會示範所實作的 ResolveUpdateUpdateConflict 方法,以回應並行衝突的 Merge 解決動作:

public void ResolveUpdateUpdateConflict(object itemData, 
    IEnumerable<SyncId> changeUnitsToMerge, 
    IEnumerable<SyncId> changeUnitsToUpdate, 
    ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out ItemFieldDictionary updatedVersion)
{
    ItemTransfer transfer = (ItemTransfer)itemData;
    ItemData dataCopy = new ItemData(transfer.ItemData);

    // Combine the conflicting data.
    ItemData mergedData = (_store.Get(transfer.Id)).Merge((ItemData)dataCopy);
    ulong timeStamp = _store.UpdateItem(transfer.Id, mergedData);

    updatedVersion = new ItemFieldDictionary();
    updatedVersion.Add(new ItemField(CUSTOM_FIELD_TIMESTAMP, typeof(ulong), timeStamp));
}
Public Sub ResolveUpdateUpdateConflict(ByVal itemData As Object, ByVal changeUnitsToMerge As IEnumerable(Of SyncId), ByVal changeUnitsToUpdate As IEnumerable(Of SyncId), ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, _
    ByRef updatedVersion As ItemFieldDictionary) Implements ISimpleSyncProviderConcurrencyConflictResolver.ResolveUpdateUpdateConflict
    Dim transfer As ItemTransfer = DirectCast(itemData, ItemTransfer)
    Dim dataCopy As New ItemData(transfer.ItemData)

    ' Combine the conflicting data. 
    Dim mergedData As ItemData = (_store.[Get](transfer.Id)).Merge(DirectCast(dataCopy, ItemData))
    Dim timeStamp As ULong = _store.UpdateItem(transfer.Id, mergedData)

    updatedVersion = New ItemFieldDictionary()
    updatedVersion.Add(New ItemField(CUSTOM_FIELD_TIMESTAMP, GetType(ULong), timeStamp))
End Sub

請參閱

參考

ISimpleSyncProviderConcurrencyConflictResolver 成員
Microsoft.Synchronization.SimpleProviders 命名空間