private async Task AddEstimatedTimeAndBus(int id, Route route, string startName, string stopName) { var tempTimes = await PtxAPI.GetEstimatedTime(@route.RouteName.Zh_tw); lock (new object()) { var tempArrivalTime = new List <string>(); var allTime = tempTimes.FindAll(t => t.RouteID == route.RouteID && t.EstimateTime.HasValue); allTime.FindAll(x => x.StopName.Zh_tw == stopName).OrderBy(y => y.EstimateTime.Value).ToList().ForEach( x => { var sec = TimeSpan.FromSeconds(Convert.ToDouble(x.EstimateTime.Value)); if (sec.TotalSeconds < 10) { tempArrivalTime.Add($"即將進站"); } else { tempArrivalTime.Add($"{sec.Minutes:D2}分{sec.Seconds:D2}秒"); } }); while (tempArrivalTime.Count < 2) { tempArrivalTime.Add("暫無資訊"); } AddBusToXaml(id, route, startName, stopName, tempArrivalTime); } }
private async Task <string> RefreshEstimatedTime(TransferBus bus) { var tempTimes = await PtxAPI.GetEstimatedTime(bus.Route.RouteName.Zh_tw); var tempArrivalTime = new List <string>(); var allTime = tempTimes.FindAll(t => t.RouteID == bus.Route.RouteID && t.EstimateTime.HasValue); allTime.FindAll(x => x.StopName.Zh_tw == bus.EndStop.Substring(3)).OrderBy(y => y.EstimateTime.Value).ToList().ForEach( x => { var sec = TimeSpan.FromSeconds(Convert.ToDouble(x.EstimateTime.Value)); if (sec.TotalSeconds < 10) { tempArrivalTime.Add($"即將進站"); } else { tempArrivalTime.Add($"{sec.Minutes:D2}分{sec.Seconds:D2}秒"); } }); while (tempArrivalTime.Count < 2) { tempArrivalTime.Add("暫無資訊"); } return($"第一班車:{tempArrivalTime[0]}\r\n第二班車:{tempArrivalTime[1]}"); }