示例#1
0
        private ITrainRoute GetTrainRoute(IFavouriteRoute favouriteRoute)
        {
            var routeRepository  = new RouteStopRepository();
            var cachedTrainRoute = routeRepository.Find(favouriteRoute.FromId, favouriteRoute.ToId);

            if (cachedTrainRoute != null)
            {
                return(cachedTrainRoute);
            }
            var stationRoutesQuery = new ApiQuery <Route>(_settingsProvider);
            var routes             = stationRoutesQuery.Query(string.Format("/query/station/{0}", favouriteRoute.FromId));

            foreach (var route in routes)
            {
                var routeQuery = new ApiQuery <TrainRoute>(_settingsProvider);
                var queryUri   = string.Format("/query/date/{0}/route/{1}/from/{2}/to/{3}", route.Date, int.Parse(route.RouteNo),
                                               favouriteRoute.FromId, favouriteRoute.ToId);
                var trainRoutes = routeQuery.Query(queryUri);
                if (trainRoutes.Any())
                {
                    var trainRoute = trainRoutes.First();
                    if (!string.IsNullOrWhiteSpace(trainRoute.FromStation.StationName) &&
                        !string.IsNullOrWhiteSpace(trainRoute.ToStation.StationName))
                    {
                        routeRepository.Add(trainRoute);
                    }
                    return(trainRoute);
                }
            }
            return(null);
        }
示例#2
0
 public LineManager(
     LineRepository lineRepository,
     StopManager stopManager,
     RouteStopRepository routeStopRepository,
     DepartureRepository departureRepository,
     LineValidator lineValidator,
     LineCorrector lineCorrector,
     LineFactory lineFactory)
 {
     _lineRepository      = lineRepository;
     _stopManager         = stopManager;
     _routeStopRepository = routeStopRepository;
     _lineValidator       = lineValidator;
     _departureRepository = departureRepository;
     _lineCorrector       = lineCorrector;
     _lineFactory         = lineFactory;
 }