Ejemplo n.º 1
0
        private static void ExtractTimetableTimes(XmlNodeList mainNodes, List <KeyValuePair <int, int> > timetableLineOrder, List <RouteStop> timetableStops)
        {
            foreach (XmlElement vehicleTypeNode in mainNodes)
            {
                int vehicleTypeID = int.Parse(vehicleTypeNode.Attributes["id"].Value);

                foreach (XmlElement stopRef in vehicleTypeNode)
                {
                    RouteStop currentRouteStop = new RouteStop();
                    int       currentStopID    = int.Parse(stopRef.Attributes["id"].Value);

                    currentRouteStop.PublicID = currentStopID;

                    foreach (XmlElement lineRef in stopRef)
                    {
                        int    lineID       = int.Parse(lineRef.Attributes["id"].Value);
                        string lineSchedule = lineRef.InnerText;

                        var currentLineSchedule = SplitTimeNode(lineSchedule, lineID);

                        currentRouteStop.LineToStopSchedule.Add(currentLineSchedule);

                        var lineIDAndVehicleType = new KeyValuePair <int, int>(lineID, vehicleTypeID);
                        if (!timetableLineOrder.Contains(lineIDAndVehicleType))
                        {
                            timetableLineOrder.Add(lineIDAndVehicleType);
                        }
                    }

                    timetableStops.Add(currentRouteStop);
                }
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }