public InterfaceLogicConnector(string path) { string[] strs = File.ReadAllLines(path); airport = new Airport(strs); FlightInfoLine endInfo = new FlightInfoLine(strs[strs.Length - 1]); endTime = endInfo.Date; UpdateInfo(); }
public void DefaultValues() { string str = "2019 7 21 7 14 Departure Moscow Boeing 737"; DateTime date = new DateTime(2019, 7, 21, 7, 14, 0); FlightInfoLine infoLine = new FlightInfoLine(str); Assert.IsTrue( infoLine.Date == date && infoLine.City == "Moscow" && infoLine.Direction == Direction.Away && infoLine.Model == "Boeing 737" ); }
private bool IsScheduleCorrect() // Проверяет, нет ли в расписании ситуации, когда следующая строка имеет более раннюю дату. { if (schedule.Length == 1) { return(true); } for (int i = 1; i < schedule.Length; i++) { var firstLine = new FlightInfoLine(schedule[i - 1]); var secondLine = new FlightInfoLine(schedule[i]); if (firstLine.Date > secondLine.Date) { return(false); } } return(true); }
private void UpdateInfo() { while (schedulePointer < schedule.Length) { var info = new FlightInfoLine(schedule[schedulePointer]); if (info.Date > currentTime) { break; } var airplane = new Airplane(info.Model, info.Date, info.City, info.Direction); airplanes.Enqueue(airplane); UpdateSumPassengers(airplane.Direction, airplane.Passengers); UpdateRecentFlight(airplane); schedulePointer++; } while (airplanes.Count > 0 && airplanes.Peek().Time.AddDays(1) < currentTime) // AddDays(1) because "airplanes" embraces recent 24 hours. { airplanes.Dequeue(); } UpdateTempPassengers(); }
public Airport(string[] schedule) { ArrInRecentFlight = 0; ArrInRecentDay = 0; ArrInDayByHours = new int[24]; ArrSummary = 0; DepInRecentFlight = 0; DepInRecentDay = 0; DepInDayByHours = new int[24]; DepSummary = 0; this.schedule = schedule; schedulePointer = 0; FlightInfoLine info = new FlightInfoLine(schedule[schedulePointer]); airplanes = new Queue <Airplane>(); currentTime = info.Date; if (!IsScheduleCorrect()) { throw new ArgumentException("В расписании есть ситуация, когда в одной из строк стоит более ранняя дата, чем в предыдущей."); } UpdateInfo(); }