Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public CountryAnswer(ICountryInfo country, bool showName, bool showFlag)
        {
            Country = country;

            ShowName = showName;
            ShowFlag = showFlag;
        }
Esempio n. 3
0
        public BorderInfo(ICountryInfo neighbor, bool hasLandBorder, bool hasMaritimeBorder, bool excluded)
        {
            Neighbor = neighbor;

            HasLandBorder     = hasLandBorder;
            HasMaritimeBorder = hasMaritimeBorder;
            Excluded          = excluded;
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public CountryQuestion(bool setOnIncorrect, ICountryInfo country, bool showName, bool showFlag)
        {
            _setOnIncorrect = setOnIncorrect;

            State   = QuestionState.Unanswered;
            Country = country;

            ShowName = showName;
            ShowFlag = showFlag;
        }
Esempio n. 6
0
 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)
     });
 }
Esempio n. 7
0
        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);
Esempio n. 9
0
 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)));
 }
Esempio n. 11
0
 public CountryEnumValue(Country country)
 {
     _countryEnum       = country;
     _countryEnumString = country.GetName();
     _countryInfo       = CountryManager.GetCountryInfo(country);
 }
Esempio n. 12
0
 protected override IQuestion CreateQuestion(ICountryInfo country)
 {
     return(new CountryQuestion(true, country, true, true));
 }
Esempio n. 13
0
 public Country(ICountryInfo countryInfo)
 {
     _countryInfo = countryInfo;
 }
Esempio n. 14
0
 protected abstract IQuestion CreateQuestion(ICountryInfo country);
Esempio n. 15
0
 protected override IQuestion CreateQuestion(ICountryInfo country)
 {
     return(new CountryQuestion(true, country, _direction == Direction.GuessFlag, _direction == Direction.GuessName));
 }