예제 #1
0
        public static StationForecast CreateStationForecastFromRealTimeInfo(RealTimeInfo realTimeInfo, Stations stations)
        {
            if (realTimeInfo == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument '{0}' is null.", nameof(realTimeInfo)));
            }
            if (stations == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Argument '{0}' is null.", nameof(stations)));
            }

            List <TramXml> inboundForecasts  = realTimeInfo.Directions.FirstOrDefault(d => d.DirectionName == "Inbound").Trams;
            List <TramXml> outboundForecasts = realTimeInfo.Directions.FirstOrDefault(d => d.DirectionName == "Outbound").Trams;

            StationForecast stationForecast = new StationForecast
            {
                Station       = stations.GetStation(realTimeInfo.StopAbbreviation),
                Message       = realTimeInfo.Message,
                Created       = realTimeInfo.Created,
                InboundTrams  = inboundForecasts.Select(tram => TramForecast.CreateTramForecastFromTramXml(tram, stations)).Where(forecast => forecast != null).ToList(),
                OutboundTrams = outboundForecasts.Select(tram => TramForecast.CreateTramForecastFromTramXml(tram, stations)).Where(forecast => forecast != null).ToList()
            };

            return(stationForecast);
        }
예제 #2
0
        public static TramForecast CreateTramForecastFromTramXml(TramXml tramXml, Stations stations)
        {
            if (tramXml?.Destination == "No trams forecast" && string.IsNullOrEmpty(tramXml.Destination))
            {
                return(null);
            }

            if (stations == null)
            {
                throw new ArgumentNullException(nameof(stations));
            }

            if (!int.TryParse(tramXml.DueMins, out int dueMinutes))
            {
                dueMinutes = 0;
            }

            try
            {
                Station destinationStation = stations.GetStationFromName(tramXml.Destination);

                TramForecast tramForecast = new TramForecast
                {
                    DestinationStation = destinationStation,
                    Minutes            = dueMinutes,
                    IsDue = dueMinutes == 0
                };

                return(tramForecast);
            }
            catch (StationNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(null);
        }