Exemplo n.º 1
0
        private void timer_tick(object sender, EventArgs e)
        {
            double secs      = 0;
            string cycleTime = cycleTimeInput.Text;

            int.TryParse(cycleTime, out int time);
            string cycleNum = cycleNumInput.Text;

            double.TryParse(cycleNum, out double duration);
            //Creates a copy of myFlightList
            FlightsList tempFlightsList = new FlightsList();

            tempFlightsList = myFlightsList.Copy();
            //Saves simulation to the stack

            FlightStack.Push(tempFlightsList);

            //int time = Convert.ToInt32(cycleTime);
            int flightsInDestination = 0;

            //Simulates a Cycle and updates position in Picturebox
            myFlightsList.FlightsSimulation(time);


            if ((duration * 60) != secs)
            {
                // i es el contador para los ciclos de la simulacion
                for (int j = 0; j < myFlightsList.Number; j++)
                {
                    if (myFlightsList.Flights[j].Simulator(time) == -1)
                    {
                        flightsInDestination++;
                    }

                    aircraftVector[j].Location = new Point((int)myFlightsList.Flights[j].PositionX, (int)myFlightsList.Flights[j].PositionY);
                    //0.7.Helper: Function to print the sector occupation in DGV
                    loadSectorInfo();
                    //Change Sector Color
                    panel1.Invalidate();

                    secs++;
                }
            }
            else
            {
                if ((duration * 60) == secs)
                {
                    timer1.Stop();
                    StopSimulation();
                }
            }
            if ((myFlightsList.Number > 0) && (flightsInDestination == myFlightsList.Number))
            {
                timer1.Stop();
                MessageBox.Show("Todos los vuelos han llegado a su destino.");
                StopSimulation();
            }
        }
Exemplo n.º 2
0
 //Restart simulation
 private void reiniciarSimulaciónToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("¿Está seguro que desea reiniciar la simulación?", "Reiniciando Simulación", MessageBoxButtons.YesNo) ==
         DialogResult.Yes)
     {
         myFlightsList = originalFlightList;
         //Clean Flights
         panel1.Controls.Clear();
         FlightStack.Clear();
         //Fill the texbox with active flight number
         this.totalFlightsLabel.Text = myFlightsList.Number.ToString();
         //0.7.Helper: Function to print the sector occupation in to DGV
         loadSectorInfo();
     }
 }
Exemplo n.º 3
0
        private void FindFlights(string departureCity, string destinationCountry, string destinationCity)
        {
            //set destination City
            DestinationCityElm.SelectByText(destinationCity);
            if (!DatesSet)
            {
                SetDates();
            }

            try
            {
                Screenshot screen = ((ITakesScreenshot)_driver).GetScreenshot();
                screen.SaveAsFile($"PegasBeforeSearch{DateTime.Now.ToString("yyyy.MM.dd.HH.m")}.png", ScreenshotImageFormat.Png);

                SearchButtonElm.Click();
                Thread.Sleep(5000);
            }
            catch (ElementClickInterceptedException ex)
            {
                _logger?.LogError(ex, $"departureCity {departureCity} destination {destinationCity}");
                ReloadAndRestorePage(departureCity, destinationCountry, destinationCity);
            }
            Thread.Sleep(5000);

            var flightTables = _driver.FindElements(By.XPath(OneWayFlightsPath));

            if (flightTables.Any())
            {
                var departureCityCode   = IataCities.FirstOrDefault(icity => icity.Name == departureCity)?.Code;
                var destinationCityCode = IataCities.FirstOrDefault(icity => icity.Name == destinationCity)?.Code;
                if (departureCityCode == null)
                {
                    Debug.WriteLine(departureCityCode);
                }
                if (destinationCityCode == null)
                {
                    Debug.WriteLine(destinationCityCode);
                }
                FlightsList.AddRange(ParseFlights(departureCity, departureCityCode, destinationCountry, destinationCity, flightTables.First()));
            }
            else
            {
                _logger?.LogWarning($"[Pegas] Город вылета {departureCity}. " +
                                    $"Страна прилёта {destinationCountry}. Город прилёта {destinationCity}. " +
                                    $"Нет рейсов");
            }
        }
Exemplo n.º 4
0
        /*************************************** Simulation Section ****************************************************
         *  5. Introducir el tiempo de ciclo de simulación (en minutos) y avanzar la simulación ciclo a ciclo.
         *  6. Reiniciar la simulación.
         *  7. Introducir el tiempo de ciclo (en minutos) y la duración de la simulación (en minutos) y
         *  avanzar de forma automática (un ciclo cada segundo). La aplicación debe permitir pausar y
         *  reanudar la simulación en cualquier momento.
         *  8. Identificar visualmente, en cada ciclo, el nivel de ocupación del sector.
         ****************************************************************************************************************/

        private void AvanzarSimulacion_Click(object sender, EventArgs e)
        {
            try
            {
                string cycleTime            = cycleTimeInput.Text;
                int    time                 = Convert.ToInt32(cycleTime);
                int    flightsInDestination = 0;
                //Creates a copy of myFlightList
                FlightsList tempFlightsList = new FlightsList();
                tempFlightsList = myFlightsList.Copy();

                //Saves simulation to the stack

                FlightStack.Push(tempFlightsList);

                //Simulates a Cycle and updates position in Picturebox
                myFlightsList.FlightsSimulation(time);
                //0.7.Helper: Function to print the sector occupation in to DGV
                loadSectorInfo();
                panel1.Invalidate();
                for (int i = 0; i < myFlightsList.Number; i++)
                {
                    aircraftVector[i].Location = new Point((int)myFlightsList.Flights[i].PositionX, (int)myFlightsList.Flights[i].PositionY);

                    if (myFlightsList.Flights[i].Simulator(time) == -1)
                    {
                        flightsInDestination++;
                    }
                }

                //Shows a message if at least one flight has arrived
                if (flightsInDestination > 0)
                {
                    MessageBox.Show(flightsInDestination + " vuelos han llegado con éxito a su destino, para más información consulte la tabla de información de vuelos.",
                                    "Hay vuelos que han llegado a su destino.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Asegurece de insertar un tiempo de simulación y que este sea de valor entero.", "Tiempo de simulación nulo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        private void FindFlights(string airCompany, string departureCity, string destinationCity)
        {
            //new Actions(_driver).MoveToElement(SearchButtonElm).MoveByOffset(0, 30).Click().Perform();
            AirCompanyDropDownElm.Click();

            var by = string.Format(SearchPattern, airCompany);

            Thread.Sleep(2200);
            AirCompanyElm.FindElement(By.XPath(by)).Click();
            Thread.Sleep(2200);

            SearchButtonElm.Click();
            Thread.Sleep(25500);

            var flights = _driver.FindElements(By.XPath(ResultsTablePath));

            if (flights.Any())
            {
                InitControls();
                FlightsList.AddRange(ParseFlights(departureCity, destinationCity, airCompany, flights.First()));
            }
        }
Exemplo n.º 6
0
        private void Back_Click(object sender, EventArgs e)
        {
            //Change Sector Color
            int         StackNum = FlightStack.Count;
            FlightsList FlightAux = new FlightsList();
            double      X, Y;

            panel1.Invalidate();

            //Checks if the stack is empty and shows a messagebox informing
            if (StackNum < 1)
            {
                MessageBox.Show("No hay ciclos anteriores");
            }
            else
            {
                FlightAux = FlightStack.Pop();

                for (int i = 0; i < myFlightsList.Number; i++)
                {
                    X = FlightAux.Flights[i].PositionX;

                    myFlightsList.Flights[i].PositionX = X;

                    Y = FlightAux.Flights[i].PositionY;

                    myFlightsList.Flights[i].PositionY = Y;

                    aircraftVector[i].Location = new Point((int)myFlightsList.Flights[i].PositionX, (int)myFlightsList.Flights[i].PositionY);
                }
            }

            //0.6.Helper: Stop and change button color and text, show is stopped and can start(Green)
            StopSimulation();
            //0.5.Helper: Function to print the sector occupation
            loadSectorInfo();
        }
Exemplo n.º 7
0
        private static void Main(string[] args)
        {
            FlightsList myFlightList = new FlightsList();
            Sector      mySector     = new Sector();

            //Project title
            Console.WriteLine("SIMULADOR DE TRAFICO AEREO - GRUPO 6");

            //Condition variable if the files loads
            bool flightLoaded  = false;
            bool sectorsLoaded = false;

            //Loading the lists for work w/it
            int resultFlights = myFlightList.LoadFlightsFile(fileUserFlights);
            int resultSector  = mySector.LoadSectorFile(fileUserSector);

            //Check if Flight File is correctly loaded
            if (resultFlights == -1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Fichero de vuelos no se ha encontrado.");
                Console.ResetColor();
            }
            else
            {
                if (resultFlights == -2)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Fichero de vuelos no tiene un formato válido.");
                    Console.ResetColor();
                }
                else
                {
                    //Shows that the file is correctly readed
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Fichero de vuelos leído correctamente");
                    //File Loaded
                    flightLoaded = true;
                    //Reset the color
                    Console.ResetColor();
                }
            }


            //Check if Sectors File is correctly loaded
            if (resultSector == -1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Fichero de sectores no se ha encontrado.");
                Console.ResetColor();
            }
            else
            {
                if (resultSector == -2)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Fichero de sectores no tiene un formato válido.");
                    Console.ResetColor();
                }
                else
                {
                    //Indica que el archivo se ha leido correctamente
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Fichero de sectores leído correctamente");
                    //Variable fichero cargado
                    sectorsLoaded = true;
                    //Limpia la consola para que el usuario pueda continuar con la siguiente instruccion
                    Console.ResetColor();
                }
            }

            //If both have been loaded
            if ((flightLoaded == true) && (sectorsLoaded == true))
            {
                //Se muestran las opciones al usuario
                Welcome();
                bool exit = false;

                while (!exit)
                {
                    switch (Console.ReadLine())
                    {
                    //MOSTRAS EMPRESAS POR PANTALLA
                    case "1":
                    {
                        //Muestra la lista de vuelos
                        myFlightList.ShowConsoleFlights();
                    }
                    break;

                    case "2":
                    {
                        //Shows the sector's traffic
                        mySector.GetTraffic(myFlightList);
                    }
                    break;

                    case "3":
                    {
                        Console.Write("Escribe el tiempo de ciclo:");
                        try
                        {
                            int inputUserCicle = Convert.ToInt32(Console.ReadLine());
                            myFlightList.FlightsSimulation(inputUserCicle);
                        }
                        catch (FormatException)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write("Error de formato en la entrada, volviendo al menú principal");
                            Console.ResetColor();
                        }
                    }
                    break;

                    case "4":
                    {
                        myFlightList.SaveList(fileNameExport);
                        exit = true;
                    }
                    break;
                    }
                    Console.WriteLine();
                    Welcome();
                }
            }
            else
            {
                if ((flightLoaded != true) && (sectorsLoaded != true))
                {
                    Console.WriteLine("\nLos ficheros no se han podido leer, el simulador no puede abrirse sin datos.");
                }
                else
                {
                    if ((flightLoaded != true) || (sectorsLoaded != true))
                    {
                        Console.WriteLine("\nEl simulador no puede funcionar con alguno de los dos ficheros comprometido.");
                    }
                    else
                    {
                        Console.WriteLine("\nError inesperado");
                    }
                }
                Console.Write("Presione una tecla para cerrar el programa.....");
                Console.ReadKey();
            }
        }
Exemplo n.º 8
0
 public void SetInfo(FlightsList flightsListObject)
 {
     this.flightsListInfo = flightsListObject;
 }