コード例 #1
0
        public static void Setup()
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<CountryContext>());
            CountryContext context = new CountryContext();

            //just load up somthing to initialise
            context.Countries.ToList();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: deeja/WikiCountryStripper
        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);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: deeja/WikiCountryStripper
 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();
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: deeja/WikiCountryStripper
        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();
        }