CustomFilterInfo 생성자
지정된 ID 형식 스키마와 사용자 지정 필터를 포함하는 CustomFilterInfo 클래스의 새 인스턴스를 초기화합니다.
네임스페이스: Microsoft.Synchronization
어셈블리: microsoft.synchronization.dll의 Microsoft.Synchronization
구문
‘선언
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
)
public CustomFilterInfo (
SyncIdFormatGroup idFormats,
ISyncFilter syncFilter
)
public function CustomFilterInfo (
idFormats : SyncIdFormatGroup,
syncFilter : ISyncFilter
)
매개 변수
- idFormats
공급자의 ID 형식 스키마입니다.
- syncFilter
사용자 지정 필터 개체입니다.
예외
예외 형식 | 조건 |
---|---|
필수 매개 변수가 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;
}
참고 항목
참조
CustomFilterInfo 클래스
CustomFilterInfo 멤버
Microsoft.Synchronization 네임스페이스