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
)
參數
- context
表示同步處理工作階段之內容的 FullEnumerationContext 物件。
傳回值
ItemFieldDictionary 物件的集合,包含所列舉項目的中繼資料。
備註
這個方法應該包含或呼叫存放區專屬程式碼,讓 Sync Framework 列舉存放區中所有項目的中繼資料。
範例
下列程式碼範例針對將項目儲存在記憶體中存放區的範例應用程式示範 EnumerateItems 方法的實作。CreateItemFieldDictionary
方法是範例方法,它會針對存放區中的每一項目傳回 ItemFieldDictionary 物件。若要在完整應用程式的內容中檢視這段程式碼,請參閱 Sync Framework SDK 及 Code Gallery 中的 "Sync101 using Simple Sync Provider"
應用程式。
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 命名空間