Share via


ISupportFilteredSync.TryAddFilter Method

When overridden in a derived class, sets the filter that is used for change enumeration by the source provider.

Namespace: Microsoft.Synchronization
Assembly: Microsoft.Synchronization (in microsoft.synchronization.dll)

Syntax

'Declaration
Function TryAddFilter ( _
    filter As Object, _
    filteringType As FilteringType _
) As Boolean
'Usage
Dim instance As ISupportFilteredSync
Dim filter As Object
Dim filteringType As FilteringType
Dim returnValue As Boolean

returnValue = instance.TryAddFilter(filter, filteringType)
bool TryAddFilter (
    Object filter,
    FilteringType filteringType
)
bool TryAddFilter (
    Object^ filter, 
    FilteringType filteringType
)
boolean TryAddFilter (
    Object filter, 
    FilteringType filteringType
)
function TryAddFilter (
    filter : Object, 
    filteringType : FilteringType
) : boolean

Parameters

  • filter
    The filter that is used for change enumeration by the source provider.
  • filteringType
    Indicates the type of information that is included in a change batch during filtered synchronization.

Return Value

True when the filter specified by filter is supported. Otherwise, false.

Remarks

Filter negotiation is achieved by using the following steps:

  1. Before the source provider begins enumerating changes, Sync Framework starts filter negotiation by calling the SpecifyFilter method of the IRequestFilteredSync interface that the destination provider implemented.

  2. During processing of SpecifyFilter, the destination provider passes filters to the FilterRequestCallback that is specified by Sync Framework.

  3. During processing of FilterRequestCallback, Sync Framework calls the TryAddFilter method of the ISupportFilteredSync interface that the source provider implemented. If the source provider does not support the requested filter, the destination provider can continue to request filters until it finds one that is supported.

When a filter has been successfully negotiated, the source provider uses it to determine which items to include during change enumeration.

Notes to Implementers: An implementation of this method can examine the filter specified by filter and filteringType, and return false to indicate that the filter is not supported. The destination provider can then request different filters until one is found that is supported.

Example

The following example implements TryAddFilter. The filter is used for synchronization only when it is a filter tracked by the replica.

Public Function TryAddFilter(ByVal filter As Object, ByVal filteringType As FilteringType) As Boolean Implements ISupportFilteredSync.TryAddFilter
    _filterForSync = Nothing

    ' The filter must be tracked by both replicas.
    For filterKey As Integer = 0 To _filterKeyMap.Count - 1
        If _filterKeyMap(filterKey).IsIdentical(DirectCast(filter, ISyncFilter)) Then
            _filterForSync = DirectCast(_filterKeyMap(filterKey), AddressFilter)
            _filteringType = filteringType
            Exit For
        End If
    Next

    Return (_filterForSync IsNot Nothing)
End Function
public bool TryAddFilter(object filter, FilteringType filteringType)
{
    _filterForSync = null;

    // The filter must be tracked by both replicas.
    for (int filterKey = 0; filterKey < _filterKeyMap.Count; filterKey++)
    {
        if (_filterKeyMap[filterKey].IsIdentical((ISyncFilter)filter))
        {
            _filterForSync = (AddressFilter)_filterKeyMap[filterKey];
            _filteringType = filteringType;
            break;
        }
    }

    return (null != _filterForSync);
}

See Also

Reference

ISupportFilteredSync Interface
ISupportFilteredSync Members
Microsoft.Synchronization Namespace