FullEnumerationSimpleSyncProvider.EnumerateItems 方法

在派生类中重写时,枚举副本中的所有项。

命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)

语法

声明
Public MustOverride Sub EnumerateItems ( _
    context As FullEnumerationContext _
)
用法
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
)

参数

返回值

ItemFieldDictionary 对象的集合,这些对象包含有关已枚举的项的元数据。

备注

此方法应包含或调用存储区特定的代码,此代码使 Sync Framework 能够对存储区中的所有项枚举元数据。

示例

下面的代码示例演示 EnumerateItems 方法的实现,该方法适用于在内存内存储区中存储项的示例应用程序。CreateItemFieldDictionary 方法是一个示例方法,它为存储区中的每个项返回 ItemFieldDictionary 对象。若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider" 应用程序(可从 Sync Framework SDK 和 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

请参阅

参考

FullEnumerationSimpleSyncProvider 类
FullEnumerationSimpleSyncProvider 成员
Microsoft.Synchronization.SimpleProviders 命名空间