Пример #1
0
        private static RTPIData TransformServiceData(JObject jsonResults)
        {
            RTPIData data = new RTPIData
            {
                StopName   = (string)jsonResults["stopid"],
                Message    = (string)jsonResults["errormessage"],
                Directions = new List <RTPIDirection>
                {
                    new RTPIDirection
                    {
                        Name     = "Inbound",
                        Arrivals = (from result in jsonResults["results"]
                                    where (string)result["direction"] == "Inbound"
                                    select ExtractArrivalDetails(result))
                                   .ToList()
                    },
                    new RTPIDirection
                    {
                        Name     = "Outbound",
                        Arrivals = (from result in jsonResults["results"]
                                    where (string)result["direction"] == "Outbound"
                                    select ExtractArrivalDetails(result))
                                   .ToList()
                    }
                }
            };

            return(data);
        }
Пример #2
0
        public async Task <RTPIData> GetRTPIForStop(string stopId)
        {
            RTPIData data = new RTPIData {
                Error = "Found no arrivals for stop"
            };

            var encodedStopId = WebUtility.UrlEncode(stopId);
            // TODO: pull this out of code
            string address = $"https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation?stopid={encodedStopId}&format=json";

            var response = await _http.GetData(address);

            var rawJson = await response.Content.ReadAsStringAsync();

            try
            {
                var jsonResults = JObject.Parse(rawJson);
                data = TransformServiceData(jsonResults);
            }
            catch (JsonException)
            {
                // Failed to parse the JSON, give the user an error.
            }

            return(data);
        }
Пример #3
0
        public async Task <RTPIData> GetRTPIForStop(string stopId)
        {
            RTPIData data = new RTPIData {
                Error = "Found no arrivals for stop"
            };

            var encodedStopId = WebUtility.UrlEncode(stopId);
            // TODO: pull this out of code
            string address = $"http://luasforecasts.rpa.ie/xml/get.ashx?action=forecast&encrypt=false&stop={encodedStopId}";

            var response = await _http.GetData(address);

            using (Stream rawResponse = await response.Content.ReadAsStreamAsync())
            {
                var xml = new XmlSerializer(typeof(LUASStopInfo));
                try
                {
                    var LUASData = xml.Deserialize(rawResponse) as LUASStopInfo;
                    if (LUASData != null)
                    {
                        data = TransformServiceData(LUASData);
                    }
                }
                catch (InvalidOperationException)
                {
                    // The LUAS API returns a plain string error message if it can not find the stop
                    // this will break the deserialization, just fall trough with error set above.
                }
            }

            return(data);
        }
Пример #4
0
        private static RTPIData TransformServiceData(LUASStopInfo stopInfo)
        {
            RTPIData data = new RTPIData
            {
                Message    = stopInfo.ServiceMessage,
                StopName   = stopInfo.LongName,
                ValidTime  = stopInfo.Created,
                Directions = (from direction in stopInfo.Directions
                              select new RTPIDirection
                {
                    Name = direction.DirectionName,
                    Arrivals = (from arrival in direction.Arrivals
                                select new RTPIArrival
                    {
                        Destination = arrival.Destination,
                        DueIn = ConvertLUASArrivalStringToDateTime(arrival.DueMins)
                    }).ToList()
                }).ToList()
            };

            return(data);
        }