Esempio n. 1
0
        public static void Setup()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<CountryContext>());
            CountryContext context = new CountryContext();

            //just load up somthing to initialise
            context.Countries.ToList();
        }
Esempio n. 2
0
        private static void AddCountries(XElement countryList, CountryContext context)
        {
            foreach (var country in context.Countries)
            {
                XElement xCountry = new XElement("country");
                xCountry.Add(new XAttribute("name", country.EnglishName));
                AddVariants(xCountry, country);

                countryList.Add(xCountry);
            }
        }
Esempio n. 3
0
 private static void Main(string[] args)
 {
     using (CountryContext context = new CountryContext())
     {
         Console.WriteLine("Starting COUNTREE outputterator...");
         XDocument countryList = new XDocument();
         countryList.Add(new XElement("countries"));
         AddCountries(countryList.Root, context);
         SaveToLocalFile(countryList);
         Console.WriteLine("Done - Hit <ENTER>");
         Console.ReadLine();
     }
 }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            Console.WriteLine("Set up database");
            Bootstrapper.Setup();
            Console.WriteLine("Finished");

            using (CountryContext countryContext = new CountryContext())
            {

                try
                {
                    IHtmlService service = new HtmlService();

                    foreach (var site in Sitelist)
                    {
                        Console.WriteLine("Loading up page: " + site);
                        HtmlDocument webpage = service.GetWebPage(site);
                        Console.WriteLine("Got website");
                        Console.WriteLine("Strip countries...");
                        var countries = CountryStripper.GetCountries(webpage);
                        Console.WriteLine("Stripped");
                        foreach (Country country in countries)
                        {
                            Console.WriteLine(string.Format("Country: {0}", country.EnglishName));
                            countryContext.Countries.Add(country);
                        }

                        Console.WriteLine("Start Save");
                        countryContext.SaveChanges();
                        Console.WriteLine("Saved!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    Console.Write(ex);
                    Console.WriteLine();
                }

                Console.WriteLine();
                Console.WriteLine("STATS");
                Console.WriteLine("-------------------");
                Console.WriteLine("Countries: " + countryContext.Countries.Count());
                Console.WriteLine("Language Sets: " + countryContext.LanguageSets.Count());
                Console.WriteLine("Languages: " + countryContext.Languages.Count());
            }
            Console.WriteLine("Press enter to close");
            Console.ReadLine();
        }