Example #1
0
        public void OnListItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            try
            {
                if (e.SelectedItem != null)
                {
                    var SelectedStation = (StationName)e.SelectedItem;

                    foreach (var station in MainPage.IrishStationList.ObjStation)
                    {
                        if (station.StationDesc == SelectedStation.TrainStationName.ToString() || SelectedStation.TrainStationName.ToString().Contains(station.StationDesc, StringComparison.InvariantCultureIgnoreCase))
                        {
                            PickedStation          = station.StationDesc;
                            PickedStationLatitude  = Convert.ToDouble(station.StationLatitude);
                            PickedStationLongitude = Convert.ToDouble(station.StationLongitude);
                            TrainData = StationData.GetStationTrains(station.StationCode);
                            if (TrainData.ObjStationData.Count > 0)
                            {
                                App.Current.MainPage = new TrainList();
                            }
                            else
                            {
                                DisplayAlert("No Train details are available", "Try a different station", "Ok");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public static ArrayOfObjStationData GetStationTrains(string code)
        {
            ArrayOfObjStationData StationTrainList = new ArrayOfObjStationData();
            XmlDocument           maindoc          = new XmlDocument();

            using (var httpClient = CreateClient())
            {
                string URL = "http://api.irishrail.ie/realtime/realtime.asmx/getStationDataByCodeXML?StationCode=" + code;
                maindoc.Load(URL);
                XmlSerializer serializer =
                    new XmlSerializer(typeof(ArrayOfObjStationData));
                using (var reader = new StringReader(maindoc.InnerXml))
                {
                    StationTrainList = (ArrayOfObjStationData)serializer.Deserialize(reader);
                }
                return(StationTrainList);
            }
        }