public GasQuery(GasQuery parameterOriginal) { UniqueId = parameterOriginal.UniqueId; _fuelType = parameterOriginal.FuelType; _long1 = parameterOriginal.Longitude1; _lat1 = parameterOriginal.Latitude1; _long2 = parameterOriginal.Longitude2; _lat2 = parameterOriginal.Latitude2; _showClosed = parameterOriginal.ShowClosedGasStations; Name = parameterOriginal.Name; _geocodeLatitude = parameterOriginal.GeocodeLatitude; _geocodeLongitude = parameterOriginal.GeocodeLongitude; }
public async Task QueryPricesAsync() { QueryResult = null; var q = new GasQuery() { FuelType = this.FuelType, GeocodeLatitude = this.Latitude, GeocodeLongitude = this.Longitude, UniqueId = Guid.NewGuid().ToString(), Latitude1 = this.Latitude - LatitudeBoundingBox, Latitude2 = this.Latitude + LatitudeBoundingBox, Longitude1 = this.Longitude - LongitudeBoundingBox, Longitude2 = this.Longitude + LongitudeBoundingBox }; try { Loading = true; ToMapPins(new List<GasStationResult>()); var gasinfoProxy = CreateGasPriceInfoProxy(); var result = await gasinfoProxy.DownloadAsync(q); if (result.Succeeded) { QueryResult = result.Result; ToMapPins(result.Result.GasStationResults); } else { await _messageService.ShowAsync("Die Preise für den selektierten Ort konnten nicht abgerufen werden"); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); // No await in catch *yet* // InfoMessage = "Die Preise für den selektierten Ort konnten nicht abgerufen werden"; } finally { Loading = false; } }
public GasQueryResult(GasQuery parameterOriginal, List <GasStationResult> gasStationResults, DateTime lastUpdated) : base(parameterOriginal) { _gasstationQueryResults = new ObservableCollection <GasStationResult>(gasStationResults); _lastUpdated = lastUpdated; }
public GasQueryResult(GasQuery parameterOriginal) : base(parameterOriginal) { }
public GasQueryResult(GasQuery parameterOriginal, List<GasStationResult> gasStationResults, DateTime lastUpdated) : base(parameterOriginal) { _gasstationQueryResults = new ObservableCollection<GasStationResult>(gasStationResults); _lastUpdated = lastUpdated; }
public GasQueryResult(GasQuery parameterOriginal):base(parameterOriginal) { }
public async Task<GasQueryDownloadResult> DownloadAsync(GasQuery parameter) { // Prepare POST data string postData = Uri.EscapeUriString(parameter.ToPostData()); var ascii = new UTF8Encoding(); byte[] bData = ascii.GetBytes(postData); var content = new ByteArrayContent(bData); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); List<RootObject> result = null; try { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*")); client.DefaultRequestHeaders.Referrer = new Uri("http://spritpreisrechner.at/ts/map.jsp"); HttpResponseMessage response = await client.PostAsync(URL, content); string json = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject<List<RootObject>>(json); } } catch (Exception ex) { return new GasQueryDownloadResult() { Succeeded = false, ErrorMessage = ex.ToString(), Result = new GasQueryResult(parameter) }; } // Errors are reported in a rather weird way so let's be extra careful in retrieving those if (result.Count == 1) { var firstItem = result.First(); if (firstItem != null) { var errorItems = firstItem.errorItems; if (errorItems != null && errorItems.Count > 0 && errorItems.First() != null) { return new GasQueryDownloadResult() { Succeeded = false, ErrorMessage = errorItems.First().msgText, Result = new GasQueryResult(parameter) }; } } } var foundTanken = new List<GasStationResult>(); foreach (var ro in result) { if (null == ro) continue; if (!String.IsNullOrWhiteSpace(ro.gasStationName)) { var tanke = new GasStationResult() { City = ro.city, PostalCode = ro.postalCode, Street = ro.address, Name = ro.gasStationName, Longitude = MappingHelpers.ConvertDouble(ro.longitude), Latitude = MappingHelpers.ConvertDouble(ro.latitude), }; if ((null != ro.spritPrice) && ro.spritPrice.Count > 0) { var preisInfo = ro.spritPrice.First(); if ((null != preisInfo) && !String.IsNullOrWhiteSpace(preisInfo.amount)) { tanke.Price = MappingHelpers.ConvertDouble(preisInfo.amount); foundTanken.Add(tanke); } } } } var orderedTanken = foundTanken.OrderBy(t => t.Price).ToList(); int tankeOrderNumber = 1; foreach (var tanke in orderedTanken) { tanke.UniqueId = tankeOrderNumber.ToString(); tankeOrderNumber++; } return new GasQueryDownloadResult() { Succeeded = true, Result = new GasQueryResult(parameter, orderedTanken, DateTime.Now) }; }
public async Task DownloadInfoAsync(double lat1, double long1, double lat2, double long2) { var fueltype = QueryResult.FuelType; var parameter = new GasQuery(Guid.NewGuid().ToString(), fueltype, long1, lat1, long2, lat2); try { var gasinfoProxy = CreateGasPriceInfoProxy(); var result = await gasinfoProxy.DownloadAsync(parameter); if (result.Succeeded) { SetQueryResultToGeocodeResult(result.Result); SendUpdateMapNotification(); CurrentLocationFound = true; } else { ErrorService.ShowLightDismissError("Die Preisinformationen konnten nicht ermittelt werden"); } } catch (Exception) { ErrorService.ShowLightDismissError("Die Preisinformationen konnten nicht ermittelt werden"); } UpdateInProgress = false; }
public async Task<bool> AddAsync(GasQuery parameters) { try { var proxy = CreateGasPriceInfoProxy(); var ergebnis = await proxy.DownloadAsync(parameters); if (ergebnis.Succeeded) { bool saveOk = await AddResultAsync(ergebnis.Result); return saveOk; } } catch (Exception) { } return false; }