/// <summary> /// 非同步取得指定列車即時資訊 /// </summary> /// <param name="train">指定列車</param> /// <returns>列車資訊</returns> public static async Task <RealTimeTrainInfo> GetRealTimeTrainInfoAsync(Train train) { if (train.Timetable.Date.Date != DateTime.Now.Date) { throw new InvalidOperationException("來源列車資訊並非來自今日時刻表"); } RealTimeTrainInfo result = new RealTimeTrainInfo(); result.Train = train; string date = DateTime.Now.ToString("yyyy/MM/dd"); result.DataSource = new Uri($"http://twtraffic.tra.gov.tw/twrail/mobile/ie_traindetail.aspx?searchdate={date}&traincode={train.Id}"); await result.RefreshAsync(); return(result); }
/// <summary> /// 非同步取得指定列車即時資訊 /// </summary> /// <param name="train">指定列車</param> /// <returns>列車資訊</returns> public static async Task<RealTimeTrainInfo> GetRealTimeTrainInfoAsync(Train train) { if (train.Timetable.Date.Date != DateTime.Now.Date) { throw new InvalidOperationException("來源列車資訊並非來自今日時刻表"); } RealTimeTrainInfo result = new RealTimeTrainInfo(); result.Train = train; string date = DateTime.Now.ToString("yyyy/MM/dd"); result.DataSource = new Uri($"http://twtraffic.tra.gov.tw/twrail/mobile/ie_traindetail.aspx?searchdate={date}&traincode={train.Id}"); await result.RefreshAsync(); return result; }