Esempio n. 1
0
        protected override void Seed(global::DataContextNamespace.DataContext context)
        {
            SimpleGeoName des    = new SimpleGeoName();
            string        xmlStr = File.ReadAllText(@"D:\ProsolutionLtd\MyTerm\MyTerm\geodata.xml");

            des = des.Deserialize(xmlStr);


            foreach (SimpleGeoName continent in des.Childrens)
            {
                foreach (SimpleGeoName country in continent.Childrens)
                {
                    Console.WriteLine("Country: " + country.Name + ", num of cities: " + country.Childrens.Count);

                    Country state = new Country()
                    {
                        Name = country.Name, Description = country.FCode
                    };
                    state = context.Countries.Add(state);

                    foreach (SimpleGeoName city in country.Childrens)
                    {
                        City town = new City()
                        {
                            Name = city.Name, PostCode = city.FCode, Country = state
                        };
                        town = context.Cities.Add(town);
                    }
                }
            }

            context.SaveChanges();
        }
Esempio n. 2
0
        private void GetNodes()
        {
            int id;

            try
            {
                id = int.Parse(this.txtGenonameId.Text);
            }
            catch { return; }

            try
            {
                var g  = GeoNamesOrgWebservice.Get(id);
                var sg = new SimpleGeoName(g);

                GetChildren(sg, g);

                var xml = XmlHelper.ToXml <SimpleGeoName>(sg);
                File.WriteAllText(@"c:\output.xml", xml);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        private void GetChildren(SimpleGeoName sg, Geoname g)
        {
            Path.Push(sg);
            CurrentLevel--;
            try
            {
                foreach (var n in g.Children(GeoNamesDataStyle.Full))
                {
                    ItemCount++;
                    UpdateCounterUI();

                    var nsg = new SimpleGeoName(n);
                    sg.Children.Add(nsg);
                    if (CurrentLevel >= 0)
                    {
                        GetChildren(nsg, n);
                    }
                }
            }
            catch {}
            CurrentLevel++;
            Path.Pop();
        }