Example #1
0
 //Stop_Time
 public void madeStop_Time(string city_name)
 {
     if (File.Exists("GTFS/" + city_name + "/stop_times.txt"))
     {
         Console.WriteLine("Rozpoczynam STOP_TIMES");
         string[] lines      = File.ReadAllLines("./GTFS/" + city_name + "/stop_times.txt");
         int      postep     = 0;
         int      poprzednie = 0;
         stop_times = new Stop_time[lines.Length];
         for (int i = 0; i < lines.Length; i++)
         {
             if (poprzednie < postep)
             {
                 Console.Clear();
                 Console.WriteLine("Ładowanie Stop_times: " + postep + "%");
                 poprzednie++;
             }
             if (i != 0)
             {
                 Stop_time temp = new Stop_time(stop_time_keys, lines[i]);
                 temp.ExtendStop_time(stops[temp.stop_id]);
                 trips[temp.trip_id].Stop_Times.Add(temp);
                 stop_times[i] = temp;
                 //stop_times[i].ExtendStop_time(Array.Find(stops,s => s.id == stop_times[i].stop_id));
                 //Array.Find(trips, t => t.id == stop_times[i].trip_id).Stop_Times.Add(stop_times[i]);
                 if (i % (int)(lines.Length * 0.1) == 0)
                 {
                     postep += 10;
                 }
             }
             else
             {
                 stop_times[i] = new Stop_time();
             }
         }
     }
 }
Example #2
0
        private async void GenerateGTFS_Click(object sender, RoutedEventArgs e)
        {
            Agency agency = new Agency(currentDirectory + @"\GTFS");

            Program.MakeAgencyTXT();
            Stop_time stopTime = new Stop_time(currentDirectory + @"\GTFS");
            Trip      trip     = new Trip(currentDirectory + @"\GTFS");



            WaitingWindow waitingWindow = new WaitingWindow(actualWindow);

            waitingWindow.Owner = this;
            waitingWindow.Show();
            bool response = await Program.MakeAsyncTripsnStopTimes();

            BlockMainWindow(false);
            waitingWindow.Close();

            if (response)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter           = "Pliki ZIP|*.zip";
                saveFileDialog.FilterIndex      = 1;
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string year  = DateTime.Now.Date.ToString().Remove(5);
                string month = DateTime.Now.Date.ToString().Remove(8).Remove(0, 5);
                string day   = DateTime.Now.Date.ToString().Remove(10).Remove(0, 8);
                saveFileDialog.FileName   = CityName.Text.ToLower().Replace(' ', '-') + "-" + year + month + day + ".zip";
                saveFileDialog.DefaultExt = "zip";
                Nullable <bool> dialogResult = saveFileDialog.ShowDialog();
                if (dialogResult == true)
                {
                    try
                    {
                        if (File.Exists(saveFileDialog.FileName))
                        {
                            File.Delete(saveFileDialog.FileName);
                        }
                        ZipFile.CreateFromDirectory(currentDirectory + @"\GTFS", (saveFileDialog.FileName));
                        Interfejs.Message successMessage = new Interfejs.Message(this, "Gratuluję", "Udało się pomyślnie wytworzyć pliki GTFS oraz spakować je do ZIP-a.");
                        successMessage.Owner = this;
                        successMessage.Show();
                        successMessage.Topmost = true;
                        ClearUI();

                        string path = currentDirectory + @"\validation.bat";
                        if (File.Exists(path))
                        {
                            File.Delete(path);                    //del existing one
                        }
                        using (FileStream fs = File.Create(path)) // now create new
                        {
                            Byte[] text = new UTF8Encoding(true).GetBytes(@"start """" /B fv.exe """ + saveFileDialog.FileName + @"""");
                            fs.Write(text, 0, text.Length);
                        }
                        System.Diagnostics.Process.Start("validation.bat");
                    }
                    catch
                    {
                        Interfejs.Message successMessage = new Interfejs.Message(this, "Błąd #02", "Nie udało się wytworzyć plików GTFS. Sprawdź zgodność Twoich plików z wymaganymi schematami. Zamknij pliki robocze z rozkładami i przystankami.");
                        successMessage.Owner = this;
                        successMessage.Show();
                        successMessage.Topmost = true;
                        ClearUI(false);
                    }
                }
            }
            else
            {
                Interfejs.Message successMessage = new Interfejs.Message(this, "Błąd #01", "Nie udało się wytworzyć plików GTFS. Sprawdź zgodność Twoich plików z wymaganymi schematami. Zamknij pliki robocze z rozkładami i przystankami.");
                successMessage.Owner = this;
                successMessage.Show();
                successMessage.Topmost = true;
                ClearUI(false);
            }
        }