private async Task GetPowerDetailsAsync() { try { PowerDetailsService pdService = PowerDetailsService.Instance(); StandingsService gsService = StandingsService.Instance(); if (pdService.SelectedPower != null) { PowerDetails = pdService.SelectedPower; CancellationTokenSource cancelToken = new CancellationTokenSource(); PowerStanding = await gsService.GetPowerAsync(PowerDetails.ShortName, cancelToken).ConfigureAwait(false); Cycle = PowerStanding.Cycle; LastUpdated = PowerStanding.LastUpdated; ExpandText = String.Format("<p>{0}</p> <ul><li>Strong Against: {1}</li><li>Weak Against: {2}</li></ul>", PowerDetails.ExpansionText, PowerDetails.ExpansionStrongGovernment, PowerDetails.ExpansionWeakGovernment); ControlText = String.Format("<p>{0}</p> <ul><li>Strong Against: {1}</li><li>Weak Against: {2}</li></ul>", PowerDetails.ControlText, PowerDetails.ControlStrongGovernment, PowerDetails.ControlWeakGovernment); } } catch (Exception ex) { ToastHelper.Toast(String.Format("Error getting Power details: {0}", ex.Message)); } }
private async void GetStandingsAsync(bool ignoreCache = false) { int cycleNo = 0; if (!string.IsNullOrWhiteSpace(Cycle)) { int p = Cycle.IndexOf(" ") + 1; Int32.TryParse(Cycle.Substring(p, Cycle.Length - p), out cycleNo); } if ((Standings?.Any() == false) || (cycleNo != CycleService.CurrentCycle() && (LastUpdated + TimeSpan.FromMinutes(10) < DateTime.Now))) { ShowMessage = false; CancellationTokenSource cancelToken = new CancellationTokenSource(); using (UserDialogs.Instance.Loading("Loading", () => cancelToken.Cancel(), null, true, MaskType.Clear)) { try { // get the standings StandingsService standingsService = StandingsService.Instance(); GalacticStandings standings = await standingsService.GetData(cancelToken, ignoreCache).ConfigureAwait(false); Cycle = $"Cycle {standings.Cycle}"; LastUpdated = standings.LastUpdated; if (standings.Standings.Count < 1) { SetMessages("Unable to display Powerplay Standings due to parsing error.", true); } else { // show the standings Device.BeginInvokeOnMainThread(() => { Standings.Clear(); foreach (PowerStanding item in standings.Standings) { Standings.Add(item); } }); } } catch (OperationCanceledException) { SetMessages("Powerplay Standings download was cancelled or timed out.", true); } catch (HttpRequestException ex) { string err = ex.Message; int start = err.IndexOf("OPENSSL_internal:", StringComparison.OrdinalIgnoreCase); if (start > 0) { start += 17; int end = err.IndexOf(" ", start, StringComparison.OrdinalIgnoreCase); err = $"SSL Error ({err.Substring(start, end - start).Trim()})"; } else if (err.IndexOf("Error:", StringComparison.OrdinalIgnoreCase) > 0) { err = err.Substring(err.IndexOf("Error:", StringComparison.OrdinalIgnoreCase) + 6).Trim(); } SetMessages($"Network Error: {err}", true); } catch (Exception ex) { if (ex.Message.Contains("unexpected end of stream")) { SetMessages("Powerplay Standings download was cancelled.", true); } else { SetMessages($"Error: {ex.Message}", true); } } } } }