다음을 통해 공유


INotifyingChangeApplierTarget.SaveItemChange 메서드

파생 클래스에서 재정의되면 항목 변경 내용을 항목 저장소에 저장합니다.

네임스페이스: Microsoft.Synchronization
어셈블리: microsoft.synchronization.dll의 Microsoft.Synchronization

구문

‘선언
Sub SaveItemChange ( _
    saveChangeAction As SaveChangeAction, _
    change As ItemChange, _
    context As SaveChangeContext _
)
‘사용 방법
Dim instance As INotifyingChangeApplierTarget
Dim saveChangeAction As SaveChangeAction
Dim change As ItemChange
Dim context As SaveChangeContext

instance.SaveItemChange(saveChangeAction, change, context)
void SaveItemChange (
    SaveChangeAction saveChangeAction,
    ItemChange change,
    SaveChangeContext context
)
void SaveItemChange (
    SaveChangeAction saveChangeAction, 
    ItemChange^ change, 
    SaveChangeContext^ context
)
void SaveItemChange (
    SaveChangeAction saveChangeAction, 
    ItemChange change, 
    SaveChangeContext context
)
function SaveItemChange (
    saveChangeAction : SaveChangeAction, 
    change : ItemChange, 
    context : SaveChangeContext
)

매개 변수

  • saveChangeAction
    변경 내용에 대해 수행할 동작입니다.
  • change
    저장할 항목 변경 내용입니다.
  • context
    적용할 변경 내용에 대한 정보입니다.

예제

다음 예제에서는 SaveItemChange 메서드에서 가장 일반적인 SaveChangeAction 값 중 일부를 처리하는 방법을 보여 줍니다.

Public Sub SaveItemChange(ByVal saveChangeAction__1 As SaveChangeAction, ByVal change As ItemChange, ByVal context As SaveChangeContext) Implements INotifyingChangeApplierTarget.SaveItemChange
    Select Case saveChangeAction__1
        ' Update the item store and metadata store when an item is created or updated. 
        Case SaveChangeAction.Create, SaveChangeAction.UpdateVersionAndData
            If True Then
                Try
                    _itemStore.UpdateContactFromSync(change, DirectCast(context.ChangeData, String))
                Catch ex As Exception
                    Dim errData As New RecoverableErrorData(ex)
                    context.RecordRecoverableErrorForItem(errData)
                End Try
                Exit Select
            End If

            ' Update only the version of this item in the metadata store. 
        Case SaveChangeAction.UpdateVersionOnly
            If True Then
                Try
                    _itemStore.UpdateContactVersion(change.ItemId, change.ChangeVersion)
                Catch ex As Exception
                    Dim errData As New RecoverableErrorData(ex)
                    context.RecordRecoverableErrorForItem(errData)
                End Try
                Exit Select
            End If

            ' Delete the item from the item store and store a tombstone for it in the metadata store. 
        Case SaveChangeAction.DeleteAndStoreTombstone
            If True Then
                Try
                    _itemStore.DeleteContactFromSync(change.ItemId, change.ChangeVersion)
                Catch ex As Exception
                    Dim errData As New RecoverableErrorData(ex)
                    context.RecordRecoverableErrorForItem(errData)
                End Try

                Exit Select
            End If

            ' Neither merging of data nor removing tombstones is supported. 
        Case SaveChangeAction.UpdateVersionAndMergeData, SaveChangeAction.DeleteAndRemoveTombstone
            If True Then
                Throw New NotImplementedException()
            End If
        Case Else

            If True Then
                Throw New ArgumentOutOfRangeException()
            End If
    End Select

    ' Save the knowledge in the metadata store 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 knowledge As SyncKnowledge = Nothing
    Dim forgottenKnowledge As ForgottenKnowledge = Nothing
    context.GetUpdatedDestinationKnowledge(knowledge, forgottenKnowledge)
    _itemStore.ContactReplicaMetadata.SetKnowledge(knowledge)
End Sub
public void SaveItemChange(SaveChangeAction saveChangeAction, ItemChange change, SaveChangeContext context)
{
    switch (saveChangeAction)
    {
        // Update the item store and metadata store when an item is created or updated.
        case SaveChangeAction.Create:
        case SaveChangeAction.UpdateVersionAndData:
        {
            try
            {
                _itemStore.UpdateContactFromSync(change, (string)context.ChangeData);
            }
            catch (Exception ex)
            {
                RecoverableErrorData errData = new RecoverableErrorData(ex);
                context.RecordRecoverableErrorForItem(errData);
            }
            break;
        }

        // Update only the version of this item in the metadata store.
        case SaveChangeAction.UpdateVersionOnly:
        {
            try
            {
                _itemStore.UpdateContactVersion(change.ItemId, change.ChangeVersion);
            }
            catch (Exception ex)
            {
                RecoverableErrorData errData = new RecoverableErrorData(ex);
                context.RecordRecoverableErrorForItem(errData);
            }
            break;
        }

        // Delete the item from the item store and store a tombstone for it in the metadata store.
        case SaveChangeAction.DeleteAndStoreTombstone:
        {
            try
            {
                _itemStore.DeleteContactFromSync(change.ItemId, change.ChangeVersion);
            }
            catch (Exception ex)
            {
                RecoverableErrorData errData = new RecoverableErrorData(ex);
                context.RecordRecoverableErrorForItem(errData);
            }

            break;
        }

        // Neither merging of data nor removing tombstones is supported.
        case SaveChangeAction.UpdateVersionAndMergeData:
        case SaveChangeAction.DeleteAndRemoveTombstone:
        {
            throw new NotImplementedException();
        }

        default:
        {
            throw new ArgumentOutOfRangeException();
        }
    }

    // Save the knowledge in the metadata store 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 knowledge;
    ForgottenKnowledge forgottenKnowledge;
    context.GetUpdatedDestinationKnowledge(out knowledge, out forgottenKnowledge);
    _itemStore.ContactReplicaMetadata.SetKnowledge(knowledge);
}

공급자가 변경 단위를 사용하는 경우 SaveItemChange 메서드는 다음 예제와 같이 삭제 동작을 처리하기 위해서만 호출됩니다.

Public Sub SaveItemChange(ByVal saveChangeAction__1 As SaveChangeAction, ByVal change As ItemChange, ByVal context As SaveChangeContext) Implements INotifyingChangeApplierTarget.SaveItemChange
    ' This provider uses change units, so SaveChangeWithChangeUnits is called for all actions except delete actions.
    If SaveChangeAction.DeleteAndStoreTombstone = saveChangeAction__1 Then
        ' Delete the item from the item store and store a tombstone for it in the metadata store.
        Try
            _ContactStore.DeleteContactFromSync(change.ItemId, change.ChangeVersion)
        Catch ex As Exception
            Dim errData As New RecoverableErrorData(ex)
            context.RecordRecoverableErrorForItem(errData)
        End Try
    Else
        ' SaveChangeWithChangeUnits should be called for all actions other than delete actions.
        Throw New NotImplementedException("SaveItemChange only handles deletes!")
    End If

    ' 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 SaveItemChange(SaveChangeAction saveChangeAction, ItemChange change, SaveChangeContext context)
{
    // This provider uses change units, so SaveChangeWithChangeUnits is called for all actions except delete actions.
    if (SaveChangeAction.DeleteAndStoreTombstone == saveChangeAction)
    {
        // Delete the item from the item store and store a tombstone for it in the metadata store.
        try
        {
            _ContactStore.DeleteContactFromSync(change.ItemId, change.ChangeVersion);
        }
        catch (Exception ex)
        {
            RecoverableErrorData errData = new RecoverableErrorData(ex);
            context.RecordRecoverableErrorForItem(errData);
        }
    }
    else 
    {
        // SaveChangeWithChangeUnits should be called for all actions other than delete actions.
        throw new NotImplementedException("SaveItemChange only handles deletes!");
    }

    // 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 네임스페이스