Ejemplo n.º 1
0
        public void DistributeEvent(String eventName, MyEventArgBase e)
        {
            if (Broadcast(eventName, e))
            {
                return;
            }

            // Not a broadcast; process event
            PluginList pluginList = new PluginList();

            lock (s_subscriberLock)
            {
                PluginList tmpList;
                if (m_Subscribers.TryGetValue(eventName, out tmpList))
                {
                    // Deep copy
                    pluginList.AddRange(tmpList);
                }
            }

            foreach (IMyPlugin plugin in pluginList)
            {
                if ((plugin.EventPriority <= e.CeilingPriority) || (plugin.EventPriority >= e.FloorPriority))
                {
                    // the source should not be involved.
                    if (!plugin.Equals(e.MyPlugin))
                    {
                        plugin.HandleEvent(eventName, e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private Boolean Broadcast(String eventName, MyEventArgBase e)
        {
            Boolean isBroadcasted = false;

            Boolean isPriorityBased = false;

            switch (eventName)
            {
            case GLOBAL_BROADCAST:
                isPriorityBased = true;
                break;

            case GLOBAL_BROADCAST_NO_PRIORITY:
                isPriorityBased = false;
                break;

            default:
                // This is not a broadcast message
                return(false);
            }

            List <PluginList> pluginLists = new List <PluginList>();

            lock (s_subscriberLock)
            {
                List <PluginList> tmpLists;
                tmpLists = m_Subscribers.Values.ToList <PluginList>();

                // Deep Copy
                pluginLists.AddRange(tmpLists);
            }

            Boolean canBroadcast = isPriorityBased;

            foreach (PluginList pluginList in pluginLists)
            {
                foreach (IMyPlugin plugin in pluginList)
                {
                    if (isPriorityBased)
                    {
                        canBroadcast = ((plugin.EventPriority <= e.CeilingPriority) || (plugin.EventPriority >= e.FloorPriority));
                    }

                    if (canBroadcast)
                    {
                        plugin.HandleEvent(eventName, e);
                    }
                }
            }


            return(isBroadcasted);
        }