Share via


FullEnumerationSimpleSyncProvider.EnumerateItems Method

When overridden in a derived class, enumerates all items in a replica.

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

Syntax

'Declaration
Public MustOverride Sub EnumerateItems ( _
    context As FullEnumerationContext _
)
'Usage
Dim instance As FullEnumerationSimpleSyncProvider
Dim context As FullEnumerationContext

instance.EnumerateItems(context)
public abstract void EnumerateItems (
    FullEnumerationContext context
)
public:
virtual void EnumerateItems (
    FullEnumerationContext^ context
) abstract
public abstract void EnumerateItems (
    FullEnumerationContext context
)
public abstract function EnumerateItems (
    context : FullEnumerationContext
)

Parameters

Return Value

A collection of ItemFieldDictionary objects that contain metadata about the items that were enumerated.

Remarks

This method should contain or call store-specific code that enables Sync Framework to enumerate the metadata for all of the items in a store.

Example

The following code examples show an implementation of the EnumerateItems method for a sample application that stores items in an in-memory store. The CreateItemFieldDictionary method is a sample method that returns an ItemFieldDictionary object for each item in the store. 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.

public override void EnumerateItems(FullEnumerationContext context)
{
    List<ItemFieldDictionary> items = new List<ItemFieldDictionary>();
    foreach (ulong id in _store.Ids)
    {
        items.Add(_store.CreateItemFieldDictionary(id));
    }
    context.ReportItems(items);
}
public ItemFieldDictionary CreateItemFieldDictionary(ulong id)
{
    ItemFieldDictionary itemFields = null;

    if (_store.ContainsKey(id))
    {
        itemFields = new ItemFieldDictionary();
        itemFields.Add(new ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_ID, typeof(ulong), id));
        itemFields.Add(new ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_TIMESTAMP, typeof(ulong), _store[id].TimeStamp));
    }
    else
    {
        throw new Exception("Item does not exist in store");
    }

    return itemFields;
}
Public Overrides Sub EnumerateItems(ByVal context As FullEnumerationContext)
    Dim items As New List(Of ItemFieldDictionary)()
    For Each id As ULong In _store.Ids
        items.Add(_store.CreateItemFieldDictionary(id))
    Next
    context.ReportItems(items)
End Sub
Public Function CreateItemFieldDictionary(ByVal id As ULong) As ItemFieldDictionary
    Dim itemFields As ItemFieldDictionary = Nothing

    If _store.ContainsKey(id) Then
        itemFields = New ItemFieldDictionary()
        itemFields.Add(New ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_ID, GetType(ULong), id))
        itemFields.Add(New ItemField(MyFullEnumerationSimpleSyncProvider.CUSTOM_FIELD_TIMESTAMP, GetType(ULong), _store(id).TimeStamp))
    Else
        Throw New Exception("Item does not exist in store")
    End If

    Return itemFields
End Function

See Also

Reference

FullEnumerationSimpleSyncProvider Class
FullEnumerationSimpleSyncProvider Members
Microsoft.Synchronization.SimpleProviders Namespace