diff --git a/Logic/Structure/GeographyUpdate.cs b/Logic/Structure/GeographyUpdate.cs index e920df84..04e2cc1f 100644 --- a/Logic/Structure/GeographyUpdate.cs +++ b/Logic/Structure/GeographyUpdate.cs @@ -108,9 +108,31 @@ namespace Swarmops.Logic.Structure GeographyDataLoader geoDataLoader = new GeographyDataLoader(); - MasterGeography geography = geoDataLoader.GetGeographyForCountry(countryCode); - MasterCity[] cities = geoDataLoader.GetCitiesForCountry(countryCode); - MasterPostalCode[] postalCodes = geoDataLoader.GetPostalCodesForCountry(countryCode); + // This next part has been hardened against transient network failures, up to 10 retries + + int retries = 0; + bool networkSuccess = false; + + while (!networkSuccess) + { + try + { + MasterGeography geography = geoDataLoader.GetGeographyForCountry(countryCode); + MasterCity[] cities = geoDataLoader.GetCitiesForCountry(countryCode); + MasterPostalCode[] postalCodes = geoDataLoader.GetPostalCodesForCountry(countryCode); + networkSuccess = true; + } + catch (Exception) + { + if (retries >= 10) + { + throw; + } + + retries++; + Thread.Sleep(5000); // wait five seconds for network conditions to clear + } + } // ID Translation lists diff --git a/Site/Pages/v5/Public/Initialize.aspx.cs b/Site/Pages/v5/Public/Initialize.aspx.cs index 03e98c4e..be479e2b 100644 --- a/Site/Pages/v5/Public/Initialize.aspx.cs +++ b/Site/Pages/v5/Public/Initialize.aspx.cs @@ -485,10 +485,9 @@ namespace Swarmops.Frontend.Pages.v5.Public // Fetch the first set of exchange rates, completing the currency collection - SupportFunctions.DisableSslCertificateChecks(); // needed bc SSL root store on Mono hosed ExchangeRateSnapshot.Create(); - // Disable SSL required - turn this on manually + // Disable SSL required - the user must turn this on manually SystemSettings.RequireSsl = false; @@ -518,14 +517,51 @@ namespace Swarmops.Frontend.Pages.v5.Public GetGeographyData geoDataFetcher = new GetGeographyData(); - Country[] countries = geoDataFetcher.GetCountries(); + Country[] countries = null; _initProgress = 7; _initMessage = "Creating all countries on local server..."; Thread.Sleep (100); int count = 0; + int countryRetries = 0; + + try + { + countries = geoDataFetcher.GetCountries(); + } + catch (Exception) + { + // ignore for now, retrying below + } + + while (++countryRetries < 10 && (countries == null || countries.Length < 20)) + { + _initMessage = "Network problem, retrying... "; + if (countryRetries > 1) + { + _initMessage += String.Format("({0})", countryRetries); + } + Thread.Sleep(500); + + try + { + countries = geoDataFetcher.GetCountries(); + } + catch (Exception) + { + if (countryRetries > 8) + { + throw; + } + + // otherwise ignore for now + } + } + int total = countries.Length; + + // Create all countries in our own database foreach (Country country in countries)