Ejemplo n.º 1
0
        /// <summary>
        /// Send the plane to do what he have to do (refill gaz .. )
        /// </summary>
        /// <param name="plane">The plane that does the job</param>
        public void Do(Plane plane)
        {
            //Set the number of the station in the plane and calls his event that he moved to release the previous station
            plane.SetStation(StationNumber);

            TookNewPlane.Invoke(plane, EventArgs.Empty);

            //When this event will be called ( from the SetStation function ) , the plane moved so he will not be on this station anymore and she can continue
            plane.Moved += (sender, e) => {
                if (sender != this.StationNumber)
                {
                    this.plane = null;
                }
            };

            //Wait the plane finish the job
            Task.Delay(plane.waitingTime).Wait();

            PlaneFinished.Invoke(plane, EventArgs.Empty);

            //Until a station is not available and doesnt take it , the plane is still here and the station is not available
            while (!isAvailable)
            {
                Task.Delay(200).Wait();
            }
        }
Ejemplo n.º 2
0
 public async Task StartWorking()
 {
     while (true)
     {
         Station nextStation;
         while (Airplane == null || Airplane.AirplaneStatus == AirplaneStatus.Moving)
         {
             await Task.Delay(200);
         }
         if (((Id == 6 || Id == 7) && Airplane.FlightState == FlightState.Landing) || (Id == 4 && Airplane.FlightState == FlightState.Departuring))
         {
             Console.Write("");
         }
         var nextStations = NextStation.Where(s => s.TypeOfStation == StationType.StationForLandingAndDeparture || (Airplane.FlightState == FlightState.Departuring ? StationType.StationForDeparture : StationType.StationForLanding) == s.TypeOfStation);
         if (nextStations.Count() == 0)
         {
             Airplane.AirplaneStatus = AirplaneStatus.Finished;
             PlaneFinished?.Invoke(Airplane, this);
             Airplane = null;
         }
         else
         {
             while (nextStations.Any(s => s.Airplane == null) == false)
             {
                 await Task.Delay(200);
             }
             nextStation             = nextStations.First(s => s.Airplane == null);
             nextStation.Airplane    = Airplane;
             Airplane.AirplaneStatus = AirplaneStatus.Moving;
             Airplane.Move();
             Trace.WriteLine($"airplane {Airplane.Id} moved from station {Id} to station {nextStation.Id}");
             Airplane = null;
         }
         StationUpdated?.Invoke();
     }
 }