示例#1
0
        public void CurrentCycleTest()
        {
            int cycle = CycleService.CurrentCycle();

            Assert.IsTrue(cycle > 200);
            Assert.IsTrue(cycle < 500);
        }
示例#2
0
        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);
                        }
                    }
                }
            }
        }