示例#1
0
        /// <summary>
        /// Put all items trough filtering again, to have a fresh set of FilteredItems.
        /// </summary>
        public void ReFilterItems()
        {
            Tracer tracer = Tracer;

            if (tracer == null)
            {
                return;
            }

            TracerFilter[] filters = FiltersArray;
            lock (this)
            {
                _filteredItems.Clear();

                foreach (TracerItem item in _items)
                {
                    if (Tracer.FilterItem(filters, item))
                    {
                        _filteredItems.Add(item);
                    }
                }
            }

            if (ItemAddedEvent != null)
            {
                ItemAddedEvent(this, null);
            }
        }
        /// <summary>
        ///
        /// </summary>
        public virtual bool ReceiveItem(TracerItem item, bool isFilteredOut)
        {
            if (_enabled && (isFilteredOut || _processNonFilteredOutItems))
            {
                bool filteredBySink = false;
                filteredBySink = !Tracer.FilterItem(FiltersArray, item);

                return(OnReceiveItem(item, isFilteredOut, filteredBySink));
            }

            return(true);
        }
        /// <summary>
        /// Put all items trough filtering again, to have a fresh set of FilteredItems.
        /// </summary>
        public void ReFilterItems()
        {
            Tracer tracer = Tracer;

            if (tracer == null)
            {
                return;
            }

            TracerFilter[]    filtersArray  = FiltersArray;
            List <TracerItem> filteredItems = new List <TracerItem>();

            // Not using a copy here causes 2 problems
            // - "collection modified" while filtering, possibly due to Filter raising some event on the same thread (FilterUpdated), that modifies deposits a new item in the _items.
            // - a possible dead lock, since we need to keep locked while calling filters Filter() methods.
            List <TracerItem> items;

            lock (this)
            {
                items = new List <TracerItem>(_items.Count);
                items.AddRange(_items);
            }

            foreach (TracerItem item in items)
            {
                if (Tracer.FilterItem(filtersArray, item))
                {
                    filteredItems.Add(item);
                }
            }

            lock (this)
            {
                _filteredItems = filteredItems;
            }

            if (ItemsFilteredEvent != null)
            {
                ItemsFilteredEvent(this);
            }

            foreach (TracerFilter filter in filtersArray)
            {// Allow the filters to raise delayed update events.
                filter.PerformDelayedUpdateEvent();
            }
        }