コード例 #1
0
        static CountryManager()
        {
            _nameAndCodeMap = WholeWorld.Data.ToDictionary(k => k.Country, v => v.CountryCode);
            _codeAndNameMap = WholeWorld.Data.ToDictionary(k => k.CountryCode, v => v.Country);

            RuntimeCountryInfoCache.FirstTimeUpdate(WholeWorld.Data);
        }
コード例 #2
0
        public static RuntimeCountryInfo Of(CountryInfo country)
        {
            if (country is null)
            {
                throw new ArgumentNullException(nameof(country));
            }

            return(RuntimeCountryInfoCache.GetOrAdd(country.Cep1CrCode, _ => new RuntimeCountryInfo(country)));
        }
コード例 #3
0
        /// <summary>
        /// Gets <see cref="CountryInfo"/> via Cosmos Region Code / CEP-1.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static RuntimeCountryInfo GetCountryInfo(RegionCodeValue value)
        {
            if (value.IsHistoricalValue())
            {
                return(RuntimeCountryInfoCache.GetOrDefault(value));
            }

            var country = WholeWorld.Data.FirstOrDefault(x => x.Cep1CrCode == value);

            return(RuntimeCountryInfo.Of(country));
        }
コード例 #4
0
        public static void AppendConfiguredCountries(IEnumerable <HistoricalCountryModel> configuredModels)
        {
            if (configuredModels is null)
            {
                return;
            }
            var models = configuredModels.ToList();

            if (!models.Any())
            {
                return;
            }

            //Step.1 修正
            foreach (var model in models)
            {
                if (!model.IsValid())
                {
                    model.Flag = -1;
                    continue;
                }

                var code = (RegionCodeValue)model.Cep1CrCode;

                if (!code.IsHistoricalValue())
                {
                    model.Flag = -1;
                    continue;
                }

                if (model.Since > DateTime.Today.Year || model.Since <= 0)
                {
                    //不支持公元前
                    model.Flag = -1;
                    continue;
                }

                if (model.EndedIn.HasValue && model.Since > model.EndedIn.Value)
                {
                    //不支持公元前
                    model.Flag = -1;
                    continue;
                }

                if (model.Previous != null)
                {
                    if (!model.Previous.EndedIn.HasValue)
                    {
                        model.Flag = -1;
                        continue;
                    }

                    if (model.Previous.EndedIn.Value > model.Since)
                    {
                        model.Flag = -1;
                        continue;
                    }

                    if (!TryFixedNavModel(models, model.Previous) || model.Previous.Kill)
                    {
                        model.Previous = null;
                    }
                }

                if (model.Next != null)
                {
                    if (model.Next.Any())
                    {
                        foreach (var nav in model.Next)
                        {
                            if (nav is null)
                            {
                                continue;
                            }

                            if (!TryFixedNavModel(models, nav))
                            {
                                nav.Kill = true;
                            }
                        }

                        if (model.Next.All(x => x.Kill))
                        {
                            model.Next.Clear();
                            model.Next = null;
                        }
                    }
                    else
                    {
                        model.Next = null;
                    }
                }

                if (!model.IsValid())
                {
                    model.Flag = -1;
                }
            }

            //Step.2 过滤
            var validModels = models.Where(x => x.IsValid()).ToList();

            //Step.3 添加
            foreach (var model in validModels)
            {
                var runtimeModel = model.ToRuntimeCountryInfo();
                var runtimeNav   = model.ToRuntimeNav();

                RuntimeCountryInfoCache.RuntimeUpdate(runtimeModel);
                HistoricalCountryEngine.AddNav(runtimeNav);
            }
        }
コード例 #5
0
 public static IEnumerable <RuntimeCountryInfo> Get(RegionCodeValue code, int year, int month, int day)
 {
     return(code.IsHistoricalValue() == false
         ? new[] { RuntimeCountryInfoCache.GetOrDefault(code) }
         : InternalGet(code, year, month, day));
 }