示例#1
0
        /// <summary>
        /// Creates a new GeonamesParser using the provided IDictionary to map each Cities'
        /// string TZ Name to int TimeZone ids.
        /// </summary>
        public GeonamesParser(DataTable featureCodesDataTable, GeonamesDirectoryInfo directory)
        {
            Directory = directory;

            _geonamesFiles = directory.ValidGeonamesFiles;

            FEATURECODE_FILE_PATH = Environment.CurrentDirectory + @"\Resources\geonames_feature_codes.txt";

            _regex = new Regex(@"\t", RegexOptions.Compiled);

            _maxParallelism = Environment.ProcessorCount;

            // Assign a reusable buffer for each thread.
            _bufferPool = new ConcurrentPool <string[]>(_maxParallelism);

            // Allocate buffer pool.
            for (int i = 0; i < _maxParallelism; i++)
            {
                // Adding string[] with max number of City fields for size.
                _bufferPool.Push(new string[City.NUM_FIELDS]);
            }

            ParsedEntries = 0;

            if (null != featureCodesDataTable)
            {
                _featureCodesDataTable = featureCodesDataTable;
            }
            else
            {
                throw new ArgumentNullException("featureCodesDataTable");
            }
        }
示例#2
0
        /// <summary>
        /// Parses the provided line into a City.
        /// </summary>
        /// <param name="line">The line to parse into a city.</param>
        /// <returns>A city parsed from the provided line.</returns>
        private object[] ParseCity(string line)
        {
            // Fields corresponding to each City data type.
            string[] fields = SplitTabs(line);

            // Parse fields into each data type.
            object[] values = new object[]
            {
                (object)DBNull.Value,
                City.ParseName(fields[City.NameIndex]),
                City.ParseAsciiName(fields[City.AsciiNameIndex]),
                City.ParseAlternateNames(fields[City.AlternateNamesIndex]),
                City.ParseLatitude(fields[City.LatitudeIndex]),
                City.ParseLongitude(fields[City.LongitudeIndex]),
                City.ParseFeatureClass(fields[City.FeatureClassIndex]) ?? (object)DBNull.Value,
                City.ParseFeatureCode(fields[City.FeatureCodeIndex]),
                City.ParseCountryCode(fields[City.CountryCodeIndex]),
                City.ParseCountryCode2(fields[City.CountryCode2Index]),
                City.ParsePopulation(fields[City.PopulationIndex]),
                City.ParseElevation(fields[City.ElevationIndex]) ?? (object)DBNull.Value,
                City.ParseModificationDate(fields[City.ModificationDateIndex]),
                City.ParseAdmin1Code(fields[City.Admin1CodeIndex]),
                City.ParseAdmin2Code(fields[City.Admin2CodeIndex]),
                City.ParseAdmin3Code(fields[City.Admin3CodeIndex]),
                City.ParseAdmin4Code(fields[City.Admin4CodeIndex]),
                City.ParseGtopo30(fields[City.Gtopo30Index]),
                (object)DBNull.Value,
                fields[City.TimeZoneIdIndex],
                (object)DBNull.Value
            };

            _bufferPool.Push(fields);

            return(values);
        }