public bool GetMatchingFilter(Message message, out MessageFilter filter)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }

            Candidate can = InnerMatch(message);

            if (can != null)
            {
                filter = can.filter;
                return(true);
            }

            filter = null;
            return(false);
        }
Example #2
0
 public void RemoveEndpoint(EndpointDispatcher endpoint)
 {
     lock (ThisLock)
     {
         if (_filters == null)
         {
             if (_cachedEndpoints != null && _cachedEndpoints.Contains(endpoint))
             {
                 _cachedEndpoints.Remove(endpoint);
             }
         }
         else
         {
             MessageFilter filter = endpoint.EndpointFilter;
             _filters.Remove(filter);
         }
     }
 }
        public bool GetMatchingFilter(MessageBuffer messageBuffer, out MessageFilter filter)
        {
            if (messageBuffer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageBuffer));
            }

            FilterDataPair pair = InnerMatch(messageBuffer);

            if (pair == null)
            {
                filter = null;
                return(false);
            }

            filter = pair.filter;
            return(true);
        }
 public TFilterData this[MessageFilter filter]
 {
     get
     {
         return(_filters[filter]);
     }
     set
     {
         if (_filters.ContainsKey(filter))
         {
             _filters[filter] = value;
         }
         else
         {
             Add(filter, value);
         }
     }
 }
        public bool GetMatchingValue(Message message, out TFilterData data)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }

            MessageFilter f = InnerMatch(message);

            if (f == null)
            {
                data = default;
                return(false);
            }

            data = _filters[f];
            return(true);
        }
        public bool GetMatchingFilter(MessageBuffer messageBuffer, out MessageFilter filter)
        {
            if (messageBuffer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageBuffer));
            }

            Message msg = messageBuffer.CreateMessage();

            try
            {
                filter = InnerMatch(msg);
                return(filter != null);
            }
            finally
            {
                msg.Close();
            }
        }
Example #7
0
 public TFilterData this[MessageFilter filter]
 {
     get
     {
         return(filters[filter]);
     }
     set
     {
         if (filters.ContainsKey(filter))
         {
             filters[filter]          = value;
             candidates[filter]._data = value;
         }
         else
         {
             Add(filter, value);
         }
     }
 }
Example #8
0
        public EndpointDispatcher(EndpointAddress address, string contractName, string contractNamespace, bool isSystemEndpoint)
        {
            originalAddress        = address;
            this.contractName      = contractName;
            this.contractNamespace = contractNamespace;

            if (address != null)
            {
                addressFilter = new EndpointAddressMessageFilter(address);
            }
            else
            {
                addressFilter = new MatchAllMessageFilter();
            }

            contractFilter        = new MatchAllMessageFilter();
            dispatchRuntime       = new DispatchRuntime(this);
            filterPriority        = 0;
            this.isSystemEndpoint = isSystemEndpoint;
        }
Example #9
0
 public TFilterData this[MessageFilter filter]
 {
     get
     {
         return(filters[filter]);
     }
     set
     {
         if (ContainsKey(filter))
         {
             int p = GetPriority(filter);
             Remove(filter);
             Add(filter, value, p);
         }
         else
         {
             Add(filter, value, defaultPriority);
         }
     }
 }
Example #10
0
        public bool GetMatchingFilter(MessageBuffer buffer, out MessageFilter filter)
        {
            filter = null;
            foreach (KeyValuePair <MessageFilter, FilterData> item in filters)
            {
                if (item.Key.Match(buffer))
                {
                    if (filter != null)
                    {
                        Collection <MessageFilter> f = new Collection <MessageFilter>();
                        f.Add(filter);
                        f.Add(item.Key);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.FilterMultipleMatches, null, f));
                    }

                    filter = item.Key;
                }
            }

            return(filter != null);
        }
Example #11
0
        public bool GetMatchingFilter(Message message, out MessageFilter filter)
        {
            filter = null;
            foreach (KeyValuePair <MessageFilter, FilterData> item in _filters)
            {
                if (item.Key.Match(message))
                {
                    if (filter != null)
                    {
                        Collection <MessageFilter> f = new Collection <MessageFilter>
                        {
                            filter,
                            item.Key
                        };
                        throw TraceUtility.ThrowHelperError(new MultipleFilterMatchesException(SR.FilterMultipleMatches, null, f), message);
                    }

                    filter = item.Key;
                }
            }

            return(filter != null);
        }
Example #12
0
        public void AddEndpoint(EndpointDispatcher endpoint)
        {
            lock (ThisLock)
            {
                MessageFilter filter   = endpoint.EndpointFilter;
                int           priority = endpoint.FilterPriority;

                if (_filters == null)
                {
                    if (_cachedEndpoints == null)
                    {
                        _cachedEndpoints = new List <EndpointDispatcher>(optimizationThreshold);
                    }

                    if (_cachedEndpoints.Count < optimizationThreshold)
                    {
                        _cachedEndpoints.Add(endpoint);
                    }
                    else
                    {
                        _filters = new MessageFilterTable <EndpointDispatcher>();
                        for (int i = 0; i < _cachedEndpoints.Count; i++)
                        {
                            int           cachedPriority = _cachedEndpoints[i].FilterPriority;
                            MessageFilter cachedFilter   = _cachedEndpoints[i].EndpointFilter;
                            _filters.Add(cachedFilter, _cachedEndpoints[i], cachedPriority);
                        }
                        _filters.Add(filter, endpoint, priority);
                        _cachedEndpoints = null;
                    }
                }
                else
                {
                    _filters.Add(filter, endpoint, priority);
                }
            }
        }
 public bool TryGetValue(MessageFilter filter, out FilterData data)
 {
     return(filters.TryGetValue(filter, out data));
 }
 internal Entry(MessageFilter f, TFilterData d)
 {
     filter = f;
     data   = d;
 }
Example #15
0
 public void Add(MessageFilter filter, TFilterData data)
 {
     Add(filter, data, defaultPriority);
 }
Example #16
0
 public bool Remove(MessageFilter key)
 {
     return(_filters.Remove(key));
 }
Example #17
0
 public void Add(MessageFilter key, FilterData value)
 {
     _filters.Add(key, value);
 }
Example #18
0
 public bool ContainsKey(MessageFilter key)
 {
     return(_filters.ContainsKey(key));
 }
Example #19
0
        public void Add(MessageFilter filter, TFilterData data, int priority)
        {
            if (filter == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("filter");
            }

            if (filters.ContainsKey(filter))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("filter", SR.FilterExists);
            }

            Type filterType = filter.GetType();
            Type tableType  = null;
            IMessageFilterTable <TFilterData> table = null;

            if (filterTypeMappings.TryGetValue(filterType, out tableType))
            {
                for (int i = 0; i < tables.Count; ++i)
                {
                    if (tables[i].priority == priority && tables[i].table.GetType().Equals(tableType))
                    {
                        table = tables[i].table;
                        break;
                    }
                }
                if (table == null)
                {
                    table = CreateFilterTable(filter);
                    ValidateTable(table);
                    if (!table.GetType().Equals(tableType))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FilterTableTypeMismatch));
                    }
                    table.Add(filter, data);
                    tables.Add(new FilterTableEntry(priority, table));
                }
                else
                {
                    table.Add(filter, data);
                }
            }
            else
            {
                table = CreateFilterTable(filter);
                ValidateTable(table);
                filterTypeMappings.Add(filterType, table.GetType());

                FilterTableEntry entry = new FilterTableEntry(priority, table);
                int idx = tables.IndexOf(entry);
                if (idx >= 0)
                {
                    table = tables[idx].table;
                }
                else
                {
                    tables.Add(entry);
                }

                table.Add(filter, data);
            }

            filters.Add(filter, data);
        }
Example #20
0
 public bool ContainsKey(MessageFilter filter)
 {
     return(filters.ContainsKey(filter));
 }
Example #21
0
 public AndMessageFilter(MessageFilter filter1, MessageFilter filter2)
 {
     Filter1 = filter1 ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(filter1));
     Filter2 = filter2 ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(filter2));
 }
Example #22
0
 internal Entry(MessageFilter f, TFilterData d, int p)
 {
     filter   = f;
     data     = d;
     priority = p;
 }