CustomFilterInfo 建構
初始化 CustomFilterInfo 類別的新執行個體,這個執行個體包含指定的識別碼格式結構描述和自訂篩選。
命名空間: Microsoft.Synchronization
組件: Microsoft.Synchronization (在 Microsoft.Synchronization.dll 中)
語法
'宣告
Public Sub New ( _
idFormats As SyncIdFormatGroup, _
syncFilter As ISyncFilter _
)
'用途
Dim idFormats As SyncIdFormatGroup
Dim syncFilter As ISyncFilter
Dim instance As New CustomFilterInfo(idFormats, _
syncFilter)
public CustomFilterInfo(
SyncIdFormatGroup idFormats,
ISyncFilter syncFilter
)
public:
CustomFilterInfo(
SyncIdFormatGroup^ idFormats,
ISyncFilter^ syncFilter
)
new :
idFormats:SyncIdFormatGroup *
syncFilter:ISyncFilter -> CustomFilterInfo
public function CustomFilterInfo(
idFormats : SyncIdFormatGroup,
syncFilter : ISyncFilter
)
參數
- idFormats
型別:Microsoft.Synchronization. . :: . .SyncIdFormatGroup
提供者的識別碼格式結構描述。
- syncFilter
型別:Microsoft.Synchronization. . :: . .ISyncFilter
自訂篩選物件。
例外
例外狀況 | 條件 |
---|---|
ArgumentNullException | 必要的參數為 null Nothing nullptr unit null 參考 (在 Visual Basic 中為 Nothing) 。 |
備註
syncFilter 所代表的自訂篩選通常會由篩選提供者的開發人員所實作。
範例
下列範例會使用自訂篩選從篩選複寫列舉變更。
Public Overloads Overrides Function GetChangeBatch(ByVal batchSize As UInteger, ByVal destinationKnowledge As SyncKnowledge, ByRef changeDataRetriever As Object) As ChangeBatch
' Return this object as the IChangeDataRetriever object that is called to retrieve item data.
changeDataRetriever = Me
' The metadata storage service does not support filter tracking, so enumerate changes manually.
Dim changeBatch As ChangeBatch
If _filterForSync Is Nothing Then
changeBatch = New ChangeBatch(IdFormats, destinationKnowledge, _ContactStore.ContactReplicaMetadata.GetForgottenKnowledge())
Else
Dim filterInfo As New CustomFilterInfo(IdFormats, _filterForSync)
changeBatch = New ChangeBatch(IdFormats, destinationKnowledge, _filterForSync.FilterForgottenKnowledge, filterInfo)
End If
' First, set the filter key map, if the destination replica tracks any filters that are
' tracked by the source replica.
If 0 < FilterKeyMap.Count Then
' Add the filter key map to the change batch before any groups are started.
changeBatch.FilterKeyMap = FilterKeyMap
End If
' Get all the items from the metadata store.
Dim allItems As IEnumerable(Of ItemMetadata) = _ContactStore.ContactReplicaMetadata.GetAllItems(True)
' Convert the destination knowledge for use with local versions.
Dim mappedDestKnowledge As SyncKnowledge = _ContactStore.ContactReplicaMetadata.GetKnowledge().MapRemoteKnowledgeToLocal(destinationKnowledge)
' Enumerate the items in the change batch.
Dim itemChanges As New List(Of ItemChange)(CInt(batchSize))
Dim cItemsInBatch As UInteger = 0
Dim replicaId As SyncId = _ContactStore.ContactReplicaMetadata.ReplicaId
For Each itemMeta As ItemMetadata In allItems
' Process all items if this is an unfiltered enumeration. Otherwise, only process an item that has been in the filter.
If _filterForSync Is Nothing OrElse _ContactStore.HasBeenInFilter(itemMeta, _filterForSync) Then
' If a change is not contained in the destination knowledge, add it to the change batch.
If Not mappedDestKnowledge.Contains(replicaId, itemMeta.GlobalId, itemMeta.ChangeVersion) Then
Dim kind As ChangeKind
If itemMeta.IsDeleted Then
kind = ChangeKind.Deleted
ElseIf _filterForSync IsNot Nothing AndAlso Not _filterForSync.IsInFilter(_ContactStore.ContactList(itemMeta.GlobalId)) Then
kind = ChangeKind.Ghost
Else
kind = ChangeKind.Update
End If
Dim itemChange As New ItemChange(IdFormats, _ContactStore.ContactReplicaMetadata.ReplicaId, itemMeta.GlobalId, kind, itemMeta.CreationVersion, itemMeta.ChangeVersion)
' Pass along any filter information for filters tracked by both the source and destination replicas.
_ContactStore.AddFilterChanges(_filterKeyMap, itemMeta, mappedDestKnowledge, itemChange)
' Add the item to the change list. Include ghosts only if the destination requested ghosts.
If kind <> ChangeKind.Ghost OrElse (kind = ChangeKind.Ghost AndAlso FilteringType.CurrentItemsAndVersionsForMovedOutItems = _filteringType) Then
itemChanges.Add(itemChange)
End If
cItemsInBatch += 1
End If
End If
If batchSize <= cItemsInBatch Then
Exit For
End If
Next
If 0 < itemChanges.Count Then
changeBatch.BeginOrderedGroup(itemChanges(0).ItemId)
' Set the filter forgotten knowledge for each filter that the destination has requested.
For iFilter As Integer = 0 To FilterKeyMap.Count - 1
Dim addressFilter As AddressFilter = DirectCast(FilterKeyMap(iFilter), AddressFilter)
changeBatch.SetFilterForgottenKnowledge(CUInt(iFilter), addressFilter.FilterForgottenKnowledge)
Next
changeBatch.AddChanges(itemChanges)
' End the group of changes in the change batch. Pass the current source knowledge.
changeBatch.EndOrderedGroup(itemChanges(itemChanges.Count - 1).ItemId, _ContactStore.ContactReplicaMetadata.GetKnowledge())
' If all items were enumerated before the batch was filled, then this is the last batch.
If cItemsInBatch < batchSize Then
changeBatch.SetLastBatch()
End If
Else
Throw New InvalidOperationException("GetChangeBatch called but there are no new changes to enumerate.")
End If
Return changeBatch
End Function
public override ChangeBatch GetChangeBatch(uint batchSize, SyncKnowledge destinationKnowledge, out object changeDataRetriever)
{
// Return this object as the IChangeDataRetriever object that is called to retrieve item data.
changeDataRetriever = this;
// The metadata storage service does not support filter tracking, so enumerate changes manually.
ChangeBatch changeBatch;
if (null == _filterForSync)
{
changeBatch = new ChangeBatch(IdFormats, destinationKnowledge, _ContactStore.ContactReplicaMetadata.GetForgottenKnowledge());
}
else
{
CustomFilterInfo filterInfo = new CustomFilterInfo(IdFormats, _filterForSync);
changeBatch = new ChangeBatch(IdFormats, destinationKnowledge, _filterForSync.FilterForgottenKnowledge, filterInfo);
}
// First, set the filter key map, if the destination replica tracks any filters that are
// tracked by the source replica.
if (0 < FilterKeyMap.Count)
{
// Add the filter key map to the change batch before any groups are started.
changeBatch.FilterKeyMap = FilterKeyMap;
}
// Get all the items from the metadata store.
IEnumerable<ItemMetadata> allItems = _ContactStore.ContactReplicaMetadata.GetAllItems(true);
// Convert the destination knowledge for use with local versions.
SyncKnowledge mappedDestKnowledge = _ContactStore.ContactReplicaMetadata.GetKnowledge().MapRemoteKnowledgeToLocal(destinationKnowledge);
// Enumerate the items in the change batch.
List<ItemChange> itemChanges = new List<ItemChange>((int)batchSize);
uint cItemsInBatch = 0;
SyncId replicaId = _ContactStore.ContactReplicaMetadata.ReplicaId;
foreach (ItemMetadata itemMeta in allItems)
{
// Process all items if this is an unfiltered enumeration. Otherwise, only process an item that has been in the filter.
if (null == _filterForSync || _ContactStore.HasBeenInFilter(itemMeta, _filterForSync))
{
// If a change is not contained in the destination knowledge, add it to the change batch.
if (!mappedDestKnowledge.Contains(replicaId, itemMeta.GlobalId, itemMeta.ChangeVersion))
{
ChangeKind kind;
if (itemMeta.IsDeleted)
{
kind = ChangeKind.Deleted;
}
else if (null != _filterForSync && !_filterForSync.IsInFilter(_ContactStore.ContactList[itemMeta.GlobalId]))
{
kind = ChangeKind.Ghost;
}
else
{
kind = ChangeKind.Update;
}
ItemChange itemChange = new ItemChange(IdFormats, _ContactStore.ContactReplicaMetadata.ReplicaId,
itemMeta.GlobalId, kind, itemMeta.CreationVersion, itemMeta.ChangeVersion);
// Pass along any filter information for filters tracked by both the source and destination replicas.
_ContactStore.AddFilterChanges(_filterKeyMap, itemMeta, mappedDestKnowledge, itemChange);
// Add the item to the change list. Include ghosts only if the destination requested ghosts.
if (kind != ChangeKind.Ghost || (kind == ChangeKind.Ghost && FilteringType.CurrentItemsAndVersionsForMovedOutItems == _filteringType))
{
itemChanges.Add(itemChange);
}
cItemsInBatch++;
}
}
if (batchSize <= cItemsInBatch)
{
break;
}
}
if (0 < itemChanges.Count)
{
changeBatch.BeginOrderedGroup(itemChanges[0].ItemId);
// Set the filter forgotten knowledge for each filter that the destination has requested.
for (int iFilter = 0; iFilter < FilterKeyMap.Count; iFilter++)
{
AddressFilter addressFilter = (AddressFilter)FilterKeyMap[iFilter];
changeBatch.SetFilterForgottenKnowledge((uint)iFilter, addressFilter.FilterForgottenKnowledge);
}
changeBatch.AddChanges(itemChanges);
// End the group of changes in the change batch. Pass the current source knowledge.
changeBatch.EndOrderedGroup(itemChanges[itemChanges.Count - 1].ItemId, _ContactStore.ContactReplicaMetadata.GetKnowledge());
// If all items were enumerated before the batch was filled, then this is the last batch.
if (cItemsInBatch < batchSize)
{
changeBatch.SetLastBatch();
}
}
else
{
throw new InvalidOperationException("GetChangeBatch called but there are no new changes to enumerate.");
}
return changeBatch;
}