Exemple #1
0
        public void AllowLanding(IPlane plane)
        {
            if (plane == null)
            {
                return;
            }
            IFlightDatabase database = FlightDatabase.Instance;
            //Nalazimo sve letove koji slecu na aerodrom vezan za ovu FlightControl-u
            //Ako nema jednog leta medju njima koji ima zadati avion(plane) baca se izuzetak
            List <IFlight> flights   = database.FindByDestAirport(Airport);
            IFlight        theFlight = null;

            foreach (IFlight flight in flights)
            {
                if (flight.GetPlane() == plane)
                {
                    theFlight = flight;
                }
            }
            if (theFlight != null)
            {
                List <ITicket> tickets = theFlight.GetTickets();
                foreach (ITicket ticket in tickets)
                {
                    ticket.SetPassenger(null);
                }
            }
            else
            {
                throw new PlaneCanNotLandException("Avion ne slece na taj aerodrom");
            }
            plane.Status = Status.FINISHED; //Avion je sleteo
            plane.ClearPassenger();         //brisu se putnicima karte
        }
Exemple #2
0
        /// <summary>
        /// Compute Calculated properties before inserting in database
        /// </summary>
        /// <param name="flight"></param>
        private void InitializeCalculatedProperties(IFlight flight)
        {
            flight.Distance = GPSUtility.DistanceTo(flight.DepartureAirport.Latitude, flight.DepartureAirport.Longitude, flight.DestinationAirport.Latitude, flight.DestinationAirport.Longitude);

            //For the fuel consumption we assume the InFlyFuelConsumption is express in L/100km
            flight.FuelNeeded = flight.Aircraft.InTakeOffFuelConsumption + ((flight.Distance * flight.Aircraft.InTakeOffFuelConsumption) / 100);
        }
        private static IFlight GetPlane(SeatStates[] s_state, SeatTypes[] s_type, Planes plane, Cities des, Cities ori, int seatAmount, DateTime DepTime, DateTime ArivTime, decimal cost, int flighBarcode)
        {
            IFlight createdFlight = null;

            switch (plane)
            {
            case Planes.Earth2K:
                createdFlight = new Earth2K();
                break;
                //case PlaneType.MarsBr:
                //    createdDwelling = new MarsBr();
                //    break;
                //case PlaneType.NeptuneAqua:
                //    createdDwelling = new NeptuneAqua();
                //    break;
                //case PlaneType.UrainusLamba:
                //    createdDwelling = new UrainusLamba();
                //    break;
                //case PlaneType.SaturnRhea:
                //    createdDwelling = new SaturnRhea();
                //    break;
            }
            createdFlight.Cost          = cost;
            createdFlight.ArrivalTime   = ArivTime;
            createdFlight.DepartureTime = DepTime;
            return(createdFlight);
        }
        private void DispatchBaggage(IFlight flight)
        {
            var baggage = new Baggage()
            {
                Flight = flight
            };


            int chosen  = FindMostSuitableCheckin(baggage);
            var checkIn = checkins[chosen];
            var queue   = checkinQueues[chosen];

            baggage.TransportationStartTime = TimerService.GetTicksSinceSimulationStart();
            baggage.TransporterId           = "Queue CheckIn";

            if (checkIn.NodeStatus == NodeStatus.Free)
            {
                checkIn.PassBaggage(baggage);
                checkIn.OnNodeStatusChangedToFree -= () => PassQueuedBaggage(chosen);
            }
            else
            {
                queue.Enqueue(baggage);
                if (checkIn.OnNodeStatusChangedToFree == null)
                {
                    checkIn.OnNodeStatusChangedToFree += () => PassQueuedBaggage(chosen);
                }
            }

            flight.DispatchedBaggageCount++;
        }
    public void SimpleInteraction()
    {
        IFlight flight = null;

        flight         = ExampleBuilder();
        flight.NextLeg = flight;
    }
 public FlightController(IFlight flightService, IAirport airportService, IAirPlane airPlaneService, IFlightHelpersServices flightHelpersServices)
 {
     _airportService        = airportService;
     _airPlaneService       = airPlaneService;
     _flightService         = flightService;
     _flightHelpersServices = flightHelpersServices;
 }
Exemple #7
0
        public void AddFlight(IFlight flight)
        {
            var flightToAdd = (Flight)flight;

            int flightTypeId   = this.msSqlData.FlightTypes.Add(flightToAdd.FlightType);
            int airlineId      = this.msSqlData.Airlines.Add(flightToAdd.Plane.Airlines);
            int airportId      = this.msSqlData.Airports.Add(flightToAdd.DestinationAirport);
            int manufacturerId = this.msSqlData.Manufacturers.Add(flightToAdd.Plane.Manufacturers);
            int modelId        = this.msSqlData.Models.Add(flightToAdd.Plane.Models);
            int planeId        = this.msSqlData.Planes.Add(new Plane
            {
                PlanePass = new PlanePassport
                {
                    RegistrationNumber = flightToAdd.Plane.PlanePassport.RegistrationNumber,
                    YearOfRegistration = flightToAdd.Plane.PlanePassport.YearOfRegistration,
                    State = flightToAdd.Plane.PlanePassport.State
                },
                ManufacturerId = manufacturerId,
                ModelId        = modelId,
                AirlineId      = airlineId
            });
            int terminalId = this.msSqlData.Terminals.Add(flightToAdd.Terminal);

            this.msSqlData.Flights.Add(new Flight
            {
                SheduledTime         = flightToAdd.SheduledTime,
                DestinationAirportId = airportId,
                FlightTypeId         = flightTypeId,
                PlaneId    = planeId,
                TerminalId = terminalId
            });
        }
        /*
         * updates flight in database
         */
        public async Task Update(IFlight flight)
        {
            var entry = db.Entry(flight);

            entry.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await db.SaveChangesAsync();
        }
Exemple #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddIdentity <AuthUser, ApplicationRole>(o =>
            {
                o.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'*+-/=?^_`{|}~.@";
                // configure identity options
                o.Password.RequireDigit           = false;
                o.Password.RequireLowercase       = false;
                o.Password.RequireUppercase       = false;
                o.Password.RequireNonAlphanumeric = false;
                o.Password.RequiredLength         = 6;
            })
            .AddEntityFrameworkStores <FlightContext>();

            services.AddMvc();
            // Add a singleton instance of our config
            services.AddSingleton(Configuration);
            // Inject our services
            services.AddScoped <IPlane, PlaneService>();
            services.AddScoped <IEmployee, EmployeeService>();
            services.AddScoped <IFlight, FlightService>();

            services.AddTransient <IFlight, FlightService>();

            services.AddHangfire(x => x.UseSqlServerStorage(Configuration.GetConnectionString("FlightConnection")));

            services.AddDbContext <FlightContext>(options => options
                                                  .UseSqlServer(Configuration.GetConnectionString("FlightConnection"), builder => builder.MigrationsAssembly("FlightData")));

            var provider = services.BuildServiceProvider();

            _flight = provider.GetService <IFlight>();
        }
Exemple #10
0
        public static void RebuildFlight(ref IFlight[] flights)
        {
            IFlight tmp = flights[0];

            for (int i = 0; i < flights.Length; i++)
            {
                if (tmp == null)
                {
                    if (flights[i] != null)
                    {
                        flights[i - 1] = flights[i];
                        flights[i]     = null;
                        tmp            = null;
                    }
                    else if (flights[i] == null && i != 0)
                    {
                        break;
                    }
                }
                else
                {
                    tmp = flights[i];
                }
            }
        }
Exemple #11
0
 /// <summary>
 /// Validate data of the airport
 /// </summary>
 /// <param name="aireport">airport to validate</param>
 /// <returns>True : the airport is valid; False : The airport is not valid</returns>
 private bool CheckFlightData(IFlight flight)
 {
     return(!(
                string.IsNullOrWhiteSpace(flight.Identifier) ||
                flight.DepartureAirport.Id == flight.DestinationAirport.Id ||
                flight.Aircraft.Id < 0));
 }
Exemple #12
0
        public Response DeleteById(int id)
        {
            IFlight response = m_InformationFinder.Delete(id);

            return(response == null
                       ? HttpStatusCode.NotFound
                       : AsJson(response));
        }
Exemple #13
0
        public IFlight Delete(int id)
        {
            IFlight entity = m_Repository.FindById(id);

            m_Repository.Remove(entity);

            return(entity);
        }
Exemple #14
0
        public Ticket(IFlight flight, SeatClass seatClass, decimal price, int numberOfSeat)
        {
            Flight = flight;

            ClassOfSeat  = seatClass;
            Price        = price;
            NumberOfSeat = numberOfSeat;
        }
        public static IFlight[] SearchByMoney(IFlight[] flights, decimal money)
        {
            IFlight[] foundFlights = new IFlight[flights.Length];
            int       i            = 0;

            foreach (var flight in flights)
            {
                foundFlights[i++] = flight.SearchByCost(money);
            }
            return(foundFlights);
        }
 public void AddLeg(IFlight leg)
 {
     foreach (IFlight flight in _flightLegs)
     {
         if (flight.Equals(leg))
         {
             throw new FlightAlreadyPresentException();
         }
     }
     _flightLegs.Add(leg);
 }
Exemple #17
0
        public void SetOnRunway(IPlane plane)
        {
            //Proveravamo da li ima slobodnih pista da postavimo avion
            //Proveravamo da li je avion u letu vec
            if (NumOfRunways == 0)
            {
                throw new NoFreeRunwayException("Nema dovoljno pista ");
            }
            if (plane.Status == Status.ONFFLIGHT)
            {
                throw new PlaneNotOnGroundException("avion je u letu: ");
            }

            //kada postavimo avion smanjujemo broj slobodnih pista za 1 i postavljamo status aviona na READY
            NumOfRunways--;
            plane.Status = Status.READY;

            //Nalazimo sve letove koji imaju kao izvorisni aerodrom onaj za koga je vezana kontrola leta
            IFlightDatabase database  = FlightDatabase.Instance;
            List <IFlight>  flights   = database.FindBySrcAirport(Airport);
            IFlight         theFlight = null;

            //Onaj let koji je vezan za nas dati avion(plane)
            //je let koji nam treba zbog liste Ticket-a
            //svaki ticket sadrzi referencu na putnika,
            //koji treba da se ubaci u avion
            foreach (IFlight flight in flights)
            {
                if (flight.GetPlane() == plane)
                {
                    theFlight = flight;
                }
            }
            if (theFlight != null)
            {
                List <ITicket> tickets = theFlight.GetTickets();
                foreach (ITicket ticket in tickets)
                {
                    if (ticket.GetPassenger() != null)
                    {
                        plane.AddPassenger(ticket.GetPassenger());
                    }
                }
            }
            else
            {   //ako nije pronadjen avion baca se izuzetak
                throw new PlaneNotSuitableException("Ne postoji let za ovaj avion: ");
            }
            if (plane != null)
            {
                Planes.Add(plane);
            }
        }
        public IFlight[] Retrieve(IFlightData data, ISearchData searchData)
        {
            IFlightData[] flightDatas = proxyFlight_.GetList(data, searchData);

            IFlight[] flights = new IFlight[flightDatas.Length];
            for (int i = 0; i < flights.Length; ++i)
            {
                flights[i] = new FlightImpl(proxyFlight_, flightDatas[i]);
            }

            return(flights);
        }
Exemple #19
0
        public void AskPermissionToLand(IFlight flight)
        {
            Console.WriteLine("Granting permission to land: {0}", flight.Name);

            foreach (IFlight flt in landingFlights)
            {
                if (flt.Name != flight.Name)
                {
                    flt.GetNotified();
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Converts IFlight entity to FlightModel
        /// </summary>
        public static FlightModel ToModel(this IFlight flight)
        {
            FlightModel flightModel = new FlightModel();

            flightModel.Id                   = flight.Id;
            flightModel.Identifier           = flight.Identifier;
            flightModel.DepartureAirportId   = flight.DepartureAirport.Id;
            flightModel.DestinationAirportId = flight.DestinationAirport.Id;
            flightModel.AircraftId           = flight.Aircraft.Id;
            flightModel.Days                 = flight.Days;

            return(flightModel);
        }
Exemple #21
0
        int IComparer.Compare(object x, object y)
        {
            IFlight f1 = x as IFlight;
            IFlight f2 = y as IFlight;

            if (f1 != null && f2 != null)
            {
                return(f1.FlightNumber.CompareTo(f2.FlightNumber));
            }
            else
            {
                return(0);
            }
        }
Exemple #22
0
        internal static void OperatePassengerMenu(IFlight[] flights)
        {
            Console.Clear();
            Printer.PrintAllFlights(flights);
            Console.WriteLine("To go back press Enter.");
            Console.WriteLine("Available flights:");
            for (int i = 0; i < flights.Length; i++)
            {
                if (flights[i] == null)
                {
                    break;
                }
                Console.Write($"{flights[i].FlightNumber.ToString()}\t");
            }

            Console.WriteLine();


            Console.WriteLine("Enter the flight number to edit passenger`s information:");//podumat o vihode
            int  flightNumber = 0;
            bool tryByte      = int.TryParse(Console.ReadLine(), out flightNumber);

            if (!tryByte)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Incorrect input");
                Console.ResetColor();
            }
            else
            {
                IFlight flight = Searcher.SearchByFlightNumber(flights, flightNumber);
                if (flight != null)
                {
                    for (int i = 0; i < flights.Length; i++)
                    {
                        if (flight == flights[i])
                        {
                            GetPassengerMenu(flights[i]);
                        }
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Entered flight does not exist!");
                    Console.ResetColor();
                }
            }
        }
        private IFlight CreateItem(Browser browser,
                                   int id = 1)
        {
            IFlight model = CreateModelForPutTest(id);

            BrowserResponse result = browser.Post(BasePath,
                                                  with =>
            {
                with.JsonBody(model);
            });

            var response = result.Body.DeserializeJson <Flight>();

            return(response);
        }
        private void AssertFlight(IFlight expected,
                                  IFlight actual)
        {
            Console.WriteLine("Comparing Flight with id {0} and {1}...",
                              expected.Id,
                              actual.Id);

            Assert.AreEqual(expected.Arrival,
                            actual.Arrival,
                            "Arrival");

            Assert.AreEqual(expected.Departure,
                            actual.Departure,
                            "Departure");
        }
Exemple #25
0
 public static FlightModel ToFlightModel(this IFlight flight)
 {
     return(new FlightModel
     {
         Name = flight.Name,
         FuelConsumptionPerDistance = flight.FuelConsumptionPerDistance,
         FuelConsumptionTakeoffEffort = flight.FuelConsumptionTakeoffEffort,
         DepartureAirportName = flight.DepartureAirport.AirportName,
         DepartureAiportLatitude = flight.DepartureAirport.GetLatitude(),
         DepartureAirportLongitude = flight.DepartureAirport.GetLongitude(),
         DestinationAirportName = flight.DestinationAirport.AirportName,
         DestinationAirportLatitude = flight.DestinationAirport.GetLatitude(),
         DestinationAirportLongitude = flight.DestinationAirport.GetLongitude()
     });
 }
Exemple #26
0
        public static void DrawTicketsInfo(IFlight flight)
        {
            Table tickeTable = new Table(String.Format("Price table for {0}", flight.Type));
            tickeTable.AddColumn("Flight number", 13, Align.Left);
            List<string> row = new List<string>();
            row.Add(flight.FlightNumber);

            foreach (SeatType seatType in flight.GetSeatTypes())
            {
                tickeTable.AddColumn(seatType.Name,20,Align.Right);
                row.Add(flight.GetTicketCost(seatType).ToString());
            }
            tickeTable.DrawHead();
            tickeTable.DrawRow(row.ToArray());
            tickeTable.DrawFooter();
        }
 public void SaveFlight(IFlight flight)
 {
     using (var connection = new SQLiteConnection(_connectionString))
         using (var command = connection.CreateCommand())
         {
             connection.Open();
             command.CommandText = "INSERT INTO flight (flight_name,fuel_consumption_per_distance,fuel_consumption_takeoff_effort," +
                                   "departure_airport_name, departure_airport_latitude, departure_airport_longitude," +
                                   "destination_airport_name, destination_airport_latitude, destination_airport_longitude" +
                                   $") VALUES ('{flight.Name}', {flight.FuelConsumptionPerDistance}, {flight.FuelConsumptionTakeoffEffort},'{flight.DepartureAirport.AirportName}',{flight.DepartureAirport.GetLatitude()}, {flight.DepartureAirport.GetLongitude()}, '{flight.DestinationAirport.AirportName}', {flight.DestinationAirport.GetLatitude()}, {flight.DestinationAirport.GetLongitude()})" +
                                   $"ON CONFLICT(flight_name) DO UPDATE SET fuel_consumption_per_distance = {flight.FuelConsumptionPerDistance},fuel_consumption_takeoff_effort={flight.FuelConsumptionTakeoffEffort}," +
                                   $"departure_airport_name='{flight.DepartureAirport.AirportName}',departure_airport_latitude={flight.DepartureAirport.GetLatitude()}, departure_airport_longitude={flight.DepartureAirport.GetLongitude()}," +
                                   $"destination_airport_name='{flight.DestinationAirport.AirportName}',destination_airport_latitude={flight.DepartureAirport.GetLatitude()}, destination_airport_longitude={flight.DestinationAirport.GetLongitude()};";
             command.ExecuteNonQuery();
         }
 }
Exemple #28
0
 public FlightController(IFlight flight, IDetail detail, IAirPlane airPlane, IAirPort airPort, IFlightStatus flightStatus, IGate gate, IWeather weather, ITypeDetail typeDetail, ICustomer customer, ICustomerFlight customerFlight, IAirline airline, ICity city, IAddress address)
 {
     _flight         = flight;
     _detail         = detail;
     _airPlane       = airPlane;
     _airport        = airPort;
     _flightStatus   = flightStatus;
     _gate           = gate;
     _Weatger        = weather;
     _TypeDetail     = typeDetail;
     _customer       = customer;
     _customerFlight = customerFlight;
     _airline        = airline;
     _city           = city;
     _address        = address;
 }
        public void Should_return_status_OK_when_item_with_id_exists()
        {
            // Given
            Browser browser = CreateBrowser();
            IFlight item    = CreateItem(browser);

            // When
            BrowserResponse result = browser.Get(BasePath + item.Id,
                                                 with =>
            {
                with.HttpRequest();
            });

            // Then
            Assert.AreEqual(HttpStatusCode.OK,
                            result.StatusCode);
        }
 public static void StoreInput()
 {
     UserInput();
     currentFlight = GetPlane(PlaceStates, PlaceTypes, AircraftType, Destination, Origin, SeatAmount, DepartureTime, ArrivalTime, Cost, FlightBarcode);
     hash.Value    = currentFlight.GetValue(currentFlight.FlightBarcode);
     store.AddingStorage(
         hash.AddingHash(hash.HashKey(hash.Value)),
         currentFlight.PlaceStates,
         currentFlight.PlaceTypes,
         currentFlight.AircraftType,
         currentFlight.Destination,
         currentFlight.Origin,
         currentFlight.SeatAmount,
         currentFlight.DepartureTime,
         currentFlight.ArrivalTime,
         currentFlight.Cost,
         currentFlight.FlightBarcode
         );
 }
        public void Should_return_JSON_string_when_item_is_deleted()
        {
            // Given
            Browser browser  = CreateBrowser();
            IFlight expected = CreateItem(browser);

            // When
            BrowserResponse result = browser.Delete(BasePath + expected.Id,
                                                    with =>
            {
                with.HttpRequest();
            });

            var actual = result.Body.DeserializeJson <Flight>();

            // Then
            AssertFlight(expected,
                         actual);
        }
Exemple #32
0
 public int CompareTo(IFlight other)
 {
     if (Type != null) if (other != null) return Type.CompareTo(other.Type);
     throw  new ArgumentException();
 }