ISimpleSyncProviderConstraintConflictResolver 인터페이스
여러 복제본에서 삽입되는 중복 항목과 같은 제약 조건 충돌을 처리하는 사용자 지정 충돌 해결 프로그램을 나타냅니다.
네임스페이스: Microsoft.Synchronization.SimpleProviders
어셈블리: microsoft.synchronization.simpleproviders.dll의 Microsoft.Synchronization.SimpleProviders
구문
‘선언
Public Interface ISimpleSyncProviderConstraintConflictResolver
‘사용 방법
Dim instance As ISimpleSyncProviderConstraintConflictResolver
public interface ISimpleSyncProviderConstraintConflictResolver
public interface class ISimpleSyncProviderConstraintConflictResolver
public interface ISimpleSyncProviderConstraintConflictResolver
public interface ISimpleSyncProviderConstraintConflictResolver
주의
제약 조건 충돌에 대한 자세한 내용은 단순 공급자의 충돌 처리를 참조하십시오.
예제
이 예제에서는 동시성 충돌 및 제약 조건 충돌에 대한 충돌 처리 정책이 ApplicationDefined
의 기본값으로 유지되어 있습니다. 즉, 응용 프로그램에서 ItemConflicting 및 ItemConstraint 이벤트를 등록하고 동기화를 처리하는 동안 충돌이 발생할 경우 이를 해결하는 동작을 지정합니다. 자세한 내용은 단순 공급자의 충돌 처리를 참조하십시오. 전체 응용 프로그램의 맥락에서 이 코드를 보려면 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
다음 코드 예제에서는 제약 조건 충돌에 대한 Merge 해결 동작에 응답하도록 구현된 MergeConstraintConflict 메서드를 보여 줍니다.
public void MergeConstraintConflict(object itemData,
ConflictVersionInformation conflictVersionInformation,
IEnumerable<SyncId> changeUnitsToMerge,
ItemFieldDictionary localConflictingItem,
ItemFieldDictionary keyAndExpectedVersion,
RecoverableErrorReportingContext recoverableErrorReportingContext,
out ItemFieldDictionary updatedKeyAndVersion)
{
ItemTransfer transfer = (ItemTransfer)itemData;
ItemData dataCopy = new ItemData(transfer.ItemData);
// Combine the conflicting data.
ItemData mergedData = (_store.Get(transfer.Id)).Merge((ItemData)dataCopy);
// We are doing a merge so we must delete the old conflicting item from our store.
ulong idConflicting = (ulong)localConflictingItem[CUSTOM_FIELD_ID].Value;
_store.DeleteItem(idConflicting);
// Now create the new merged data in the store.
if (_store.Contains(transfer.Id))
{
_store.UpdateItem(transfer.Id, dataCopy);
}
else
{
_store.CreateItem(mergedData, transfer.Id);
}
updatedKeyAndVersion = _store.CreateItemFieldDictionary(transfer.Id);
}
Public Sub MergeConstraintConflict(ByVal itemData As Object, ByVal conflictVersionInformation As ConflictVersionInformation, ByVal changeUnitsToMerge As IEnumerable(Of SyncId), ByVal localConflictingItem As ItemFieldDictionary, ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, _
ByRef updatedKeyAndVersion As ItemFieldDictionary) Implements ISimpleSyncProviderConstraintConflictResolver.MergeConstraintConflict
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))
' We are doing a merge so we must delete the old conflicting item from our store.
Dim idConflicting As ULong = CULng(localConflictingItem(CUSTOM_FIELD_ID).Value)
_store.DeleteItem(idConflicting)
' Now create the new merged data in the store.
If _store.Contains(transfer.Id) Then
_store.UpdateItem(transfer.Id, dataCopy)
Else
_store.CreateItem(mergedData, transfer.Id)
End If
updatedKeyAndVersion = _store.CreateItemFieldDictionary(transfer.Id)
End Sub
참고 항목
참조
ISimpleSyncProviderConstraintConflictResolver 멤버
Microsoft.Synchronization.SimpleProviders 네임스페이스