public async void Initialize(string ritId, string company, string trein, string richting, string stationCode) { PageName = trein; Richting = _resourceLoader.GetString("RitInfoViewModelRichting") + " " + richting; RitStops = new List <RitInfoStop>(); RitStops = await DataLoader.LoadAsync(async() => { var serviceInfo = await RitnummerService.GetRit(ritId, company, DateTime.Now); List <RitInfoStop> stops = null; if (serviceInfo.FirstOrDefault() != null) { stops = serviceInfo.First().Stops; //Fill station name for each stop foreach (var stop in stops) { var station = StationNameService.GetStationByCode(stop.Code); if (station != null) { stop.Station = station.Name; } if (stop.Code.ToLower() == stationCode.ToLower()) { stop.IsCurrent = true; } } } return(stops); }); if (RitStops == null || !RitStops.Any()) { RitStops = null; DataLoader.LoadingState = LoadingState.Error; } if (RitStops != null && RitInfoAvailable != null) { RitInfoAvailable(null, null); } }
public async void Initialize(string ritId, string company, string trein, string richting, string stationCode) { PageName = trein; if (!string.IsNullOrEmpty(richting)) { Richting = AppResources.RitInfoViewModelRichting + " " + richting; } RitStops = new List <RitInfoStop>(); TreinInfo = null; _stationCode = stationCode; var ritStopsLoader = DataLoader.LoadAsync(async() => { var serviceInfo = await RitnummerService.GetRit(ritId, company, DateTime.Now); List <RitInfoStop> stops = null; if (serviceInfo.FirstOrDefault() != null) { stops = serviceInfo.First().Stops; //Fill station name for each stop foreach (var stop in stops) { var station = StationNameService.GetStationByCode(stop.Code); if (station != null) { stop.Station = station.Name; } if (stop.Code.ToLower() == stationCode.ToLower()) { stop.IsCurrent = true; _vertrekTijd = stop.Departure; } } } return(stops); }); //Start loading treinfo (but dont await yet) var treinInfoLoader = RitnummerService.GetTreinInfo(ritId); RitStops = await ritStopsLoader; if (RitStops == null || !RitStops.Any()) { RitStops = null; DataLoader.LoadingState = LoadingState.Error; } if (RitStops != null && RitInfoAvailable != null) { RitInfoAvailable(null, null); } try { //Optional Treinfo TreinInfo = await treinInfoLoader; } catch { } }