#pragma warning disable 1998 private static async Task <Module> GetModule(string value) #pragma warning restore 1998 { try { ModuleType moduleType = ModuleType.None; string city = string.Empty; string postal = string.Empty; string cityCode = string.Empty; string country = string.Empty; string language = string.Empty; LatitudeCoords latitudeCoords = null; LongitudeCoords longitudeCoords = null; Categories categories = Categories.Business; Countries countries = Countries.AE; Languages languages = Languages.AF; if (value != string.Empty) { if (!value.Contains("news")) { LocationTable locationTable = DataAccess.GetLocationData()?[0]; moduleType = (ModuleType)Enum.Parse(typeof(ModuleType), Regex.Replace(value, @"[\d-]", string.Empty).ToUpper()); if (locationTable != null) { switch (moduleType) { case ModuleType.None: break; case ModuleType.Time: Coordinates coordinates = await GoogleMapsGeocoding.GetCoordinatesForPostal(locationTable.Postal, locationTable.Country); if (coordinates == null) { break; } latitudeCoords = coordinates.Latitude; longitudeCoords = coordinates.Longitude; break; case ModuleType.Weather: city = locationTable.City; postal = locationTable.Postal; cityCode = locationTable.CityCode; country = locationTable.Country; language = locationTable.Language; break; case ModuleType.Weatherforecast: city = locationTable.City; postal = locationTable.Postal; cityCode = locationTable.CityCode; country = locationTable.Country; language = locationTable.Language; break; case ModuleType.News: break; case ModuleType.Quote: break; case ModuleType.Joke: break; } } } else { moduleType = ModuleType.News; value = value.Remove(0, 4); // To UppperCamelCase value = value.First().ToString().ToUpper() + value.Substring(1); categories = (Categories)Enum.Parse(typeof(Categories), Regex.Replace(value, @"[\d-]", string.Empty)); LocationTable locationTable = DataAccess.GetLocationData()?[0]; // ReSharper disable once InvertIf if (locationTable != null) { countries = (Countries)Enum.Parse(typeof(Countries), locationTable.Country.ToUpper()); languages = (Languages)Enum.Parse(typeof(Languages), locationTable.Language.ToUpper()); } } } return(new Module { ModuleType = moduleType, City = city, Postal = postal, CityCode = cityCode, Country = country, Language = language, LatitudeCoords = latitudeCoords, LongitudeCoords = longitudeCoords, NewsCategory = categories, NewsCountry = countries, NewsLanguage = languages }); } catch (Exception exception) { Log.Log.WriteException(exception); return(new Module()); } }
#pragma warning disable 1998 private static async Task <Module> getModule(string value) #pragma warning restore 1998 { ModuleType moduleType = ModuleType.NONE; string city = string.Empty; string country = string.Empty; string language = string.Empty; LatitudeCoords latitudeCoords = null; LongitudeCoords longitudeCoords = null; Categories categories = Categories.Business; Countries countries = Countries.AE; Languages languages = Languages.AF; if (value != string.Empty) { if (!value.Contains("news")) { LocationTable locationTable = DataAccess.GetLocationData()?[0]; moduleType = (ModuleType)Enum.Parse(typeof(ModuleType), value.ToUpper()); if (locationTable != null) { switch (moduleType) { case ModuleType.NONE: break; case ModuleType.TIME: Coordinates coordinates = await GoogleMapsGeocoding.GetCoordinatesForCity(locationTable.City, locationTable.State, locationTable.Country); latitudeCoords = coordinates.Latitude; longitudeCoords = coordinates.Longitude; break; case ModuleType.WEATHER: city = locationTable.City; country = locationTable.Country; language = locationTable.Language; break; case ModuleType.WEATHERFORECAST: city = locationTable.City; country = locationTable.Country; language = locationTable.Language; break; case ModuleType.NEWS: break; case ModuleType.QUOTE: break; case ModuleType.JOKE: break; } } } else { moduleType = ModuleType.NEWS; value = value.Remove(0, 4); // To UppperCamelCase value = value.First().ToString().ToUpper() + value.Substring(1); categories = (Categories)Enum.Parse(typeof(Categories), value); LocationTable locationTable = DataAccess.GetLocationData()?[0]; // ReSharper disable once InvertIf if (locationTable != null) { countries = (Countries)Enum.Parse(typeof(Countries), locationTable.Country.ToUpper()); languages = (Languages)Enum.Parse(typeof(Languages), locationTable.Language.ToUpper()); } } } return(new Module { ModuleType = moduleType, City = city, Country = country, Language = language, LatitudeCoords = latitudeCoords, LongitudeCoords = longitudeCoords, NewsCategory = categories, NewsCountry = countries, NewsLanguage = languages }); }