/// <summary> /// Returns list of connectioins. /// Returns false if something went wrong. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="connectionList"></param> /// <returns></returns> public bool GetConnectionList(string from, string to, ref List <Connection> connectionList) { m_ErrorState = STHErrorState.NONE; if (String.IsNullOrEmpty(from) || String.IsNullOrEmpty(to)) { return(false); } connectionList = m_Transport.GetConnections(from, to).ConnectionList; if (connectionList.Count < 0) { return(false); } return(true); }
/// <summary> /// /// Returns false if soemthing went wrong /// </summary> /// <param name="stationName"></param> /// <param name="date"></param> /// <param name="time"></param> /// <param name="entries"></param> /// <returns></returns> public bool GetStationBoard(string stationName, DateTime date, DateTime time, ref List <StationBoard> entries) { m_ErrorState = STHErrorState.NONE; string dateTime = date.ToString("yyyy-MM-dd") + time.ToString("HH:mm"); string id = m_Transport.GetStations(stationName).StationList.ElementAt(0).Id; // Abusing id parameter StationBoardRoot stationBoardRoot = m_Transport.GetStationBoard(stationName, id, dateTime); entries = stationBoardRoot.Entries; if (entries.Count <= 0) { m_ErrorState = STHErrorState.ListNullOrEmpty; return(false); } return(true); }
/// <summary> /// Shows Station Location in Google Maps. /// Returns false if something went wrong /// </summary> /// <param name="station"> Station arguments needs the name of the Station you want to show a Map. </param> /// <returns></returns> public bool MapView(string station) { m_ErrorState = STHErrorState.NONE; if (string.IsNullOrEmpty(station)) { m_ErrorState = STHErrorState.ArgumentNullOrEmpty; return(false); } Coordinate statoinCoord = m_Transport.GetStations(station).StationList.ElementAt(0).Coordinate; double x = statoinCoord.XCoordinate; double y = statoinCoord.YCoordinate; String xStr = Convert.ToString(x).Replace(',', '.'); String yStr = Convert.ToString(y).Replace(',', '.'); System.Diagnostics.Process.Start("http://www.google.ch/maps/place/" + xStr + "," + yStr); return(true); }
/// <summary> /// Formats Duration. /// Returns empty string if something went wrong /// </summary> /// <param name="test"></param> /// <returns></returns> public string FormateDuration(string test) { m_ErrorState = STHErrorState.NONE; string formatedDuration = test; var split1 = formatedDuration.Split('d'); if (split1.Length < 1) { return(""); } var split2 = split1[1].Split(':'); if (split2.Length < 2) { return(""); } return(split1[0] + "t " + split2[0] + "h " + split2[1] + "m " + split2[2] + "s"); }
/// <summary> /// Returns list of found connections. /// Returns false if something went wrong. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="date"></param> /// <param name="time"></param> /// <param name="connectionList"></param> /// <returns></returns> public bool GetConnectionList(string from, string to, DateTime date, DateTime time, ref List <Connection> connectionList) { m_ErrorState = STHErrorState.NONE; if (String.IsNullOrEmpty(from) || String.IsNullOrEmpty(to)) { m_ErrorState = STHErrorState.ArgumentNullOrEmpty; return(false); } string dateTime = date.ToString("yyyy-MM-dd") + time.ToString("HH:mm"); connectionList = m_Transport.GetConnections(from, to, dateTime).ConnectionList; if (connectionList.Count < 0) { m_ErrorState = STHErrorState.ListNullOrEmpty; return(false); } return(true); }
/// <summary> /// Gets list of station names. /// Returns false if something went wrong. /// </summary> /// <param name="stationName"></param> /// <param name="list"></param> /// <returns></returns> public bool GetStationNames(string stationName, ref List <string> list) { m_ErrorState = STHErrorState.NONE; if (String.IsNullOrEmpty(stationName)) { m_ErrorState = STHErrorState.ArgumentNullOrEmpty; return(false); } // Api sends only up to 10 results, chance to evaluate the right station by 2 letters is too low to show if (stationName == null || stationName.Length <= 1) { m_ErrorState = STHErrorState.ListNullOrEmpty; return(false); } var stationList = m_Transport.GetStations(stationName).StationList; if (stationList == null) { return(false); } if (stationList.Count <= 0) { m_ErrorState = STHErrorState.ListNullOrEmpty; return(false); } var stationNames = new List <string>(); foreach (Station station in stationList) { stationNames.Add(station.Name); } list.Clear(); list = stationNames; return(true); }