Share via


AnchorEnumerationSimpleSyncProvider.GetEnumerationAnchor Method

When overridden in a derived class, returns an enumeration anchor that is used to determine the set of changes to synchronize during a session.

Namespace: Microsoft.Synchronization.SimpleProviders
Assembly: Microsoft.Synchronization.SimpleProviders (in microsoft.synchronization.simpleproviders.dll)

Syntax

'Declaration
Public MustOverride Function GetEnumerationAnchor As Byte()
'Usage
Dim instance As AnchorEnumerationSimpleSyncProvider
Dim returnValue As Byte()

returnValue = instance.GetEnumerationAnchor
public abstract byte[] GetEnumerationAnchor ()
public:
virtual array<unsigned char>^ GetEnumerationAnchor () abstract
public abstract byte[] GetEnumerationAnchor ()
public abstract function GetEnumerationAnchor () : byte[]

Return Value

A byte array that represents an enumeration anchor, such as a timestamp.

Remarks

An anchor is a point in time. Time can either be logical time, such as a timestamp or another monotonically increasing number, or it can be clock time. During the first synchronization session, the anchor value is null; therefore all items in the store are enumerated. During subsequent synchronization sessions, the GetEnumerationAnchor method is called to provide a new anchor value. Changes that are made after the previous anchor value and before the new anchor value are synchronized. The new anchor value is then stored by Sync Framework and used as the previous anchor value for the next synchronization session.

Example

The following code examples show an implementation of the GetEnumerationAnchor method for a sample application that stores items in an in-memory store. The GetAnchor method is a sample method that returns an anchor for the store, which is the timestamp of the last change given to Sync Framework. To view this code in the context of a complete application, see the "Sync101 using Simple Sync Provider" application that is available in the Sync Framework SDK and from Code Gallery.

Note

This is a very simple anchor and change tracking implementation. For a production anchor implementation, you would have to consider optimistic concurrency issues that can arise when user changes to the store occur during a synchronization session.

public override byte[] GetEnumerationAnchor()
{
    return _store.GetAnchor();
}
public byte[] GetAnchor()
{
    //Use the timestamp of the last change as the anchor.
    if (_trackedChanges.Count > 0)
    {
        return BitConverter.GetBytes(_trackedChanges.Keys[_trackedChanges.Count - 1]);
    }
    else
    {
        return null;
    }
}
Public Overrides Function GetEnumerationAnchor() As Byte()
    Return _store.GetAnchor()
End Function
Public Function GetAnchor() As Byte()
    'Use the timestamp of the last change as the anchor. 
    If _trackedChanges.Count > 0 Then
        Return BitConverter.GetBytes(_trackedChanges.Keys(_trackedChanges.Count - 1))
    Else
        Return Nothing
    End If
End Function

See Also

Reference

AnchorEnumerationSimpleSyncProvider Class
AnchorEnumerationSimpleSyncProvider Members
Microsoft.Synchronization.SimpleProviders Namespace