示例#1
0
        private static void GetStops(XmlNode stopsNode, List <RouteStop> stops)
        {
            foreach (XmlElement stop in stopsNode)
            {
                int          stopID       = int.Parse(stop.Attributes["id"].Value);
                int          stopCode     = int.Parse(stop.Attributes["code"].Value);
                string       stopName     = stop.Attributes["publicName"].Value;
                StopLocation stopLocation = new StopLocation(stop.Attributes["lat"].Value, stop.Attributes["lon"].Value);

                RouteStop currentStop = new RouteStop(stopID, stopName);
                currentStop.Code            = stopCode;
                currentStop.DefaultLocation = stopLocation;
                stops.Add(currentStop);
            }
        }
示例#2
0
        private static void GetLines(XmlNode linesNode, int currentIDNumeric, List <RouteLine> lines, List <RouteStop> stops)
        {
            foreach (XmlElement line in linesNode)
            {
                int       lineID      = int.Parse(line.Attributes["id"].Value);
                string    lineName    = line.Attributes["publicName"].Value;
                RouteLine currentLine = new RouteLine(lineID, lineName, currentIDNumeric);
                lines.Add(currentLine);

                foreach (XmlElement route in line)
                {
                    int    currentRouteID   = int.Parse(route.Attributes["route_id"].Value);
                    string currentRouteName = route.Attributes["publicName"].Value;

                    Route currentRoute = new Route(currentRouteID, currentRouteName);

                    var currentChildNode = route.ChildNodes[0];
                    int currentChildID   = int.Parse(currentChildNode.Attributes["id"].Value);

                    RouteStop currentStop = null;
                    try
                    {
                        var tempStop = stops.Where(x => x.PublicID == currentChildID).First();
                        currentStop = tempStop.Clone() as RouteStop;
                    }
                    catch (InvalidOperationException)
                    {
                        currentStop = new RouteStop(currentChildID, "MISSING!");
                    }

                    for (int i = 1; i < route.ChildNodes.Count; i++)
                    {
                        if (route.ChildNodes[i].Name == "stopRef")
                        {
                            currentRoute.Stops.Add(currentStop);
                            currentChildNode = route.ChildNodes[i];
                            currentChildID   = int.Parse(currentChildNode.Attributes["id"].Value);
                            try
                            {
                                var tempStop = stops.Where(x => x.PublicID == currentChildID).First();
                                currentStop = tempStop.Clone() as RouteStop;
                            }
                            catch (InvalidOperationException)
                            {
                                currentStop = new RouteStop(currentChildID, "MISSING!");
                            }
                        }
                        else
                        {
                            string lat = route.ChildNodes[i].Attributes["lat"].Value;
                            string lon = route.ChildNodes[i].Attributes["lon"].Value;

                            StopLocation currentStopLocation = new StopLocation(lat, lon);
                            currentStop.StopLocations.Add(currentStopLocation);
                        }
                    }

                    currentRoute.Stops.Add(currentStop);
                    currentLine.LineRoute.Add(currentRoute);
                }
            }
        }