private void CleanUpDepartures(StopAreaViewModel stopArea, StopPointViewModel stopPoint) { foreach (var departure in stopPoint.Where(d => IsOverdue(d.Time)).ToArray()) { stopPoint.Remove(departure); logger.LogDebug($"Removed Departure {departure.Name} {departure.Towards} with {departure.RunNo} from StopPoint {stopPoint.Name} in StopArea {stopArea.Name}"); } }
private void SortDeparturesByDepartureTime(StopAreaViewModel stopArea, StopPointViewModel stopPoint) { if (!stopPoint.OrderBy(x => x.Time).SequenceEqual(stopPoint)) { stopPoint.SortBy(x => x.Time); logger.LogDebug($"Sorted Departures at StopPoint {stopPoint.Name} in StopArea {stopArea.Name}"); } }
private async Task UpdateDepartures(StopAreaViewModel stopArea, Data.StopPoint fetchedStopPoint, StopPointViewModel stopPoint) { foreach (var fetchedDeparture in fetchedStopPoint.Departures.Take(GetDepartureCacheLimit())) { var departure = stopPoint.FirstOrDefault(x => x.RunNo == fetchedDeparture.RunNo); if (departure == null) { // INFO: Make sure we don't add back a deleted Departure. if (IsOverdue(fetchedDeparture.DepartureTime)) { continue; } departure = await departureVmFactory.CreateViewModelAsync(fetchedDeparture).ConfigureAwait(true); await UpdateDeviations(fetchedDeparture, departure).ConfigureAwait(true); stopPoint.Add(departure); logger.LogDebug($"Added Departure {departure.Name} {departure.Towards} with {departure.RunNo} to StopPoint {stopPoint.Name} in StopArea {stopArea.Name}"); } else { await departureVmFactory.UpdateViewModelAsync(fetchedDeparture, departure).ConfigureAwait(true); await UpdateDeviations(fetchedDeparture, departure).ConfigureAwait(true); logger.LogDebug($"Updated Departure {departure.Name} {departure.Towards} with {departure.RunNo} to StopPoint {stopPoint.Name} in StopArea {stopArea.Name}"); } } }