private bool Select(HashSet <ICountryInfo> selected, ICountryInfo current, int count, Continent continent, bool ignoreExlusion) { var next = current.Borders .Where(b => b.HasLandBorder && (ignoreExlusion || !b.Excluded) && !selected.Contains(b.Neighbor) && (continent == Continent.Unspecified || b.Neighbor.Continent == continent)) .Select(b => new { Country = b.Neighbor, Order = _random.Next() }) .OrderBy(i => i.Order) .Take(_random.Next(1, count - selected.Count + 1)) .Select(i => i.Country) .ToList(); selected.UnionWith(next); if (selected.Count > count) { return(true); } foreach (var item in next) { if (Select(selected, item, count, continent, ignoreExlusion)) { return(true); } } return(false); }
public CountryAnswer(ICountryInfo country, bool showName, bool showFlag) { Country = country; ShowName = showName; ShowFlag = showFlag; }
public BorderInfo(ICountryInfo neighbor, bool hasLandBorder, bool hasMaritimeBorder, bool excluded) { Neighbor = neighbor; HasLandBorder = hasLandBorder; HasMaritimeBorder = hasMaritimeBorder; Excluded = excluded; }
private string GetCountryTranslatedName(ICountryInfo countryInfo, LanguageCode languageCode) { if (countryInfo != null && countryInfo.Translations != null && countryInfo.Translations.Length > 0) { return(countryInfo.Translations.Where(x => x.LanguageCode == languageCode).Select(x => x.Name).FirstOrDefault()); } return(null); }
public CountryQuestion(bool setOnIncorrect, ICountryInfo country, bool showName, bool showFlag) { _setOnIncorrect = setOnIncorrect; State = QuestionState.Unanswered; Country = country; ShowName = showName; ShowFlag = showFlag; }
internal static CountryInfoDto Convert(ICountryInfo country) { return(new CountryInfoDto { CommonName = country.CommonName, OfficialName = country.OfficialName, CountryCode = country.Alpha2Code.ToString(), Region = country.Region.ToString(), Borders = GetBorderCountryInfos(country.BorderCountries) }); }
private string GetCountryTranslatedName(ICountryInfo countryInfo, LanguageCode languageCode) { this._alpha2Code2CountryTranslation.TryGetValue(countryInfo.Alpha2Code, out var countryTranslation); if (countryTranslation.Translations != null && countryTranslation.Translations.Length > 0) { return(countryTranslation.Translations.Where(x => x.LanguageCode == languageCode).Select(x => x.Name).FirstOrDefault()); } return(null); }
public CountryEnumValue(string countryString) { if (string.IsNullOrWhiteSpace(countryString)) { throw new ArgumentNullException(nameof(countryString)); } var length = countryString.Length; if (length == 2 || length == 3) { var country = CountryManager.GetCountryInfo(countryString); if (country != null) { _countryEnum = country.Country; _countryEnumString = countryString; _countryInfo = country; return; } } var enumMember = Enums.GetMember <Country>(countryString, true); if (enumMember != null) { _countryEnum = enumMember.Value; _countryEnumString = countryString; _countryInfo = CountryManager.GetCountryInfo(_countryEnum); return; } //历史国家的 Name 应当是 国名+建国年,比如 Yugoslavia1992 if (countryString.Length <= 4) { throw new ArgumentException("The length of the countryString must greater than 4."); } #if NETSTANDARD2_0 var year = countryString.Substring(countryString.Length - 4).CastToInt32(-1); var countryStr = countryString.Substring(0, countryString.Length - 4); #else var year = countryString[^ 4..].CastToInt32(-1);
public Country(ICountryInfo info) { this.CallingCode = info.CallingCodes.First(); this.CountryCode = info.Alpha2Code.ToString(); this.Name = info.OfficialName; }
/// <summary> /// Get region code / CEP-1 from <see cref="CountryInfo"/>. /// </summary> /// <param name="country"></param> /// <returns></returns> public static long GetRegionCode(this ICountryInfo country) { return(country?.Cep1CrCode ?? throw new ArgumentNullException(nameof(country))); }
public CountryEnumValue(Country country) { _countryEnum = country; _countryEnumString = country.GetName(); _countryInfo = CountryManager.GetCountryInfo(country); }
protected override IQuestion CreateQuestion(ICountryInfo country) { return(new CountryQuestion(true, country, true, true)); }
public Country(ICountryInfo countryInfo) { _countryInfo = countryInfo; }
protected abstract IQuestion CreateQuestion(ICountryInfo country);
protected override IQuestion CreateQuestion(ICountryInfo country) { return(new CountryQuestion(true, country, _direction == Direction.GuessFlag, _direction == Direction.GuessName)); }