private void SetStationFree(Airplane airplane, Flight flight, Station currentStation) { airplaneBL.SetArplaneFree(currentStation.AirplaneId); flight.IsOver = true; historyBL.EndRecord(currentStation, flight); currentStation.AirplaneId = 0; currentStation.IsAvailable = true; KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (!keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Remove(keyPair); } StationIsAvailable?.Invoke(); connection.InvokeAsync("StationDataChanged", Stations); SaveChanges(); }
private void PutAirplaneInNextStation(Airplane airplane, Flight flight, Station currentStation, Station nextStation) { historyBL.EndRecord(currentStation, flight); currentStation.IsAvailable = true; currentStation.AirplaneId = 0; nextStation.AirplaneId = airplane.Id; nextStation.IsAvailable = false; historyBL.StartRecord(nextStation, flight); airplaneBL.WaitInStation(airplane, flight); KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (!keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Remove(keyPair); } StationIsAvailable?.Invoke(); }
public bool MoveAirplaneToNextStation(Airplane airplane, Flight flight) { bool res = false; Station currentStation = Stations.FirstOrDefault(s => s.AirplaneId == airplane.Id); switch (flight.FlightType) { case FlightType.Arrival: int idx = arrivalCourseList.IndexOf(currentStation.Id); if (idx == arrivalCourseList.Count - 1 || idx == arrivalCourseList.Count - 2) //Take off { currentStation.IsAvailable = true; currentStation.AirplaneId = 0; airplane.IsAvailable = true; KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (!keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Remove(keyPair); } StationIsAvailable?.Invoke(); } else { Station nextArrivalStation = Stations.FirstOrDefault(s => s.Id == arrivalCourseList[idx + 1]); if (nextArrivalStation.IsAvailable) { currentStation.IsAvailable = true; currentStation.AirplaneId = 0; nextArrivalStation.AirplaneId = airplane.Id; nextArrivalStation.IsAvailable = false; KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (!keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Remove(keyPair); } StationIsAvailable?.Invoke(); res = true; } else { KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Add(new KeyValuePair <Airplane, Flight>(airplane, flight)); } res = false; } } break; case FlightType.Departure: idx = departureCourseList.IndexOf(currentStation.Id); if (idx == departureCourseList.Count - 1) { currentStation.IsAvailable = true; currentStation.AirplaneId = 0; airplane.IsAvailable = true; KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (!keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Remove(keyPair); } StationIsAvailable?.Invoke(); } else { Station nextDepartureStation = Stations.FirstOrDefault(s => s.Id == arrivalCourseList[idx + 1]); if (nextDepartureStation.IsAvailable) { currentStation.IsAvailable = true; currentStation.AirplaneId = 0; nextDepartureStation.AirplaneId = airplane.Id; nextDepartureStation.IsAvailable = false; KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (!keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Remove(keyPair); } StationIsAvailable?.Invoke(); res = true; } else { KeyValuePair <Airplane, Flight> keyPair = waitingToMoveAirplanes.FirstOrDefault(kp => (kp.Key == airplane && kp.Value == flight)); if (keyPair.Equals(default(KeyValuePair <Airplane, Flight>))) { waitingToMoveAirplanes.Add(new KeyValuePair <Airplane, Flight>(airplane, flight)); } res = false; } } break; default: break; } return(res); }