private void FavoritesButtonClicked(object sender, EventArgs e) { try { Structures.Basic.StationsBasic.StationBasic station = Request.GetStationFromString(stopEntry.Text); if (station == null) { PlatformDependentSettings.ShowMessage(Settings.Localization.UnableToFindStation + ": " + stopEntry.Text); return; } if (StationInfoCached.Select(station.ID) != null) { return; } var fav = new StationInfoCached(station.ID); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Request.CacheDepartureBoardAsync(fav.ConstructNewRequest()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed favoritesStackLayout.Children.Add(new FavoriteItemContentView(favoritesStackLayout, scrollView, fav, stopEntry)); } catch { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Request.CheckBasicDataValidity(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } }
public FindStationInfoPage() { InitializeComponent(); BindingContext = new FindStationInfoPageViewModel(); foreach (var cached in StationInfoCached.FetchStationInfoData()) { favoritesStackLayout.Children.Add(new FavoriteItemContentView(favoritesStackLayout, scrollView, cached, stopEntry)); } }
private static async Task <DepartureBoardResponse> SendDepartureBoardRequestAsync(StationInfoRequest dbRequest, bool forceCache = false) { DepartureBoardResponse dbResponse = null; using (var dbProcessing = new DepartureBoardProcessing()) { var cached = StationInfoCached.Select(dbRequest.StopID); if (cached == null || (cached.ShouldBeUpdated || forceCache)) { try { if (!await CheckBasicDataValidity()) { var results = cached?.FindResultsSatisfyingRequest(dbRequest); return(results?.Departures.Count == 0 ? null : results); } // Process the request immediately so the user does not have to wait until the caching is completed. dbResponse = await dbProcessing.ProcessAsync(dbRequest, dbRequest.Count == -1?int.MaxValue : Settings.TimeoutDuration); // Then update the cache. #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed if (cached != null && cached.ShouldBeUpdated && dbRequest.Count != -1 && CanBeCached) { Task.Run(async() => cached.UpdateCache(await dbProcessing.ProcessAsync(cached.ConstructNewRequest(), int.MaxValue))); } #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } catch (System.Net.WebException) { PlatformDependentSettings.ShowMessage(Settings.Localization.UnreachableHost); } } else { dbResponse = cached?.FindResultsSatisfyingRequest(dbRequest); if (dbResponse?.Departures.Count == 0) { dbResponse = await dbProcessing.ProcessAsync(dbRequest, Settings.TimeoutDuration); } } } return(dbResponse); }
private void removeButton_Click(object sender, EventArgs e) { foreach (StationInfoCached item in favoritesListBox.CheckedItems) { item.Remove(); } favorites = StationInfoCached.FetchStationInfoData().ToList(); favoritesListBox.Items.Clear(); foreach (var item in favorites) { favoritesListBox.Items.Add(item); } removeButton.Enabled = favoritesListBox.CheckedItems.Count > 0; findButton.Enabled = favoritesListBox.CheckedItems.Count > 0; }
private void addButton_Click(object sender, System.EventArgs e) { Structures.Basic.StationsBasic.StationBasic station = Request.GetStationFromString(stationTextBox.Text); if (station == null || StationInfoCached.Select(station.ID) != null) { return; } var fav = new StationInfoCached(station.ID); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Request.CacheDepartureBoardAsync(fav.ConstructNewRequest()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed favoritesListBox.Items.Add(fav); favorites.Add(fav); }
public FavoriteStationsWindow() { InitializeComponent(); Settings.Theme.Apply(this); stationTextBox.Text = Settings.Localization.Station; addButton.Text = Settings.Localization.Add; removeButton.Text = Settings.Localization.Remove; findButton.Text = Settings.Localization.Find; favorites = StationInfoCached.FetchStationInfoData().ToList(); foreach (var item in favorites) { favoritesListBox.Items.Add(item); } }
/// <summary> /// Updates all the cached results. /// </summary> public static async Task UpdateCachedResultsAsync(bool forceUpdate = false) { Task ForEachFetchedResult <Res, Req>(IEnumerable <CachedData <Res, Req> > collection, Func <Req, bool, Task> processAsync) where Res : ResponseBase where Req : RequestBase { return(Task.Run(() => { foreach (var fetched in collection) { if (forceUpdate || fetched.ShouldBeUpdated) { processAsync(fetched.ConstructNewRequest(), forceUpdate); } } })); } await Task.WhenAll( ForEachFetchedResult(StationInfoCached.FetchStationInfoData(), CacheDepartureBoardAsync), ForEachFetchedResult(LineInfoCached.FetchLineInfoData(), CacheDepartureBoardAsync), ForEachFetchedResult(JourneyCached.FetchJourneyData(), CacheJourneyAsync) ); }
/// <summary> /// Caches the departures according to departure board request. /// </summary> private static async Task <bool> CacheDepartureBoardAsync(StationInfoRequest dbRequest, bool forceCache = false) => StationInfoCached.CacheResults(DataFeedDesktop.Basic.Stations.FindByIndex(dbRequest.StopID), DataFeedDesktop.OfflineMode ? new DepartureBoardResponse() : await SendDepartureBoardRequestAsync(dbRequest, forceCache)) != null;
/// <summary> /// Caches the departures according to departure board request. /// </summary> private static async Task <bool> CacheDepartureBoardAsync(StationInfoRequest dbRequest, bool forceUpdate = false) => CanBeCached? StationInfoCached.CacheResults(DataFeedClient.Basic.Stations.FindByIndex(dbRequest.StopID), await SendDepartureBoardRequestAsync(dbRequest, forceUpdate)) != null : false;