Exemplo n.º 1
0
        private void notify()
        {
            ArrivalEvent e = new ArrivalEvent(results, myStop);

            if (ArrivalsUpdated != null)
            {
                ArrivalsUpdated(this, e);
            }
        }
Exemplo n.º 2
0
        private void notify(bool error = false)
        {
            ArrivalEvent e = new ArrivalEvent(results, myStop);

            e.Error = error;
            if (ArrivalsUpdated != null)
            {
                ArrivalsUpdated(this, e);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// USED IN LIVE MODE
        /// Receives the live results from the live fetcher
        /// reconciled with scheduled data and notifies observers
        /// </summary>
        private void receiveLiveResults(LiveArrivalFetcher fetcher, ArrivalEvent e)
        {
            if (fetcher != this.fetcher || !liveMode)            //verify this is the correct fetcher
            {
                return;
            }
            List <Arrival> masterList = new List <Arrival> ();

            if (e.Error)              //don't propagate the live error (whatever it was). Just return only the schedule data.
            {
                results = getDataScheduleNow();
                notify();
                return;
            }
            List <Arrival> liveData  = e.Arrivals;
            var            scheduled = db.getNextArrivals(myStop.stopId, aheadTime, DateTime.Now);

            //go through scheduled list and keep buses (by full name) that are not in live
            foreach (Arrival sAr in scheduled)
            {
                bool contains = false;
                foreach (Arrival lAr in liveData)
                {
                    if (lAr.Destination == sAr.Destination)                      //found bus with matching nmae
                    {
                        contains = true;
                        break;
                    }
                }
                if (!contains && sAr.Time < DateTime.Now.Add(aheadTime)) //also check whether within timeframe
                {
                    masterList.Add(sAr);                                 //add scheduled arrival since live data not tracking that bus
                }
            }
            //merge with livedata that is within after and ahead window
            masterList.AddRange(liveData.Where((x) => (x.Time > afterTime && x.Time < DateTime.Now.Add(aheadTime))));
            masterList.Sort();

            results = masterList;
            notify();
        }
Exemplo n.º 5
0
 private void notify(bool error=false)
 {
     ArrivalEvent e = new ArrivalEvent (results, myStop);
     e.Error = error;
     if (ArrivalsUpdated != null)
         ArrivalsUpdated (this, e);
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// USED IN LIVE MODE
        /// Receives the live results from the live fetcher
        /// reconciled with scheduled data and notifies observers
        /// </summary>
        private void receiveLiveResults(LiveArrivalFetcher fetcher, ArrivalEvent e)
        {
            if (fetcher != this.fetcher || !liveMode)//verify this is the correct fetcher
                return;
            List<Arrival> masterList = new List<Arrival> ();
            if (e.Error) {//don't propagate the live error (whatever it was). Just return only the schedule data.
                results = getDataScheduleNow ();
                notify ();
                return;
            }
            List<Arrival> liveData = e.Arrivals;
            var scheduled = db.getNextArrivals (myStop.stopId, aheadTime, DateTime.Now);
            //go through scheduled list and keep buses (by full name) that are not in live
            foreach (Arrival sAr in scheduled) {
                bool contains = false;
                foreach (Arrival lAr in liveData) {
                    if (lAr.Destination == sAr.Destination) {//found bus with matching nmae
                        contains = true;
                        break;
                    }
                }
                if (!contains && sAr.Time < DateTime.Now.Add (aheadTime))//also check whether within timeframe
                    masterList.Add (sAr);//add scheduled arrival since live data not tracking that bus
            }
            //merge with livedata that is within after and ahead window
            masterList.AddRange (liveData.Where ((x) => (x.Time > afterTime && x.Time < DateTime.Now.Add (aheadTime))));
            masterList.Sort ();

            results = masterList;
            notify ();
        }
Exemplo n.º 8
0
 private void notify()
 {
     ArrivalEvent e = new ArrivalEvent (results, myStop);
     if (ArrivalsUpdated != null)
         ArrivalsUpdated (this, e);
 }