Beispiel #1
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);
        }