Ejemplo n.º 1
0
 public void initArrivalCache()
 {
     //Set the arrival times of all routes at all stops to be --.
     //TODO - be smarter about this.
     arrivalCache.Clear();
     foreach (long currRouteID in selectedRoutes)
     {
         foreach (long currStopID in routeCache[currRouteID].stops)
         {
             ArrivalInfo arrivalInfo = new ArrivalInfo();
             arrivalInfo.ArrivalTimes = "--";
             arrivalInfo.RouteColor = '#' + routeCache[currRouteID].color;
             arrivalInfo.RouteShortName = routeCache[currRouteID].short_name;
             arrivalInfo.RouteName = routeCache[currRouteID].long_name;
             if (arrivalCache.ContainsKey(currStopID))
             {
                 arrivalCache[currStopID].Add(currRouteID, arrivalInfo);
             }
             else
             {
                 arrivalCache.Add(currStopID, new Dictionary<long, ArrivalInfo>());
                 arrivalCache[currStopID].Add(currRouteID, arrivalInfo);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void ReadArrivalCallback(IAsyncResult asynchronousResult)
        {
            string resultString = Util.ProcessCallBack(asynchronousResult);
            if (resultString != null)
            {
                var arrivalsroot = JsonConvert.DeserializeObject<ArrivalRoot>(resultString);
                DateTime currTime = DateTime.Now;

                Dictionary<long, Route> routeCacheRef = App.ViewModel.routeCache;
                Dictionary<long, Dictionary<long, ArrivalInfo>> arrivalCacheRef = App.ViewModel.arrivalCache;

                foreach (var stoparrival in arrivalsroot.data)
                {
                    long stopID = stoparrival.stop_id;
                    foreach (var arrival in stoparrival.arrivals)
                    {
                        DateTime rawArrivalTime = DateTime.Parse(arrival.arrival_at);
                        TimeSpan timeDiff = rawArrivalTime - currTime;

                        //string arrivalTime = DateTime.Parse(arrival.arrival_at).ToShortTimeString();
                        string arrivalTime;
                        if (timeDiff.Minutes < 1)
                        {
                            arrivalTime = "< 1 min";
                        }
                        else
                        {
                            arrivalTime = timeDiff.Minutes.ToString() + " mins";
                        }
                        //string routeName = routeCacheRef[arrival.route_id].short_name + " - " + routeCacheRef[arrival.route_id].long_name;
                        long routeID = arrival.route_id;

                        if (arrivalCacheRef[stopID][routeID].ArrivalTimes != "--")
                        {
                            (arrivalCacheRef[stopID])[routeID].ArrivalTimes += ", " + arrivalTime;
                        }
                        else
                        {
                            ArrivalInfo arrivalInfo = new ArrivalInfo();
                            arrivalInfo.RouteName = routeCacheRef[routeID].long_name;
                            arrivalInfo.RouteShortName = routeCacheRef[routeID].short_name;
                            arrivalInfo.RouteColor = '#' + routeCacheRef[routeID].color;
                            arrivalInfo.ArrivalTimes = arrivalTime;
                            (arrivalCacheRef[stopID])[routeID] = arrivalInfo;
                        }
                    }
                }
                /*StringBuilder contents = new StringBuilder();
                foreach (long StopID in arrivalCache.Keys)
                {
                    contents.Append("\n" + StopID.ToString());
                    foreach (string RouteName in arrivalCache[StopID].Keys)
                    {
                        contents.Append(" " + RouteName.ToString() + ":" + arrivalCache[StopID][RouteName]);
                    }
                }
                cleanUpStops();
                //TODO - remove this bullshit way of doing this, and use await() instead.
                if (App.ViewModel.selectedRoutesNames.Count > 0 && App.ViewModel.stops.Count == 0)
                {
                    string route = App.ViewModel.selectedRoutesNames[0];
                    App.ViewModel.addArrivalsForRoute(route);
                }*/
                App.ViewModel.updateStops();
            }
        }