/// <summary>
        /// Triggers all registered
        /// <see cref="IEventCounterFactory"/>
        /// to produce
        /// <see cref="EventCounter"/>
        /// instance
        /// and count the event.
        /// </summary>
        /// <param name="event">
        ///
        /// <see cref="iText.Kernel.Counter.Event.IEvent"/>
        /// to be counted
        /// </param>
        /// <param name="metaInfo">
        ///
        /// <see cref="iText.Kernel.Counter.Event.IMetaInfo"/>
        /// object that can holds information about instance that throws the event
        /// </param>
        /// <param name="caller">the class that throws the event</param>
        public virtual void OnEvent(IEvent @event, IMetaInfo metaInfo, Type caller)
        {
            IContext context            = null;
            bool     contextInitialized = false;

            foreach (IEventCounterFactory factory in factories.Keys)
            {
                EventCounter counter = factory.GetCounter(caller);
                if (counter != null)
                {
                    if (!contextInitialized)
                    {
                        if (metaInfo != null)
                        {
                            context = ContextManager.GetInstance().GetContext(metaInfo.GetType());
                        }
                        if (context == null)
                        {
                            context = ContextManager.GetInstance().GetContext(caller);
                        }
                        if (context == null)
                        {
                            context = ContextManager.GetInstance().GetContext(@event.GetType());
                        }
                        contextInitialized = true;
                    }
                    if ((context != null && context.Allow(@event)) || (context == null && counter.fallback.Allow(@event)))
                    {
                        counter.OnEvent(@event, metaInfo);
                    }
                }
            }
        }
예제 #2
0
 public SimpleEventCounterFactory(EventCounter counter)
 {
     this.counter = counter;
 }