示例#1
0
 static void DatabaseCache()
 {
     while (true)
     {
         Dictionary <int, Adres> temp = new Dictionary <int, Adres>(addCache);
         foreach (Adres adres in temp.Values)
         {
             int key = adres.ID;
             if (!cacheDone.Contains(key))
             {
                 AdresDatabase.addAdres(adres);
                 cacheDone.Add(key);
                 savedAddresses.Add(key);
             }
         }
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            // Unzip File
            // FileUtil.UnZip(@"C:\Users\timde\source\repos\Adreslezen\Adreslezen\Data\CRAB_Adressenlijst_GML.zip", @"C:\Users\timde\source\repos\Adreslezen\Adreslezen\Data\Extract");

            // Run the progress thread
            Console.WriteLine("--------------------------");
            Console.WriteLine("Project created by Tim De Smet");
            Console.WriteLine("HoGent Adreslezen");
            Console.WriteLine("--------------------------");
            Console.WriteLine(" ");
            Console.WriteLine("Loading address data...");
            Console.WriteLine(" ");

            // Create database connnection
            database = new DatabaseUtil(mysql_host, mysql_user, mysql_pass, mysql_data);

            // Setup running tasks
            var t  = Task.Run(() => ProgressThread());
            var tt = Task.Run(() => DatabaseCache());

            // Start loading stopwatch
            var watch = System.Diagnostics.Stopwatch.StartNew();

            using (FileStream fs = File.Open(@"C:\Users\timde\source\repos\Data\Extract\GML\CrabAdr.gml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        bool          reading = false;
                        List <string> obj     = new List <string>();

                        String line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            // Start logging
                            if (!reading && line.Contains("agiv:CrabAdr"))
                            {
                                obj.Clear();
                                reading = true;
                            }

                            // Add line
                            if (reading)
                            {
                                obj.Add(line);
                            }

                            // Stop logging and build object
                            if (reading && line.Contains("/agiv:CrabAdr"))
                            {
                                reading = false;
                                buildObject(obj);
                            }
                            ++count;
                        }
                    }

            watch.Stop();

            // Save additional data to database
            AdresDatabase.saveCities(cities);
            AdresDatabase.saveStreets(streets);
            AdresDatabase.saveLocation(locations);

            while (savedAddresses.Count < 3632646)
            {
                Thread.Sleep(20);
            }

            t.Wait();
            tt.Wait();

            // Search
            while (true)
            {
                Console.Clear();
                Console.WriteLine("[1] Search on City");
                Console.WriteLine("[2] Search on Street");
                Console.WriteLine("[3] City information");
                Console.WriteLine("[4] Stats");
                Console.Write("Search type: ");
                String searchType = Console.ReadLine();

                if (searchType.Equals("1"))
                {
                    Console.Clear();
                    Console.Write("Input a city name: ");
                    String arg1 = Console.ReadLine();
                    foreach (Gemeente city in cities.Values)
                    {
                        if (city.Gemeentenaam.Equals(arg1))
                        {
                            Console.Clear();
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("(" + arg1 + ") - Found streets:");
                            Console.WriteLine("--------------------------");
                            foreach (Straatnaam straat in streets.Values)
                            {
                                if (straat.Gemeente.Equals(city))
                                {
                                    Console.WriteLine(straat.Streetname);
                                }
                            }
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("Press ENTER to continue...");
                            Console.ReadLine();
                        }
                    }
                }
                if (searchType.Equals("2"))
                {
                    Console.Clear();
                    Console.Write("Input a streetname: ");
                    String          arg1      = Console.ReadLine();
                    List <Gemeente> gemeentes = new List <Gemeente>();
                    foreach (Straatnaam straat in streets.Values)
                    {
                        if (straat.Streetname.Equals(arg1))
                        {
                            if (!gemeentes.Contains(straat.Gemeente))
                            {
                                gemeentes.Add(straat.Gemeente);
                            }
                        }
                    }
                    Console.Clear();
                    Console.WriteLine("--------------------------");
                    Console.WriteLine("(" + arg1 + ") - Found cities:");
                    Console.WriteLine("--------------------------");
                    foreach (Gemeente gemeente in gemeentes)
                    {
                        Console.WriteLine(gemeente.Gemeentenaam);
                    }
                    Console.WriteLine("--------------------------");
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ReadLine();
                }
                if (searchType.Equals("3"))
                {
                    Console.Clear();
                    Console.Write("Input a city name: ");
                    String arg1 = Console.ReadLine();

                    foreach (Gemeente city in cities.Values)
                    {
                        if (city.Gemeentenaam.Equals(arg1))
                        {
                            Console.Clear();
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("(" + arg1 + ") - Found information:");
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("Name: " + city.Gemeentenaam);
                            Console.WriteLine("NisCode: " + city.NIScode);
                            Console.WriteLine("Postcode: N/A");

                            int strcount = 0;
                            foreach (Straatnaam straat in streets.Values)
                            {
                                if (straat.Gemeente.Equals(city))
                                {
                                    ++strcount;
                                }
                            }

                            Console.WriteLine("Total streets: " + strcount);
                            Console.WriteLine("--------------------------");
                            Console.WriteLine("Press ENTER to continue...");
                            Console.ReadLine();
                            break;
                        }
                    }
                }
                if (searchType.Equals("4"))
                {
                    Console.Clear();
                    Console.WriteLine("--------------------------");
                    Console.WriteLine("Statistics:");
                    Console.WriteLine("--------------------------");
                    Console.WriteLine("Total lines: " + count);
                    Console.WriteLine("Total addresses: " + addIds.Count);
                    Console.WriteLine("Total cities: " + cities.Count);
                    Console.WriteLine("Total streets: " + streets.Count);
                    Console.WriteLine("Total locations: " + locations.Count);
                    Console.WriteLine("Loading time: " + watch.Elapsed.TotalSeconds + " sec.");
                    Console.WriteLine("--------------------------");
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ReadLine();
                }
            }
        }