コード例 #1
0
            private static void StoreStations()
            {
                if (trainStations != null)
                    return;

                var client = new TransportTimesClient();
                var dotNetStations = client.GetAllTrainStations();

                var jsonStations = dotNetStations
                                        .Select(stn => new { id = stn.Id, value = stn.Name, label = $"{stn.Name} ({stn.Id})" });
                trainStations = new JavaScriptSerializer().Serialize(jsonStations);
            }
コード例 #2
0
        public void TestGetAllTrainStationsAlt2()
        {
            var sut = new TransportTimesClient();

            var allStations = sut.GetAllTrainStations();

            foreach (var station in allStations)
            {
                Console.WriteLine($"{station.Id} is {station.Name}");
            }

            Assert.IsTrue(allStations.Any(), "expect some stations back from irish rail service");
        }
コード例 #3
0
        public void TestGetTimesForBusStop()
        {
            var sut = new TransportTimesClient();

            var task = sut.GetTimesForBusStop("00608");

            Assert.IsTrue(task.Wait(WebTimoutMs), "timed out waiting for web response");

            var busTimes = task.Result;

            foreach (var bus in busTimes)
            {
                Console.WriteLine($"{bus.Service} to {bus.Destination} due {bus.DueRelative} ({bus.DueAbsolute})");
            }

            Assert.IsTrue(busTimes.Any(), "expect some bus times back from rtpi service");
        }
コード例 #4
0
        public async Task<IDictionary<string, IEnumerable<TransportTime>>> MyTransportTimes()
        {
            var username = identity.GetUserName();
            var client = new TransportTimesClient();
            var result = new Dictionary<string, IEnumerable<TransportTime>>();

            var myJourneys = dbContext.JourneysEager().Where(j => j.UserEmail == username);

            foreach (var journey in myJourneys)
            {
                IEnumerable<TransportTime> times = Array.Empty<TransportTime>();

                foreach (var serviceFilter in journey.DepartureCriteriaCollection)
                {
                    var station = serviceFilter.Station;

                    switch (station.StationType)
                    {
                        case StationType.busStop:
                        case StationType.luasStop:
                            {
                                var t = await client.GetTimesForBusStop(station.ID);
                                times = times.Concat(ApplyServiceListFilter(serviceFilter, t));
                                break;
                            }
                        case StationType.trainStation:
                        {
                                var t = await client.GetTimesForDartStation(station.ID, serviceFilter.Station.Direction.Value);
                                times = times.Concat(ApplyServiceListFilter(serviceFilter, t));
                                break;
                            }
                    }
                }

                result.Add(
                    journey.Name, 
                    times.OrderBy(t => t.Minutes));
            }

            return result;
        }