Пример #1
0
 public override bool Equals(object obj)
 {
     if (obj is RouteSpec)
     {
         RouteSpec rs = (RouteSpec)obj;
         return(Source.Equals(rs.Source) && Destination.Equals(rs.Destination));
     }
     else
     {
         return(false);
     }
 }
Пример #2
0
        public static List <RouteStep> Get(RouteSpec spec, bool store)
        {
            bool generate = false;

            if (routes.ContainsKey(spec))
            {
                if (DateTime.Now - routes[spec].Item2 > RouteTimeout)
                {
                    generate = true;
                }
            }
            else
            {
                generate = true;
            }

            if (generate)
            {
                List <RouteStep>   route      = new List <RouteStep>();
                DirectionsResponse directions = DirectionsResponse.Get(spec.Source, spec.Destination);
                if (directions.Routes.Count > 0)
                {
                    // TODO: Consider equivalent Linq
                    foreach (Leg leg in directions.Routes[0].Legs)
                    {
                        foreach (Step step in leg.Steps)
                        {
                            route.Add(new RouteStep()
                            {
                                Start    = step.StartLocation,
                                End      = step.EndLocation,
                                Distance = step.Distance.Value,
                                Duration = TimeSpan.FromSeconds(step.Duration.Value),
                                Polyline = step.Polyline
                            });
                        }
                    }
                    routes[spec] = new Tuple <List <RouteStep>, DateTime>(route, DateTime.Now);
                }
                return(new List <RouteStep>(route));
            }

            return(new List <RouteStep>(routes[spec].Item1));

            // Return copy of route, as the list is modified by the things that use it.
        }