Exemplo n.º 1
0
 /// <summary>
 /// Get data from NOW including LIVE data (when network online)
 /// </summary>
 public ArrivalMonitor(BusStop stop) : this(stop, DateTime.Now)
 {
     liveMode = true;
     db       = BusDB_GTFS_SQL.Instance;
     fetcher  = new LiveArrivalFetcher(myStop);
     fetcher.ArrivalsUpdated += new LiveArrivalFetcher.ArrivalObserver(receiveLiveResults);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Get data from NOW including LIVE data (when network online)
 /// </summary>
 public ArrivalMonitor(BusStop stop)
     : this(stop, DateTime.Now)
 {
     liveMode = true;
     db = BusDB_GTFS_SQL.Instance;
     fetcher = new LiveArrivalFetcher (myStop);
     fetcher.ArrivalsUpdated += new LiveArrivalFetcher.ArrivalObserver (receiveLiveResults);
 }
Exemplo n.º 3
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.º 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
 public void SetUp()
 {
     fetcher = new LiveArrivalFetcher(new BusStop("Colony Manor", 3382, new MonoTouch.CoreLocation.CLLocation(40,-70)));
 }