示例#1
0
        public void PassPassengers(string busId, string flightId, int capacity)
        {
            lock (flightLock)
            {
                var flight = Flights.Find(e => e.FlightId == flightId);
                if (flight == null)
                {
                    return;
                }

                int count      = flight.Passengers.Count;
                int passCount  = (count > capacity) ? capacity : count;
                var passengers = flight.Passengers.GetRange(0, passCount);

                MqClient.Send <PassengersFromStorageResponse>(storageBus,
                                                              new PassengersFromStorageResponse()
                {
                    BusId = busId, PassengersCount = passCount, PassengersIds = passengers
                });
                Console.WriteLine($"Sent to Bus: {busId}, {passCount}");

                flight.Passengers.RemoveRange(0, passCount);

                MqClient.Send <PassengerPassMessage>(storagePas,
                                                     new PassengerPassMessage()
                {
                    ObjectId = busId, Status = PassengerStatus.InBus, PassengersIds = passengers
                });
                Console.WriteLine($"Sent to Passenger: in {busId}");

                TryToRemove(flightId);
            }
        }
示例#2
0
 public void TryToRemove(string id)
 {
     lock (flightLock)
     {
         var flight = Flights.Find(e => e.FlightId == id);
         if (flight.Baggage == 0 && flight.Passengers.Count == 0)
         {
             Flights.Remove(flight);
         }
     }
 }
示例#3
0
        public void UpdateFlightStatus(string id, FlightStatus status)
        {
            lock (Flights)
            {
                switch (status)
                {
                case FlightStatus.New:
                    Flights.Add(new Flight()
                    {
                        FlightId = id, Status = status
                    });
                    Console.WriteLine($"Added new flight {id}");
                    break;

                case FlightStatus.CheckIn:
                    Flights.Find(e => (e.FlightId == id)).Status = status;
                    Console.WriteLine($"Added check-in: {id} - {status}");
                    break;

                case FlightStatus.Boarding:
                    var boarding = Flights.Find(e => (e.FlightId == id));
                    boarding.Status = status;
                    Console.WriteLine($"Added boarding: {id} - {status}");
                    MqClient.Send(
                        regGrServ,
                        new FlightInfo()
                    {
                        FlightId       = id,
                        PassengerCount = boarding.PasCount,
                        BaggageCount   = boarding.BagCount,
                        FoodList       = new List <Tuple <Food, int> >()
                        {
                            Tuple.Create(Food.Standard, boarding.StandardFood),
                            Tuple.Create(Food.Vegan, boarding.VeganFood),
                            Tuple.Create(Food.Child, boarding.ChildFood),
                        }
                    }
                        );
                    Console.WriteLine($"Sent to Ground Service: {id}, {boarding.PasCount}, {boarding.BagCount}, {boarding.StandardFood}, {boarding.VeganFood}, {boarding.ChildFood}");
                    break;

                case FlightStatus.Departed:
                    Flights.Find(e => (e.FlightId == id)).Status = status;
                    Console.WriteLine($"Added departed: {id} - {status}");
                    break;

                default:
                    break;
                }
            }
        }
示例#4
0
 public void AddBaggage(string flightId)
 {
     lock (flightLock)
     {
         var flight = Flights.Find(e => e.FlightId == flightId);
         if (flight != null)
         {
             flight.Baggage++;
             return;
         }
         Flights.Add(new Flight()
         {
             FlightId = flightId, Baggage = 1
         });
     }
 }
示例#5
0
 public void AddPassenger(string flightId, string pasId)
 {
     lock (flightLock)
     {
         var flight = Flights.Find(e => e.FlightId == flightId);
         if (flight != null)
         {
             flight.Passengers.Add(pasId);
             return;
         }
         var newFlight = new Flight()
         {
             FlightId = flightId
         };
         newFlight.Passengers.Add(pasId);
         Flights.Add(newFlight);
     }
 }
        private void InitCoupons()
        {
            Coupon coupon1 = new Coupon();
            Coupon coupon2 = new Coupon();
            Coupon coupon3 = new Coupon();

            coupon1.Id       = 1;
            coupon1.Luggages = Luggages;
            coupon1.Flight   = Flights.Find(f => f.Id == 1);
            coupon2.Id       = 2;
            coupon2.Flight   = Flights.Find(f => f.Id == 2);
            coupon2.Luggages.Add(Luggages.Find(l => l.Weight == 50));
            coupon3.Id = 3;
            Coupons.Add(coupon1);
            Coupons.Add(coupon2);
            Coupons.Add(coupon3);
            Flights.Find(f => f.Id == 1).Coupons.Add(coupon1);
            Flights.Find(f => f.Id == 2).Coupons.Add(coupon2);
        }
示例#7
0
        public void PassBaggage(string carId, string flightId, int capacity)
        {
            lock (flightLock)
            {
                var flight = Flights.Find(e => e.FlightId == flightId);
                if (flight == null)
                {
                    return;
                }

                int count = (flight.Baggage > capacity) ? capacity : flight.Baggage;

                MqClient.Send <BaggageFromStorageResponse>(storageBaggage,
                                                           new BaggageFromStorageResponse()
                {
                    BaggageCarId = carId, BaggageCount = count
                });
                Console.WriteLine($"Sent to Baggage car: {carId}, {count}");

                flight.Baggage -= count;

                TryToRemove(flightId);
            }
        }
示例#8
0
        public void Registrate(string passengerId, string flightId, bool hasBaggage, Food foodType)
        {
            Flight flight;

            lock (Flights)
            {
                flight = Flights.Find(e => e.FlightId == flightId);
            }

            if (flight == null)
            {
                MqClient.Send(
                    regPas,
                    new CheckInResponse()
                {
                    PassengerId = passengerId, Status = CheckInStatus.NoSuchFlight
                }
                    );
                Console.WriteLine($"Sent to Passenger: {passengerId}, {CheckInStatus.NoSuchFlight}");
                return;
            }

            switch (flight.Status)
            {
            case FlightStatus.New:
                MqClient.Send(
                    regPas,
                    new CheckInResponse()
                {
                    PassengerId = passengerId, Status = CheckInStatus.Early
                }
                    );
                Console.WriteLine($"Sent to Passenger: {passengerId}, {CheckInStatus.Early}");
                break;

            case FlightStatus.Boarding:
            case FlightStatus.Delayed:
            case FlightStatus.Departed:
                MqClient.Send(
                    regPas,
                    new CheckInResponse()
                {
                    PassengerId = passengerId, Status = CheckInStatus.Late
                }
                    );
                Console.WriteLine($"Sent to Passenger: {passengerId}, {CheckInStatus.Late}");
                break;

            case FlightStatus.CheckIn:
                lock (PasList)
                {
                    PasList.Add(
                        new CheckInRequest()
                    {
                        PassengerId = passengerId,
                        FlightId    = flightId,
                        HasBaggage  = hasBaggage,
                        FoodType    = foodType
                    }
                        );
                }
                // Отправить запрос кассе на проверку билета
                MqClient.Send(
                    regCash,
                    new CheckTicketRequest()
                {
                    PassengerId = passengerId, FlightId = flightId
                }
                    );
                Console.WriteLine($"Sent to CashBox: {passengerId}, {flightId}");
                break;
            }
        }
示例#9
0
        public void PassToTerminal(string passengerId, string flightId, bool baggage, Food food)
        {
            var rand = new Random().NextDouble();

            if (rand < 0.2) // Вероятность лагания пассажира - 20%
            {
                var errorTime = new Random().Next(MIN_ERR_MS, MAX_ERR_MS);
                DelaySource.CreateToken().Sleep(errorTime);
            }

            lock (Flights)
            {
                var flight = Flights.Find(e => e.FlightId == flightId);
                var status = flight.Status;

                if (status == FlightStatus.Boarding || status == FlightStatus.Departed)
                {
                    MqClient.Send(
                        regPas,
                        new CheckInResponse()
                    {
                        PassengerId = passengerId, Status = CheckInStatus.LateForTerminal
                    }
                        );
                    Console.WriteLine($"Sent to Passenger: {passengerId}, {CheckInStatus.LateForTerminal}");
                    return;
                }

                // Отправить пассажира в накопитель
                MqClient.Send(regStorage,
                              new PassengerStoragePass()
                {
                    PassengerId = passengerId, FlightId = flightId
                });
                flight.PasCount++;
                MqClient.Send(
                    regPas,
                    new CheckInResponse()
                {
                    PassengerId = passengerId, Status = CheckInStatus.Terminal
                }
                    );

                if (baggage)
                {
                    // Отправить багаж в накопитель - Накопитель(flightId)
                    MqClient.Send(regStorageBaggage,
                                  new BaggageStoragePass()
                    {
                        FlightId = flightId
                    });
                    flight.BagCount++;
                }

                // Добавить еду для рейса
                switch (food)
                {
                case Food.Standard:
                    flight.StandardFood++;
                    break;

                case Food.Vegan:
                    flight.VeganFood++;
                    break;

                case Food.Child:
                    flight.ChildFood++;
                    break;

                default:
                    break;
                }
            }
        }