Beispiel #1
0
        public RouteConfig ParseRouteConfig(string xml)
        {
            XDocument document = XDocument.Parse(xml);

            if (document.Root == null)
            {
                return null;
            }

            TryParseError(document.Root);

            XElement routeElement = document.Root.Element("route");

            if (routeElement == null)
            {
                return null;
            }

            var route = new RouteConfig
                            {
                                Tag = routeElement.Attr("tag"),
                                Title = routeElement.Attr("title"),
                                Color = routeElement.Attr("color"),
                                OppositeColor = routeElement.Attr("oppositeColor"),
                                LatMin = routeElement.Attr("latMin").ToDecimal(),
                                LatMax = routeElement.Attr("latMax").ToDecimal(),
                                LonMin = routeElement.Attr("lonMin").ToDecimal(),
                                LonMax = routeElement.Attr("lonMax").ToDecimal()
                            };

            route.Stops = routeElement.Elements("stop").Select(x => new Stop
                                                                        {
                                                                            Tag = x.Attr("tag"),
                                                                            Title = x.Attr("title"),
                                                                            Lat = x.Attr("lat").ToDecimal(),
                                                                            Lon = x.Attr("lon").ToDecimal(),
                                                                            StopId = x.Attr("stopId").ToInt()
                                                                        }).ToList();

            IEnumerable<Direction> directions = from x in routeElement.Elements("direction")
                                                select new Direction
                                                           {
                                                               Tag = x.Attr("tag"),
                                                               Title = x.Attr("title"),
                                                               Name = x.Attr("name"),
                                                               UserForUI = x.Attr("useForUI").ToBool(),
                                                               Stops = (from y in route.Stops
                                                                        where
                                                                            x.Elements("stop").Select(u => u.Attr("tag"))
                                                                            .Contains(y.Tag)
                                                                        select y).ToList()
                                                           };

            route.Directions = directions.ToList();

            List<Path> paths = routeElement.Elements("path").Select(x => new Path
                                                                             {
                                                                                 Points =
                                                                                     x.Elements("point").Select(
                                                                                         y => new Point
                                                                                                  {
                                                                                                      Lat = y.Attr("lat").ToDecimal(),
                                                                                                      Lon = y.Attr("lon").ToDecimal()
                                                                                                  }).ToList()
                                                                             }).ToList();

            route.Paths = paths;

            return route;
        }
Beispiel #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(RouteConfig other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Tag, Tag);
 }
Beispiel #3
0
 private async void MainViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "SelectedRoute")
     {
         _routeConfig = await _client.GetRouteConfig("ttc", SelectedRoute.Tag);
         Directions.Clear();
         Stops.Clear();
         Predictions.Clear();
         foreach (var direction in _routeConfig.Directions)
         {
             Directions.Add(direction);
         }
     }
     else if (e.PropertyName == "SelectedDirection" && SelectedDirection != null)
     {
         Stops.Clear();
         foreach (var stop in SelectedDirection.Stops)
         {
             Stops.Add(stop);
         }
     }
     else if (e.PropertyName == "SelectedStop")
     {
         UpdatePredictions();
     }
 }