From 47ee4c06eea4b592ee3109d1a3973f0408913cd7 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 26 Jul 2019 17:17:47 +0100 Subject: [PATCH] Require --grids to get grid support. Hackily improve support for Cloudlog not responding. --- ft8spotter/Program.cs | 50 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/ft8spotter/Program.cs b/ft8spotter/Program.cs index 11d6f50..48cd403 100644 --- a/ft8spotter/Program.cs +++ b/ft8spotter/Program.cs @@ -10,6 +10,8 @@ using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Text; +using System.Threading; +using System.Threading.Tasks; namespace ft8spotter { @@ -23,6 +25,8 @@ namespace ft8spotter { bool all = args.Any(a => a == "--all"); + bool grids = args.Any(a => a == "--grids"); + string bandArg = args.SingleOrDefault(a => a.EndsWith("m")); if (string.IsNullOrWhiteSpace(bandArg) || !int.TryParse(bandArg.Substring(0, bandArg.Length - 1).Replace("--", ""), out int band)) @@ -81,7 +85,7 @@ namespace ft8spotter string grid = GetGrid(msg); - var needed = entity == null ? Needed.No : GetNeeded(band, entity.Adif, grid, "ft8"); + var needed = entity == null ? Needed.No : GetNeeded(band, entity.Adif, grids ? grid : null, "ft8"); if (all || !Needed.No.Equals(needed)) { @@ -312,7 +316,40 @@ namespace ft8spotter private static HttpClient httpClient = new HttpClient(); private static Uri cloudLogUri; - + + private static string HttpGet(string url) + { + int delay = 100; + + while (true) + { + try + { + return httpClient.GetStringAsync(new Uri(cloudLogUri, url)).Result; + } + catch (Exception ex) + { + string message; + if (ex is AggregateException aggregateException) + { + message = String.Join(Environment.NewLine, aggregateException.InnerExceptions.Select(e => e.Message)); + } + else + { + message = ex.Message; + } + + Console.WriteLine(message); + Thread.Sleep(delay); + + if (delay < TimeSpan.FromMinutes(1).TotalMilliseconds) + { + delay *= 2; + } + } + } + } + private static Needed GetNeeded(int band, int? adif, string gridSquare, string mode) { if (!adif.HasValue) @@ -322,8 +359,7 @@ namespace ft8spotter int dxcc = adif.Value; - int qsosWithThatCountryOnThatBand = int.Parse(httpClient.GetStringAsync(new Uri(cloudLogUri, $"country_worked/{dxcc}/{band}m")).Result); - + int qsosWithThatCountryOnThatBand = int.Parse(HttpGet($"country_worked/{dxcc}/{band}m")); var result = new Needed(); @@ -333,7 +369,7 @@ namespace ft8spotter } else { - int qsosWithThatCountryOnThatBandInThisMode = int.Parse(httpClient.GetStringAsync(new Uri(cloudLogUri, $"country_worked/{dxcc}/{band}m/{mode}")).Result); + int qsosWithThatCountryOnThatBandInThisMode = int.Parse(HttpGet($"country_worked/{dxcc}/{band}m/{mode}")); if (qsosWithThatCountryOnThatBandInThisMode == 0) { result.NewCountryOnBandOnMode = true; @@ -347,14 +383,14 @@ namespace ft8spotter gridSquare = gridSquare.Substring(0, 4); } - int qsosWithThatGridOnThatBand = int.Parse(httpClient.GetStringAsync(new Uri(cloudLogUri, $"gridsquare_worked/{gridSquare}/{band}m")).Result); + int qsosWithThatGridOnThatBand = int.Parse(HttpGet($"gridsquare_worked/{gridSquare}/{band}m")); if (qsosWithThatGridOnThatBand == 0) { result.NewGridOnBand = true; } else { - int qsosWithThatGridOnThatBandInThisMode = int.Parse(httpClient.GetStringAsync(new Uri(cloudLogUri, $"gridsquare_worked/{gridSquare}/{band}m/{mode}")).Result); + int qsosWithThatGridOnThatBandInThisMode = int.Parse(HttpGet($"gridsquare_worked/{gridSquare}/{band}m/{mode}")); if (qsosWithThatGridOnThatBandInThisMode == 0) { result.NewGridOnBandOnMode = true;