Esempio n. 1
0
 public EventInfo(EventBus bus, object source, EventCategoryToken categoryToken, string categoryName, string type, object arguments)
 {
     Bus          = bus;
     Source       = source;
     Category     = categoryToken;
     CategoryName = categoryName;
     Type         = type;
     Arguments    = arguments;
     _IsConsumed  = false;
 }
Esempio n. 2
0
        private EventCategoryToken GetCategory(string name)
        {
            EventCategoryToken result;

            if (!_Categories.TryGetValue(name, out result))
            {
                result            = new EventCategoryToken(name);
                _Categories[name] = result;
            }

            return(result);
        }
Esempio n. 3
0
        protected void BroadcastToSubscribers(object source, string type, object arguments)
        {
            EventInfo           info = null;
            EventSubscriberList subscribers;
            EventFilter         filter;
            EventCategoryToken  categoryToken = null;
            string categoryName = null;

            IEventSource iSource = source as IEventSource;

            if (iSource != null)
            {
                categoryName  = iSource.CategoryName;
                categoryToken = GetCategory(categoryName);
            }

            for (int i = 0; i < 6; i++)
            {
                string typeFilter = (i & 1) == 1 ? type : AnyType;
                object sourceFilter;

                switch (i)
                {
                case 0:
                case 1:
                    sourceFilter = AnySource;
                    break;

                case 2:
                case 3:
                    sourceFilter = categoryToken;
                    break;

                default:
                    sourceFilter = source;
                    break;
                }

                if ((sourceFilter == null) || (typeFilter == null))
                {
                    continue;
                }

                CreateFilter(
                    sourceFilter,
                    typeFilter,
                    out filter,
                    false
                    );

                if (!_Subscribers.TryGetValue(filter, out subscribers))
                {
                    continue;
                }

                int count = subscribers.Count;
                if (count <= 0)
                {
                    continue;
                }

                if (info == null)
                {
                    info = new EventInfo(this, source, categoryToken, categoryName, type, arguments);
                }

                using (var b = BufferPool <EventSubscriber> .Allocate(count)) {
                    var temp = b.Data;
                    subscribers.CopyTo(temp);

                    for (int j = count - 1; j >= 0; j--)
                    {
                        temp[j](info);

                        if (info.IsConsumed)
                        {
                            return;
                        }
                    }

                    b.Clear();
                }
            }
        }