コード例 #1
0
ファイル: ParseHelper.cs プロジェクト: nexDevelopment/nexMUNI
        public static async Task<List<Route>> ParsePredictionsAsync(XDocument document)
        {
            var routes = new List<Route>();
            string routeNum;
            IEnumerable<XElement> rootElements;

            //If there was an error getting the xml, return an empty list
            if (document.Root == null) return routes;

            rootElements = document.Element("body").Elements("predictions");
            foreach(XElement predictionElement in rootElements)
            {
                string routeTitle = predictionElement.Attribute("routeTitle").Value;
                routeNum = ParseRouteNum(predictionElement);

                //Check to see if the route has already been added to the collection
                if (!routes.Any(r => r.RouteNumber == routeNum))
                {
                    Route newRoute = new Route(routeTitle, routeNum);

                    var subElement = predictionElement.Element("direction");
                    if (subElement != null)
                    {
                        var dirTitle = subElement.Attribute("title").Value;
                        var times = ParseTimes(subElement);
                        newRoute.Directions.Add(new RouteDirection(dirTitle, times));
                        routes.Add(newRoute);
                    }
                }
                else
                {
                    Route tempRoute = routes.Find(r => r.RouteNumber == routeNum);

                    var subElement = predictionElement.Element("direction");
                    if (subElement != null)
                    {
                        var dirTitle = subElement.Attribute("title").Value;
                        var times = ParseTimes(subElement);
                        tempRoute.Directions.Add(new RouteDirection(dirTitle, times));
                    }

                }   
            }
            return routes;
        }
コード例 #2
0
ファイル: WebHelper.cs プロジェクト: nexDevelopment/nexMUNI
        public static async Task<XDocument> GetSearchPredictionsAsync(Stop stop, Route route)
        {
            var url = baseUrls["searchPrediction"] + stop.stopId + "&routeTag=" + route.RouteNumber;

             //Make sure to pull from the network and not cache everytime predictions are refreshed 
            client.DefaultRequestHeaders.IfModifiedSince = DateTime.Now;
            try
            {
                var response = await client.GetAsync(new Uri(url));
                response.EnsureSuccessStatusCode();
                var reader = await response.Content.ReadAsStringAsync();
                xmlDoc = XDocument.Parse(reader);
            }
            catch (Exception)
            {
                await ErrorHandler.NetworkError("Error getting predictions. Check network connection and try again.");
                throw;
            }

            return xmlDoc;
        }
コード例 #3
0
ファイル: WebHelper.cs プロジェクト: nexDevelopment/nexMUNI
        public async static Task<XDocument> GetBusLocationsAsync(Route route)
        {
            //Because the API requires an epoch time offset for some reason...
            TimeSpan epoch = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            var timestamp = (long)epoch.TotalMilliseconds - TimeSpan.FromMinutes(5).TotalMilliseconds;

            //if (route.Equals("Powell/Mason Cable Car")) route = "59";
            //else if (route.Equals("Powell/Hyde Cable Car")) route = "60";
            //else if (route.Equals("California Cable Car")) route = "61";
            //else if (route.Contains('-'))
            //{
            //    route = route.Substring(0, route.IndexOf('-'));
            //}

            var url = baseUrls["busLocations"] + route.RouteNumber + "&t=" + timestamp;

             try
            {
                var response = await client.GetAsync(new Uri(url));
                response.EnsureSuccessStatusCode();
                string reader = await response.Content.ReadAsStringAsync();
                xmlDoc = await Task.Run(() => XDocument.Parse(reader));
            }
            catch (Exception)
            {
                await ErrorHandler.NetworkError("Error getting route info. Check network connection and try again.");
                return null;
            }

             return xmlDoc;
        }
コード例 #4
0
 public async Task<List<List<BasicGeoposition>>> GetRoutePathAsync(Route route)
 {
     var xmlDoc = await WebHelper.GetRoutePathAsync(route.RouteNumber);
     return await Task.Run(() => MapHelper.ParseRoutePath(xmlDoc));
 }
コード例 #5
0
        public async Task LoadDirectionsAsync(Route route)
        {
            SelectedRoute = route;
            SelectedStop = null;

            //if (route.Equals("Powell/Mason Cable Car")) route = "59";
            //else if (route.Equals("Powell/Hyde Cable Car")) route = "60";
            //else if (route.Equals("California Cable Car")) route = "61";
            //else
            //{
            //    route = route.Substring(0, route.IndexOf('-'));
            //}

            try {
                var xmlDoc = await WebHelper.GetRouteDirections(route.RouteNumber);

                if (xmlDoc != null)
                {
                    DirectionsList = await Task.Run(() => ParseHelper.ParseDirections(xmlDoc));
                    allStopsList = await Task.Run(() => ParseHelper.ParseStops(xmlDoc));
                    await Task.Run(() => ParseHelper.ParseStopTags(xmlDoc, inboundStops, outboundStops));
                }
            } 
            catch (Exception)
            {
                throw;
            }
   
        }
コード例 #6
0
 public RouteMapViewModel(Route route)
 {
     SelectedRoute = route;
 }