public static IDisposable Subscribe(IGlobalSubscriber subscriber)
        {
            List <Type> implementedGlobalSubscribers = EventBusHelper.GetImplementedGlobalSubscribers(subscriber);

            bool wasIterating = s_IsIterating;

            s_IsIterating = true;

            foreach (Type interfaceType in implementedGlobalSubscribers)
            {
                List <GlobalSubscriberNode> correspondingList;
                if (s_GlobalSubscribers.ContainsKey(interfaceType))
                {
                    correspondingList = s_GlobalSubscribers[interfaceType];
                }
                else
                {
                    correspondingList = new List <GlobalSubscriberNode>();
                    s_GlobalSubscribers[interfaceType] = correspondingList;
                }

                correspondingList.Add(new GlobalSubscriberNode(subscriber));
            }

            s_IsIterating = wasIterating;
            if (!s_IsIterating)
            {
                CleanUp();
            }

            return(new DisposeAction(() => Unsubscribe(subscriber)));
        }
        public static void Unsubscribe(IGlobalSubscriber subscriber)
        {
            List <Type> subscribersTypes = EventsHandlerHelper.GetSubscriberTypes(subscriber);

            foreach (Type type in subscribersTypes)
            {
                if (_subscribers.ContainsKey(type))
                {
                    _subscribers[type].Remove(subscriber);
                }
            }
        }
Esempio n. 3
0
        public static void Unsubscribe(IGlobalSubscriber subscriber)
        {
            List <Type> subscriberTypes = EventBusHelper.GetSubscriberTypes(subscriber);

            foreach (Type t in subscriberTypes)
            {
                if (s_Subscribers.ContainsKey(t))
                {
                    s_Subscribers[t].Remove(subscriber);
                }
            }
        }
        public static void Subscribe(IGlobalSubscriber subscriber)
        {
            List <Type> subscribersTypes = EventsHandlerHelper.GetSubscriberTypes(subscriber);

            foreach (Type type in subscribersTypes)
            {
                if (!_subscribers.ContainsKey(type))
                {
                    _subscribers[type] = new SubscribersList <IGlobalSubscriber>();
                }
                _subscribers[type].Add(subscriber);
            }
        }
Esempio n. 5
0
        public static void Subscribe(IGlobalSubscriber subscriber)
        {
            List <Type> subscriberTypes = EventBusHelper.GetSubscriberTypes(subscriber);

            foreach (Type t in subscriberTypes)
            {
                if (!s_Subscribers.ContainsKey(t))
                {
                    s_Subscribers[t] = new SubscribersList <IGlobalSubscriber>();
                }
                s_Subscribers[t].Add(subscriber);
            }
        }
        private static void Unsubscribe(IGlobalSubscriber subscriber)
        {
            List <Type> implementedGlobalSubscribers = EventBusHelper.GetImplementedGlobalSubscribers(subscriber);

            foreach (Type interfaceType in implementedGlobalSubscribers)
            {
                if (s_GlobalSubscribers.ContainsKey(interfaceType))
                {
                    List <GlobalSubscriberNode> subscribers = s_GlobalSubscribers[interfaceType];
                    subscribers.FirstOrDefault(node => node.SubscriberEquals(subscriber))?.Release();
                }
            }

            if (!s_IsIterating)
            {
                CleanUp();
            }
        }
        public static List <Type> GetSubscriberTypes(
            IGlobalSubscriber globalSubscriber)
        {
            Type type = globalSubscriber.GetType();

            if (s_CashedSubscriberTypes.ContainsKey(type))
            {
                return(s_CashedSubscriberTypes[type]);
            }

            List <Type> subscriberTypes = type
                                          .GetInterfaces()
                                          .Where(t => t.GetInterfaces()
                                                 .Contains(typeof(IGlobalSubscriber)))
                                          .ToList();

            s_CashedSubscriberTypes[type] = subscriberTypes;
            return(subscriberTypes);
        }
 public bool SubscriberEquals(IGlobalSubscriber globalSubscriber)
 {
     return(m_GlobalSubscriber == globalSubscriber);
 }
 public GlobalSubscriberNode(IGlobalSubscriber globalSubscriber)
 {
     m_GlobalSubscriber = globalSubscriber;
 }
Esempio n. 10
0
 public static List <Type> GetImplementedGlobalSubscribers(IGlobalSubscriber globalSubscriber)
 {
     return(globalSubscriber.GetType().GetInterfaces()
            .Where(type => type.GetInterfaces().Contains(typeof(IGlobalSubscriber)))
            .ToList());
 }