/// <summary> /// Provides station suggestions when the query changes. /// </summary> private async void OnQueryChanged() { await TryExecuteAsync(async _ => { var request = new StationSearchRequest { StationName = Query, UserLocation = _locationService.LastKnownLocation == null ? null : new GeoPoint { Latitude = _locationService.LastKnownLocation.Latitude, Longitude = _locationService.LastKnownLocation.Longitude } }; // Don't use the provided token, having a bunch of OperationCanceledExceptions is too slow var response = await _transportService.SearchStationsAsync(request, CancellationToken.None); if (response.Status != TransportStatus.Success) { throw new Exception("An error occurred on the server while fetching stations."); } Stations = response.Stations; }); }
public Task <StationSearchResponse> SearchStationsAsync(StationSearchRequest request, CancellationToken cancellationToken) { return(Task.FromResult ( new StationSearchResponse { Status = TransportStatus.Success, Stations = new[] { new Station { Name = "UNIL-Dorigny" }, new Station { Name = "UNIL-Mouline" }, new Station { Name = "UNIL-Sorge" } } } )); }
/// <summary> /// Finds the station with the specified name, adds it to the settings, and navigates back. /// </summary> private async Task AddStationByNameAsync(string stationName) { if (_pluginSettings.Stations.Any(s => s.Name == stationName)) { _navigationService.NavigateBack(); } await TryExecuteAsync(async token => { var request = new StationSearchRequest { StationName = stationName }; var response = await _transportService.SearchStationsAsync(request, token); if (response.Status != TransportStatus.Success) { throw new Exception("An error occurred on the server while fetching stations."); } _pluginSettings.Stations.Add(response.Stations[0]); _navigationService.NavigateBack(); }); }
public Task <StationSearchResponse> SearchStationsAsync(StationSearchRequest request, CancellationToken cancellationToken) { return(CallAsync <StationSearchRequest, CancellationToken, StationSearchResponse>(x => x.SearchStationsAsync, request, cancellationToken)); }