Compartilhar via


Método KnowledgeSyncProvider.ProcessChangeBatch

Quando substituído em uma classe derivada, processa um conjunto de alterações detectando conflitos e aplicando alterações no repositório de itens.

Namespace: Microsoft.Synchronization
Assembly: Microsoft.Synchronization (em microsoft.synchronization.dll)

Sintaxe

'Declaração
Public MustOverride Sub ProcessChangeBatch ( _
    resolutionPolicy As ConflictResolutionPolicy, _
    sourceChanges As ChangeBatch, _
    changeDataRetriever As Object, _
    syncCallbacks As SyncCallbacks, _
    sessionStatistics As SyncSessionStatistics _
)
'Uso
Dim instance As KnowledgeSyncProvider
Dim resolutionPolicy As ConflictResolutionPolicy
Dim sourceChanges As ChangeBatch
Dim changeDataRetriever As Object
Dim syncCallbacks As SyncCallbacks
Dim sessionStatistics As SyncSessionStatistics

instance.ProcessChangeBatch(resolutionPolicy, sourceChanges, changeDataRetriever, syncCallbacks, sessionStatistics)
public abstract void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy,
    ChangeBatch sourceChanges,
    Object changeDataRetriever,
    SyncCallbacks syncCallbacks,
    SyncSessionStatistics sessionStatistics
)
public:
virtual void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy, 
    ChangeBatch^ sourceChanges, 
    Object^ changeDataRetriever, 
    SyncCallbacks^ syncCallbacks, 
    SyncSessionStatistics^ sessionStatistics
) abstract
public abstract void ProcessChangeBatch (
    ConflictResolutionPolicy resolutionPolicy, 
    ChangeBatch sourceChanges, 
    Object changeDataRetriever, 
    SyncCallbacks syncCallbacks, 
    SyncSessionStatistics sessionStatistics
)
public abstract function ProcessChangeBatch (
    resolutionPolicy : ConflictResolutionPolicy, 
    sourceChanges : ChangeBatch, 
    changeDataRetriever : Object, 
    syncCallbacks : SyncCallbacks, 
    sessionStatistics : SyncSessionStatistics
)

Parâmetros

  • resolutionPolicy
    A política de resolução de conflitos a ser usada quando este método aplica alterações.
  • sourceChanges
    Um lote de alterações do provedor de origem a ser aplicado localmente.
  • changeDataRetriever
    Um objeto que pode ser usado para recuperar dados de alteração. Pode ser um objeto IChangeDataRetriever ou um objeto específico ao provedor.
  • syncCallbacks
    Um objeto que recebe notificações de evento durante a aplicação de alterações.
  • sessionStatistics
    Controla estatísticas de alterações. Para um provedor que usa uma aplicação de alterações personalizada, este objeto deve ser atualizado com os resultados da aplicação de alterações.

Comentários

Quando uma alteração de origem contém alterações da unidade de alteração, o provedor de destino deve determinar quais (se houver alguma) versões da unidade de alteração devem ser incluídas no lote de versões de destino enviadas ao aplicador de alterações. Essa decisão depende do tipo de alteração do provedor de origem e do fato de o item estar ou não marcado como excluído na réplica de destino. Para obter mais informações, consulte Sincronizando unidades de alteração.

Exemplo

O exemplo a seguir obtém a versão de destino de todos os itens no lote de alterações e cria um objeto NotifyingChangeApplier, usando-o para tratar detecção de conflitos e aplicação de alterações.

public override void ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)
{
    // Use the metadata store to get the local versions of changes received from the source provider.
    IEnumerable<ItemChange> destVersions = _itemStore.ContactReplicaMetadata.GetLocalVersions(sourceChanges);

    // Use a NotifyingChangeApplier object to process the changes. Note that this object is passed as the INotifyingChangeApplierTarget
    // object that will be called to apply changes to the item store.
    NotifyingChangeApplier changeApplier = new NotifyingChangeApplier(IdFormats);
    changeApplier.ApplyChanges(resolutionPolicy, sourceChanges, (IChangeDataRetriever)changeDataRetriever, destVersions,
        _itemStore.ContactReplicaMetadata.GetKnowledge(), _itemStore.ContactReplicaMetadata.GetForgottenKnowledge(), 
        this, _sessionContext, syncCallbacks);
}

O exemplo a seguir mostra o método GetLocalVersions que foi chamado no exemplo anterior. Este exemplo enumera as alterações no lote de alterações de origem e cria uma lista de versões de destino.

public override IEnumerable<ItemChange> GetLocalVersions(ChangeBatch sourceChanges)
{
    List<ItemChange> localVersions = new List<ItemChange>();

    // Enumerate the source changes and retrieve the destination version for each source change. 
    foreach (ItemChange srcItem in sourceChanges)
    {
        ItemChange localVer;

        // When the source item exists in the destination metadata store, retrieve the destination version of the item.
        if (_items.ContainsKey(srcItem.ItemId))
        {
            XmlItemMetadata localMeta = _items[srcItem.ItemId];
            ChangeKind kind = (localMeta.IsDeleted) ? ChangeKind.Deleted : ChangeKind.Update;
            localVer = new ItemChange(IdFormats, ReplicaId, srcItem.ItemId, kind, localMeta.CreationVersion, localMeta.ChangeVersion);
        }
        // When the source item does not exist in the destination metadata store, create a new change with unknown
        // version information.
        else
        {
            localVer = new ItemChange(IdFormats, ReplicaId, srcItem.ItemId, ChangeKind.UnknownItem, SyncVersion.UnknownVersion, SyncVersion.UnknownVersion);
        }

        localVersions.Add(localVer);
    }

    return localVersions;
}

Consulte também

Referência

Classe KnowledgeSyncProvider
Membros KnowledgeSyncProvider
Namespace Microsoft.Synchronization