public Timetable BuildTimetable(ITransportInterface data)
        {
            DateTime startLoad = DateTime.Now;

            Timetable timetable = new Timetable();
            int totalTrainsPerWeek = 0;
            List<string> timetableSources = data.TimetableUrls;

            // download all the webpages concurrently
            WebDownloader downloader = new WebDownloader();
            Dictionary<string, string> downloadedPages = downloader.downloadWebpagesConcurrently(timetableSources);

            foreach (string s in timetableSources)
            {
                string webPage = downloadedPages[s];
                ITimetableExtractor timetableExtractor = data.TimetableExtractor;
                Service service = timetableExtractor.ExtractTimetable(webPage);
                timetable.AddService(service);
                totalTrainsPerWeek += service.NumberRoutes;
            }

            DateTime finishLoad = DateTime.Now;
            TimeSpan diff = finishLoad - startLoad;
            Console.WriteLine("Timetable data downloaded in {0}s{1}ms", (int)diff.TotalSeconds, diff.Milliseconds);
            return timetable;
        }
Example #2
0
        private void setTransportType(TransportType type)
        {
            TransportFactory factory = new TransportFactory();
            data = factory.TransportSource(type);

            int length = 80;

            sql_locationtextBox.Text = ShortenString(data.DefaultDBLocation.FullName, length);
            network_textBox.Text = ShortenString(data.DefaultNetworkLocation.FullName, length);
        }
Example #3
0
        public static void LoadNetworkDependants(FileInfo sqlDB, Network network, ITransportInterface data)
        {
            Dictionary<string, int> location_aliases = getNetworkAliases(sqlDB);
            List<LocationPair> touchingLocations = data.TouchingLocationsSource.getTouchingLocations(location_aliases);
            List<LocationPair> swappingLocations = data.SwappingLocationsSource.getSwappingLocations(location_aliases);

            DateTime startLoad = DateTime.Now;
            Dictionary<string, string> dic;
            //SQLiteDatabase db = new SQLiteDatabase(sqlDB);

            using (SQLiteConnection sql_connection = SQLiteDatabase.GetConnection(sqlDB))
            {
                sql_connection.Open();
                using (SQLiteTransaction sql_Transaction = sql_connection.BeginTransaction())
                {

                    // add the touching locations data

                    foreach (LocationPair tl in touchingLocations)
                    {
                        dic = new Dictionary<string, string>();
                        dic.Add(SQLFieldNames.TOUCHING_LOCATIONS_LOCATION1_ID, tl.Point1.ToString());
                        dic.Add(SQLFieldNames.TOUCHING_LOCATIONS_LOCATION2_ID, tl.Point2.ToString());

                        int tl_id = SQLiteDatabase.Insert(sql_connection, SQLFieldNames.TOUCHING_LOCATIONS, dic);
                    }

                    // add the swapping locations data

                    foreach (LocationPair tl in swappingLocations)
                    {
                        dic = new Dictionary<string, string>();
                        dic.Add(SQLFieldNames.SWAP_LOCATIONS_LOCATION1_ID, tl.Point1.ToString());
                        dic.Add(SQLFieldNames.SWAP_LOCATIONS_LOCATION2_ID, tl.Point2.ToString());

                        int tl_id = SQLiteDatabase.Insert(sql_connection, SQLFieldNames.SWAP_LOCATIONS, dic);
                    }

                    sql_Transaction.Commit();
                }

            }

            DateTime finishLoad = DateTime.Now;
            TimeSpan diff = finishLoad - startLoad;
            Console.WriteLine("Network Dependant Data Entered in {0}s{1}ms", (int)diff.TotalSeconds, diff.Milliseconds);
        }