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

'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
)
boolean TryGetDestinationVersion (
    ItemChange sourceChange, 
    /** @attribute OutAttribute() */ /** @ref */ ItemChange destinationVersion
)
JScript does not support passing value-type arguments by reference.

Parameters

  • sourceChange
    The item change that is sent by the source provider.
  • destinationVersion
    Returns an item change that contains the version of the item in the destination replica.

Return Value

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.

Example

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
INotifyingChangeApplierTarget Members
Microsoft.Synchronization Namespace