private void arrivalsUpdated(ArrivalMonitor source, ArrivalEvent e) { if (monitor != null && source == monitor && e.Error == false) { // cachedArrivals = e.Arrivals.ToArray (); // // //combine arrivals by route for better display // cachedBundles=new List<ArrivalBundle>(); // ArrivalBundle lastBundle=null; // if (cachedArrivals.Length>0){ // foreach (Arrival a in cachedArrivals){ // if (lastBundle==null||lastBundle.Bus!=a.Bus){ // if (lastBundle!=null) // cachedBundles.Add (lastBundle); // lastBundle=new ArrivalBundle(a); // } else // lastBundle.Times.Add (a.Time); // } // cachedBundles.Add (lastBundle); // } Dictionary <string, int> destinationToListPos = new Dictionary <string, int>(); List <List <Arrival> > bundles = new List <List <Arrival> >(); //should be sorted by the monitor foreach (Arrival a in e.Arrivals) { if (destinationToListPos.ContainsKey(a.Destination)) { //use the dictionary to find which bundle to add to bundles[destinationToListPos[a.Destination]].Add(a); } else { //create a new list for this dest List <Arrival> newList = new List <Arrival>(); newList.Add(a); //add it to the list of lists bundles.Add(newList); //make note of the index so we can retrieve it to add more destinationToListPos.Add(a.Destination, bundles.Count - 1); } } cachedBundles = bundles; } ArrivalsUpdated(this); }
private void reinitializeArrivalMonitor() { if (DisplayedStop == null) { monitor = null; } else { if (FutureTime == null) //live mode { monitor = new ArrivalMonitor((BusStop)DisplayedStop); } else //time travel mode { monitor = new ArrivalMonitor((BusStop)DisplayedStop, FutureTime.Value); } monitor.ArrivalsUpdated += arrivalsUpdated; } Refresh(); }
private void reinitializeArrivalMonitor() { if (DisplayedStop == null) monitor = null; else { if (FutureTime == null)//live mode monitor = new ArrivalMonitor ((BusStop)DisplayedStop); else//time travel mode monitor = new ArrivalMonitor ((BusStop)DisplayedStop, FutureTime.Value); monitor.ArrivalsUpdated+=arrivalsUpdated; } Refresh(); }
private void arrivalsUpdated(ArrivalMonitor source, ArrivalEvent e) { if (monitor != null && source == monitor && e.Error == false) { // cachedArrivals = e.Arrivals.ToArray (); // // //combine arrivals by route for better display // cachedBundles=new List<ArrivalBundle>(); // ArrivalBundle lastBundle=null; // if (cachedArrivals.Length>0){ // foreach (Arrival a in cachedArrivals){ // if (lastBundle==null||lastBundle.Bus!=a.Bus){ // if (lastBundle!=null) // cachedBundles.Add (lastBundle); // lastBundle=new ArrivalBundle(a); // } else // lastBundle.Times.Add (a.Time); // } // cachedBundles.Add (lastBundle); // } Dictionary<string, int> destinationToListPos = new Dictionary<string, int>(); List<List<Arrival>> bundles = new List<List<Arrival>>(); //should be sorted by the monitor foreach (Arrival a in e.Arrivals){ if (destinationToListPos.ContainsKey(a.Destination)){ //use the dictionary to find which bundle to add to bundles[destinationToListPos[a.Destination]].Add (a); } else{ //create a new list for this dest List<Arrival> newList = new List<Arrival>(); newList.Add(a); //add it to the list of lists bundles.Add(newList); //make note of the index so we can retrieve it to add more destinationToListPos.Add(a.Destination, bundles.Count-1); } } cachedBundles=bundles; } ArrivalsUpdated (this); }