Beispiel #1
0
        public static IEnumerable <GeonamesAdminEntity> Parse(string path)
        {
            using (var file = new StreamReader(path))
            {
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    if (line.TrimStart().StartsWith("#"))
                    {
                        continue;
                    }

                    var parse  = line.Split(new char[] { '\t' });
                    var entity = GeonamesAdminEntity.Parse(parse);

                    yield return(entity);
                }
            }
        }
Beispiel #2
0
        public static GeonamesAdminEntity Parse(string[] parts)
        {
            var entity = new GeonamesAdminEntity();

            if (parts.Length != 4)
            {
                throw new ArgumentException("Expecting 4 columns as input");
            }

            int geonameId;

            if (int.TryParse(parts[3], out geonameId))
            {
                entity.Id = geonameId;
            }
            else
            {
                throw new ArgumentException("Could not parse Geonames ID");
            }

            entity.ConcatenatedCodes = parts[0];
            entity.Name      = parts[1];
            entity.AsciiName = parts[2];

            return(entity);
        }