Beispiel #1
0
        static public void LoadGeocodeList()
        {
            if (!ProvinceGeocodes.Any())
            {
                XElement lGeocodeXML = XElement.Load(BasicGeocodeFileName());

                var lQuery = from c in lGeocodeXML.Descendants(TambonHelper.TambonNameSpace + "entity")
                             orderby(string) c.Attribute("english")
                             select new PopulationDataEntry
                {
                    Name    = (string)c.Attribute("name"),
                    English = (string)c.Attribute("english"),
                    Type    = (EntityType)Enum.Parse(typeof(EntityType), (string)c.Attribute("type")),
                    Geocode = (Int32)c.Attribute("geocode")
                };

                ProvinceGeocodes.Clear();
                ProvinceGeocodes.AddRange(lQuery);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns the tree of administrative subdivisions for a given province.
        /// </summary>
        /// <param name="provinceCode">TIS1099 code of the province.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <cref>provinceCode</cref> does not refer to a valid province.</exception>
        /// <returns>Tree of subdivisions.</returns>
        /// <remarks>Internally caches a clone of the returned value, to load the file from disc only once.</remarks>
        static public PopulationData GetGeocodeList(Int32 provinceCode)
        {
            PopulationData result = null;

            if (!ProvinceGeocodes.Any(entry => entry.Geocode == provinceCode))
            {
                throw new ArgumentOutOfRangeException("provinceCode");
            }
            if (_GeocodeCache.Keys.Contains(provinceCode))
            {
                result = new PopulationData((PopulationDataEntry)(_GeocodeCache[provinceCode].Clone()));
            }
            else
            {
                String fileName = TambonHelper.GeocodeSourceFile(provinceCode);
                if (File.Exists(fileName))
                {
                    result = PopulationData.Load(fileName);
                    _GeocodeCache.Add(provinceCode, (PopulationDataEntry)(result.Data.Clone()));
                }
            }
            return(result);
        }