public bool OnListenerRemoving(string eventType, Delegate listenerBeingRemoved)
        {
                        #if LOG_ALL_MESSAGES
            Debug.Log("MESSENGER OnListenerRemoving \t\"" + eventType + "\"\t{" + listenerBeingRemoved.Target + " -> " + listenerBeingRemoved.Method + "}");
                        #endif

            bool success = true;
            if (Routers.ContainsKey(eventType))
            {
                Delegate d = Routers[eventType];

                if (d == null)
                {
                    success = false;
                    throw new ListenerException(string.Format("Attempting to remove listener with for event type \"{0}\" but current listener is null.", eventType));
                }
                else if (d.GetType() != listenerBeingRemoved.GetType())
                {
                    success = false;
                    throw new ListenerException(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name));
                }
            }
            else
            {
                success = false;
                throw new ListenerException(string.Format("Attempting to remove listener for type \"{0}\" but Messenger doesn't know about this event type.", eventType));
            }

            return(success);
        }
Exemple #2
0
        private void btnCompute_Click(object sender, EventArgs e)
        {
            if (listRouter.SelectedItem == null)
            {
                MessageBox.Show("Not selected router", "Error", MessageBoxButtons.OK);
                return;
            }
            int routerId = Int32.Parse(listRouter.SelectedItem.ToString().Split('_')[0]);
            int turn     = Int32.Parse(listRouter.SelectedItem.ToString().Split('_')[1]);

            DijkstraFinding dijkstra = new DijkstraFinding(BusManager.Inst());
            Router          router   = null;

            if (!Routers.ContainsKey(routerId))
            {
                MessageBox.Show("Invalid router", "Error", MessageBoxButtons.OK);
                return;
            }
            router = Routers[routerId];
            List <int> stationIds = null;

            if (turn == 0)
            {
                stationIds = router.Stations1;
            }
            else if (turn == 1)
            {
                stationIds = router.Stations2;
            }
            if (stationIds == null)
            {
                MessageBox.Show("Invalid turn", "Error", MessageBoxButtons.OK);
                return;
            }

            for (int i = 0; i < stationIds.Count - 1; i++)
            {
                dijkstra.addPath(stationIds[i], stationIds[i + 1]);
            }

            Vertex dest = dijkstra.computePath(stationIds[0], stationIds[stationIds.Count - 20]);

            if (dest == null)
            {
                MessageBox.Show("Cannot find shortest path");
                return;
            }

            List <int> listStation = new List <int>();

            while (dest.PreviewVertex != null)
            {
                listStation.Add(dest.StationId);
                dest = dest.PreviewVertex;
            }
            listStation.Reverse();
            clearMap();
            drawStationPath(listStation, Color.Red, sortedPathOverlay);
        }
        public void OnListenerAdding(string eventType, Delegate listenerBeingAdded)
        {
                        #if LOG_ALL_MESSAGES || LOG_ADD_LISTENER
            Debug.Log("MESSENGER OnListenerAdding \t\"" + eventType + "\"\t{" + listenerBeingAdded.Target + " -> " + listenerBeingAdded.Method + "}");
                        #endif

            if (!Routers.ContainsKey(eventType))
            {
                Routers.Add(eventType, null);
            }

            Delegate d = Routers[eventType];
            if (d != null && d.GetType() != listenerBeingAdded.GetType())
            {
                throw new ListenerException(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name));
            }
        }
 public bool ContainsEvent(string eventType)
 {
     return(Routers.ContainsKey(eventType));
 }