Share via


INotifyingChangeApplierTarget.TryGetDestinationVersion Method

Gets the version of an item stored in the destination replica.

Namespace:  Microsoft.Synchronization
Assembly:  Microsoft.Synchronization (in Microsoft.Synchronization.dll)

Syntax

bool TryGetDestinationVersion(
    ItemChange sourceChange,
    out ItemChange destinationVersion
)

Parameters

Return Value

Type: System.Boolean
true if the item was found in the destination replica; otherwise, false.

Remarks

This method is called by NotifyingChangeApplier when destination versions are not passed to the ApplyChanges method. TryGetDestinationVersion is called one time for each change in the batch of changes that is sent to the change applier.

This method is optional and can throw NotImplementedException, except when the provider reports constraint conflicts or any other provider in the synchronization community resolves constraint conflicts by merging. In either of these cases, this method must be implemented.

Examples

The following example shows how to get the destination versions of change units contained in an item by using the metadata storage service.

public bool TryGetDestinationVersion(ItemChange sourceChange, out ItemChange destinationVersion)
{
    bool found = false;
    // Get the item metadata from the metadata store.
    ItemMetadata itemMeta = _ContactStore.ContactReplicaMetadata.FindItemMetadataById(sourceChange.ItemId);
    if (null != itemMeta)
    {
        // The item metadata exists, so translate the change unit metadata to the proper format and
        // return the item change object.
        ChangeUnitChange cuChange;
        List<ChangeUnitChange> cuChanges = new List<ChangeUnitChange>();
        foreach (ChangeUnitMetadata cuMeta in itemMeta.GetChangeUnitEnumerator())
        {
            cuChange = new ChangeUnitChange(IdFormats, cuMeta.ChangeUnitId, cuMeta.ChangeUnitVersion);
            cuChanges.Add(cuChange);
        }
        destinationVersion = new ItemChange(IdFormats, _ContactStore.ContactReplicaMetadata.ReplicaId, sourceChange.ItemId,
            ChangeKind.Update, itemMeta.CreationVersion, cuChanges);

        found = true;
    }
    else
    {
        destinationVersion = null;
    }
    return found;
}

See Also

Reference

INotifyingChangeApplierTarget Interface

Microsoft.Synchronization Namespace