CustomFilterInfo 构造函数

初始化 CustomFilterInfo 类的一个新实例,该实例包含指定的 ID 格式架构和自定义筛选器。

命名空间: 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
)
public CustomFilterInfo (
    SyncIdFormatGroup idFormats, 
    ISyncFilter syncFilter
)
public function CustomFilterInfo (
    idFormats : SyncIdFormatGroup, 
    syncFilter : ISyncFilter
)

参数

  • idFormats
    提供程序的 ID 格式架构。
  • syncFilter
    自定义筛选器对象。

异常

异常类型 条件

ArgumentNullException

必需的参数为 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 命名空间