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

'Declaration
Function TryGetDestinationVersion ( _
    sourceChange As ItemChange, _
    <OutAttribute> ByRef destinationVersion As ItemChange _
) As Boolean
'Usage
Dim instance As INotifyingChangeApplierTarget
Dim sourceChange As ItemChange
Dim destinationVersion As ItemChange
Dim returnValue As Boolean

returnValue = instance.TryGetDestinationVersion(sourceChange, _
    destinationVersion)
bool TryGetDestinationVersion(
    ItemChange sourceChange,
    out ItemChange destinationVersion
)
bool TryGetDestinationVersion(
    ItemChange^ sourceChange, 
    [OutAttribute] ItemChange^% destinationVersion
)
abstract TryGetDestinationVersion : 
        sourceChange:ItemChange * 
        destinationVersion:ItemChange byref -> bool 
function TryGetDestinationVersion(
    sourceChange : ItemChange, 
    destinationVersion : ItemChange
) : boolean

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 Function TryGetDestinationVersion(ByVal sourceChange As ItemChange, ByRef destinationVersion As ItemChange) As Boolean Implements INotifyingChangeApplierTarget.TryGetDestinationVersion
    Dim found As Boolean = False
    ' Get the item metadata from the metadata store.
    Dim itemMeta As ItemMetadata = _ContactStore.ContactReplicaMetadata.FindItemMetadataById(sourceChange.ItemId)
    If itemMeta IsNot Nothing Then
        ' The item metadata exists, so translate the change unit metadata to the proper format and
        ' return the item change object.
        Dim cuChange As ChangeUnitChange
        Dim cuChanges As New List(Of ChangeUnitChange)()
        For Each cuMeta As ChangeUnitMetadata In itemMeta.GetChangeUnitEnumerator()
            cuChange = New ChangeUnitChange(IdFormats, cuMeta.ChangeUnitId, cuMeta.ChangeUnitVersion)
            cuChanges.Add(cuChange)
        Next
        destinationVersion = New ItemChange(IdFormats, _ContactStore.ContactReplicaMetadata.ReplicaId, sourceChange.ItemId, ChangeKind.Update, itemMeta.CreationVersion, cuChanges)

        found = True
    Else
        destinationVersion = Nothing
    End If
    Return found
End Function
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