INotifyingChangeApplierTarget.SaveChangeWithChangeUnits 메서드
파생 클래스에서 재정의되면 변경 단위 변경 내용을 포함하는 항목 변경 내용을 항목 저장소에 저장합니다.
네임스페이스: Microsoft.Synchronization
어셈블리: microsoft.synchronization.dll의 Microsoft.Synchronization
구문
‘선언
Sub SaveChangeWithChangeUnits ( _
change As ItemChange, _
context As SaveChangeWithChangeUnitsContext _
)
‘사용 방법
Dim instance As INotifyingChangeApplierTarget
Dim change As ItemChange
Dim context As SaveChangeWithChangeUnitsContext
instance.SaveChangeWithChangeUnits(change, context)
void SaveChangeWithChangeUnits (
ItemChange change,
SaveChangeWithChangeUnitsContext context
)
void SaveChangeWithChangeUnits (
ItemChange^ change,
SaveChangeWithChangeUnitsContext^ context
)
void SaveChangeWithChangeUnits (
ItemChange change,
SaveChangeWithChangeUnitsContext context
)
function SaveChangeWithChangeUnits (
change : ItemChange,
context : SaveChangeWithChangeUnitsContext
)
매개 변수
- change
적용할 항목 변경 내용입니다.
- context
적용할 변경 내용에 대한 정보입니다.
주의
구현자를 위한 정보: context에 포함된 동작이 Create인 경우 항목 변경 내용이 원자적으로 저장되어야 합니다. 즉, 모든 변경 단위가 성공적으로 저장되거나 전체 항목 변경 내용이 삭제되어야 합니다. 변경 단위 중 일부만 저장되고 나머지는 저장하지 못하면 데이터가 손상될 수 있습니다. RecordRecoverableErrorForChangeUnit이 호출되고 context가 Create인 경우 RecordRecoverableErrorForChangeUnit은 CreateFailuresMustBeForEntireItemException을 발생시킵니다. 동기화가 이 메서드 중에 취소되고 공급자가 변경 단위 중 일부를 적용한 경우 공급자는 적용되지 않은 모든 변경 단위에 대해 RecordRecoverableErrorForChangeUnit을 호출해야 합니다.
예제
다음 예제에서는 SaveChangeWithChangeUnits 메서드에서 가장 일반적인 SaveChangeAction 값 중 일부를 처리하는 방법을 보여 줍니다.
Public Sub SaveChangeWithChangeUnits(ByVal change As ItemChange, ByVal context As SaveChangeWithChangeUnitsContext) Implements INotifyingChangeApplierTarget.SaveChangeWithChangeUnits
' Enumerate the change units received and apply them by using the specified action.
For Each cuChange As ChangeUnitChange In change.ChangeUnitChanges
Select Case context.GetActionForChangeUnit(cuChange)
Case SaveChangeAction.Create, SaveChangeAction.UpdateVersionAndData
If True Then
' Update the item store and metadata store for the specified change unit.
Try
Dim cuData As String = DirectCast(context.ChangeData, String())(cuChange.ChangeUnitId.GetByteId())
_ContactStore.UpdateContactFromSync(change, cuChange, cuData)
Catch ex As Exception
Dim errData As New RecoverableErrorData(ex)
context.RecordRecoverableErrorForChangeUnit(cuChange, errData)
End Try
Exit Select
End If
Case SaveChangeAction.UpdateVersionAndMergeData
If True Then
' Merge actions are not supported by this implementation.
Throw New NotImplementedException("UpdateVersionAndMergeData is not supported.")
End If
Case SaveChangeAction.UpdateVersionOnly
If True Then
' Update only the version of this change unit in the metadata store.
Try
_ContactStore.UpdateContactVersion(change.ItemId, cuChange.ChangeUnitId, cuChange.ChangeUnitVersion)
Catch ex As Exception
Dim errData As New RecoverableErrorData(ex)
context.RecordRecoverableErrorForChangeUnit(cuChange, errData)
End Try
Exit Select
End If
Case SaveChangeAction.DeleteAndRemoveTombstone, SaveChangeAction.DeleteAndStoreTombstone
If True Then
' Delete actions are handled in SaveItemChange, so throw an exception.
Throw New InvalidOperationException("SaveChangeWithChangeUnits received a delete action.")
End If
Case Else
If True Then
Throw New ArgumentOutOfRangeException("SaveChangeWithChangeUnits received an out-of-range action.")
End If
End Select
Next
' Use the metadata storage service to save the knowledge as each change is applied. Saving knowledge as each change is applied is
' not required. It is more robust than saving the knowledge only after each change batch, because if synchronization is interrupted
' before the end of a change batch, the knowledge will still reflect all of the changes applied. However, it is less efficient because
' knowledge must be stored more frequently.
Dim updatedKnowledge As SyncKnowledge = Nothing
Dim updatedForgottenKnowledge As ForgottenKnowledge = Nothing
context.GetUpdatedDestinationKnowledge(updatedKnowledge, updatedForgottenKnowledge)
_ContactStore.ContactReplicaMetadata.SetKnowledge(updatedKnowledge)
End Sub
public void SaveChangeWithChangeUnits(ItemChange change, SaveChangeWithChangeUnitsContext context)
{
// Enumerate the change units received and apply them by using the specified action.
foreach (ChangeUnitChange cuChange in change.ChangeUnitChanges)
{
switch (context.GetActionForChangeUnit(cuChange))
{
case SaveChangeAction.Create:
case SaveChangeAction.UpdateVersionAndData:
{
// Update the item store and metadata store for the specified change unit.
try
{
string cuData = ((string[])context.ChangeData)[cuChange.ChangeUnitId.GetByteId()];
_ContactStore.UpdateContactFromSync(change, cuChange, cuData);
}
catch (Exception ex)
{
RecoverableErrorData errData = new RecoverableErrorData(ex);
context.RecordRecoverableErrorForChangeUnit(cuChange, errData);
}
break;
}
case SaveChangeAction.UpdateVersionAndMergeData:
{
// Merge actions are not supported by this implementation.
throw new NotImplementedException("UpdateVersionAndMergeData is not supported.");
}
case SaveChangeAction.UpdateVersionOnly:
{
// Update only the version of this change unit in the metadata store.
try
{
_ContactStore.UpdateContactVersion(change.ItemId, cuChange.ChangeUnitId, cuChange.ChangeUnitVersion);
}
catch (Exception ex)
{
RecoverableErrorData errData = new RecoverableErrorData(ex);
context.RecordRecoverableErrorForChangeUnit(cuChange, errData);
}
break;
}
case SaveChangeAction.DeleteAndRemoveTombstone:
case SaveChangeAction.DeleteAndStoreTombstone:
{
// Delete actions are handled in SaveItemChange, so throw an exception.
throw new InvalidOperationException("SaveChangeWithChangeUnits received a delete action.");
}
default:
{
throw new ArgumentOutOfRangeException("SaveChangeWithChangeUnits received an out-of-range action.");
}
}
}
// Use the metadata storage service to save the knowledge as each change is applied. Saving knowledge as each change is applied is
// not required. It is more robust than saving the knowledge only after each change batch, because if synchronization is interrupted
// before the end of a change batch, the knowledge will still reflect all of the changes applied. However, it is less efficient because
// knowledge must be stored more frequently.
SyncKnowledge updatedKnowledge;
ForgottenKnowledge updatedForgottenKnowledge;
context.GetUpdatedDestinationKnowledge(out updatedKnowledge, out updatedForgottenKnowledge);
_ContactStore.ContactReplicaMetadata.SetKnowledge(updatedKnowledge);
}
참고 항목
참조
INotifyingChangeApplierTarget 인터페이스
INotifyingChangeApplierTarget 멤버
Microsoft.Synchronization 네임스페이스