public void FetchStations(ComboBox s) { WebClient webclient = new WebClient(); webclient.UploadStringCompleted += (obj, arguments) => { StationList = FormatStationJSON(arguments.Result); foreach (var item in StationList) { s.Items.Add(item.AdvertisedLocationName); } }; string requestBody = ImportantVariables.RequestAllStationsQuery(); webclient.Encoding = Encoding.UTF8; webclient.UploadStringAsync(Adress, "POST", requestBody); }
public void FetchArrivalDeparture(ListBox s, string StationShortName) { WebClient webclient = new WebClient(); webclient.UploadStringCompleted += (obj, arguments) => { var ResultList = FormatArrivalDepartureJSON(arguments.Result); ArrivalDepartureList.Clear(); foreach (var result in ResultList) { if (result.TrainAnnouncement != null) { foreach (var train in result.TrainAnnouncement) { if (train.ToLocation != null) { ArrivalDepartureList.Add(train); var time = train.AdvertisedTimeAtLocation.Split('T'); var LocationName = train.ToLocation[0].LocationName; s.Items.Add(time[1].Substring(0, 5) + " TrainNr: " + train.AdvertisedTrainIdent + " To: " + GetStationFullName(LocationName) + " Date: " + time[0].Substring(8, 2) + "/" + time[0].Substring(5, 2) ); } } } } }; Uri address = new Uri(ImportantVariables.APIAdress); string requestBody = ImportantVariables.RequestStationTrainTimesQuery(StationShortName); webclient.Encoding = Encoding.UTF8; webclient.UploadStringAsync(address, "POST", requestBody); }
public void FetchTrainMessages(Label TrainInfoLabel, int TrainNumber, string StationShortName, string ArrivalTime) { WebClient webclient = new WebClient(); webclient.UploadStringCompleted += (obj, arguments) => { var ListOfResult = FormatTrainMessagesJSON(arguments.Result); TrainInfoLabel.Text = "Info: "; foreach (var Tmessage in ListOfResult) { if (Tmessage.LocationSignature == StationShortName && Tmessage.AdvertisedTimeAtLocation == ArrivalTime) { if (Tmessage.Canceled == true) { foreach (var explanation in Tmessage.Deviation) { TrainInfoLabel.Text += explanation + " "; } TrainInfoLabel.Text += Tmessage.WebLink; } else { if (Tmessage.ToLocation != null) { if (Tmessage.ActivityType == "Avgang") { if (Tmessage.EstimatedTimeAtLocation != null) { var newTime = Tmessage.EstimatedTimeAtLocation.Split('T'); TrainInfoLabel.Text += "Estimerad tid: " + newTime[1].Substring(0, 5) + " "; } else { var Time = Tmessage.AdvertisedTimeAtLocation.Split('T'); TrainInfoLabel.Text += "Ankomsttid: " + Time[1].Substring(0, 5) + " "; } var ToLocationName = GetStationFullName(Tmessage.ToLocation[0].LocationName); if (Tmessage.ToLocation[0].LocationName == "No.nk") { ToLocationName = "Narvik"; } TrainInfoLabel.Text += " TrainNr: " + Tmessage.AdvertisedTrainIdent + " mot " + ToLocationName; } } } } } }; Uri address = new Uri(ImportantVariables.APIAdress); string requestBody = ImportantVariables.RequestTrainMessageQuery(TrainNumber); webclient.Encoding = Encoding.UTF8; webclient.UploadStringAsync(address, "POST", requestBody); }