/// <summary> /// Gets collection of the stations. /// </summary> /// <param name="station">Wanted station.</param> /// <returns></returns> /// <exception cref="DataNotFoundException"/> /// <exception cref="WrongDataProvidedException"/>> /// <exception cref="WebException"/> /// <exception cref="ArgumentException"/> public IEnumerable <Station> GetStations(string station) { try { //Get html document of the stations var doc = PkpPageInfo.GetHtmlDocumentOfStations(station); //Get table with all found stations var table = GetTable(doc.DocumentNode); //Collection with stations to return List <Station> coll_stations = new List <Station>(); //Get all rows from the table foreach (HtmlNode row in table.SelectNodes("tr") ?? throw new NodeNotFoundException("Rows were not found")) { //Get all cells from the current row foreach (HtmlNode cell in row.SelectNodes("td") ?? throw new NodeNotFoundException("Cells were not found")) { //Remove unnecessary white spaces. string trimed = cell.InnerText.Trim(); //Get value from onlick attribute string id = cell.GetAttributeValue("onclick", "Not found"); //If it's not found then throw the exception if (id == "Not found") { throw new NodeAttributeNotFoundException("Onclick was not found"); } //Get the train id from the value id = id.Substring(id.IndexOf("id=") + 3); //add station to the collection coll_stations.Add(new Station(trimed, id)); } } return(coll_stations); } catch (ArgumentException ex) //It occurs when the station has not been found { throw new WrongDataProvidedException("The station name was not found", ex); } catch (Exception ex) //Other exceptions are expected and about not finding data { //So check the thrown exception if it's a type of any those ones if (ex is NodeNotFoundException || ex is NodeAttributeNotFoundException || ex is ArgumentOutOfRangeException) { throw new DataNotFoundException(ex); //and throw it } throw ex; } }
/// <summary> /// Gets <see cref="DelayInfoCollection{TBy, TData}"/> in regard of the given station /// </summary> /// <exception cref="DataNotFoundException"/> /// <exception cref="WebException"/> public DelayInfoCollection <Station, IDelayInfo <Station> > GetStationDelayInfos(Station station) { try { //get html document of the trains by the given station with their delay time. var doc = PkpPageInfo.GetHtmlDocumentOfDelayedTrains(station.StationID); //get table that contains trains with delay time. var tables = GetMultipleTables(doc.DocumentNode); //Helper variables string trainName = string.Empty, id = string.Empty, host = string.Empty, from = string.Empty, destination = string.Empty; DateTime date = default; TimeSpan?planned = default, delay = null;