INotifyingChangeApplierTarget::TryGetDestinationVersion Method
Gets the version of an item stored in the destination replica.
Assembly: Microsoft.Synchronization (in Microsoft.Synchronization.dll)
bool TryGetDestinationVersion(
ItemChange^ sourceChange,
[OutAttribute] ItemChange^% destinationVersion
)
Parameters
- sourceChange
- Type: Microsoft.Synchronization::ItemChange
The item change that is sent by the source provider.
- destinationVersion
- Type: Microsoft.Synchronization::ItemChange%
Returns an item change that contains the version of the item in the destination replica.
Return Value
Type: System::Booleantrue if the item was found in the destination replica; otherwise, false.
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.
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; }
Show: