public void LeibitTimeTest_AddMinutes7() { LeibitTime time = new LeibitTime(eDaysOfService.Monday, 1, 7); time = time.AddMinutes(-153); Assert.AreEqual(eDaysOfService.Sunday, time.Day); Assert.AreEqual(22, time.Hour); Assert.AreEqual(34, time.Minute); }
public void LeibitTimeTest_AddMinutes5() { LeibitTime time = new LeibitTime(eDaysOfService.Sunday, 23, 50); time = time.AddMinutes(-27); Assert.AreEqual(eDaysOfService.Sunday, time.Day); Assert.AreEqual(23, time.Hour); Assert.AreEqual(23, time.Minute); }
public void LeibitTimeTest_AddMinutes6() { LeibitTime time = new LeibitTime(eDaysOfService.Friday, 23, 7); time = time.AddMinutes(-63); Assert.AreEqual(eDaysOfService.Friday, time.Day); Assert.AreEqual(22, time.Hour); Assert.AreEqual(4, time.Minute); }
public void LeibitTimeTest_AddMinutes4() { LeibitTime time = new LeibitTime(eDaysOfService.Sunday, 23, 7); time = time.AddMinutes(55); Assert.AreEqual(eDaysOfService.Monday, time.Day); Assert.AreEqual(0, time.Hour); Assert.AreEqual(2, time.Minute); }
public void LeibitTimeTest_AddMinutes3() { LeibitTime time = new LeibitTime(eDaysOfService.Tuesday, 23, 7); time = time.AddMinutes(105); Assert.AreEqual(eDaysOfService.Wednesday, time.Day); Assert.AreEqual(0, time.Hour); Assert.AreEqual(52, time.Minute); }
public void LeibitTimeTest_AddMinutes2() { LeibitTime time = new LeibitTime(eDaysOfService.Tuesday, 13, 7); time = time.AddMinutes(156); Assert.AreEqual(eDaysOfService.Tuesday, time.Day); Assert.AreEqual(15, time.Hour); Assert.AreEqual(43, time.Minute); }
private void __GetSchedule(Station station, string path) { if (station == null || station.ScheduleFile.IsNullOrWhiteSpace()) { return; } string ScheduleFile = Path.Combine(path, Constants.SCHEDULE_FOLDER, station.ScheduleFile); if (!File.Exists(ScheduleFile)) { return; } // Encoding e.g. for German Umlaute using (var reader = new StreamReader(ScheduleFile, Encoding.GetEncoding("iso-8859-1"))) { reader.ReadLine(); var header = reader.ReadLine(); if (!__GetBounds(header, "VON", out int startFrom, out int startLength) || !__GetBounds(header, "VT", out int daysFrom, out int daysLength) || !__GetBounds(header, "BEMERKUNGEN", out int remarkFrom, out int remarkLength) || !__GetBounds(header, "NACH", out int destinationFrom, out _)) { return; } while (!reader.EndOfStream) { string ScheduleLine = reader.ReadLine(); if (ScheduleLine.StartsWith("240000 999999")) { break; } if (ScheduleLine.Length < 91) { continue; } string sHour = ScheduleLine.Substring(0, 2); string sMinute = ScheduleLine.Substring(2, 2); string sStop = ScheduleLine.Substring(4, 2); string sHandling = ScheduleLine.Substring(6, 1); string sTrain = ScheduleLine.Substring(7, 6); string sDirection = ScheduleLine.Substring(13, 1); string Type = ScheduleLine.Substring(14, 3).Trim(); string sTrack = ScheduleLine.Substring(18, 5).Trim(); string Start = ScheduleLine.Substring(startFrom, startLength).Trim(); string sDays = ScheduleLine.Substring(daysFrom, daysLength).Trim().ToLower(); string Remark = ScheduleLine.Substring(remarkFrom, remarkLength).Trim(); string Destination = ScheduleLine.Substring(destinationFrom).Trim(); if (sTrain.Length > 5) { sTrain = sTrain.Substring(sTrain.Length - 5); } int TrainNr; if (!Int32.TryParse(sTrain, out TrainNr)) { continue; } Train Train = station.ESTW.Area.Trains.GetOrAdd(TrainNr, new Train(TrainNr, Type, Start, Destination)); int Hour; if (!Int32.TryParse(sHour, out Hour)) { continue; } int Minute; if (!Int32.TryParse(sMinute, out Minute)) { continue; } int Stop; if (!Int32.TryParse(sStop, out Stop)) { continue; } eScheduleDirection Direction; switch (sDirection) { case "<": Direction = eScheduleDirection.RightToLeft; break; case "L": Direction = eScheduleDirection.LeftToLeft; break; case "R": Direction = eScheduleDirection.RightToRight; break; default: Direction = eScheduleDirection.LeftToRight; break; } eHandling Handling = eHandling.Unknown; if (Stop == 60) { Handling = eHandling.Start; } else if (sHandling == " ") { Handling = eHandling.StopPassengerTrain; } else if (sHandling == "X") { Handling = eHandling.StopFreightTrain; } else if (sHandling == "A" || sHandling == "Ä") { Handling = eHandling.Destination; } else if (sHandling == "L") { Handling = eHandling.StaffChange; } else if (sHandling == "D" || sHandling == "d") { Handling = eHandling.Transit; } else if (sHandling == "(") { Handling = eHandling.Transit; Direction = eScheduleDirection.RightToLeft; } else if (sHandling == ")") { Handling = eHandling.Transit; Direction = eScheduleDirection.LeftToRight; } var Days = LeibitTime.ParseDays(sDays); LeibitTime Departure = new LeibitTime(Hour, Minute); LeibitTime Arrival; if (Handling == eHandling.Transit || Handling == eHandling.Start) { Arrival = null; } else if (Handling == eHandling.StaffChange && Stop == 0) { Arrival = Departure.AddMinutes(Constants.STAFF_CHANGE_STOPTIME * -1); } else if (Handling == eHandling.Destination) { Arrival = Departure; Departure = null; } else { Arrival = Departure.AddMinutes(Stop * -1); } Track Track = station.Tracks.FirstOrDefault(t => t.Name == sTrack); if (Track == null) { Track = new Track(sTrack, true, false, station, null); } new Schedule(Train, Arrival, Departure, Track, Days, Direction, Handling, Remark); } } }
private void __LoadScheduleFromFile(Station station, string scheduleFile, List <string> tracks) { if (!File.Exists(scheduleFile)) { if (Debugger.IsAttached) { throw new OperationFailedException($"Die Datei '{scheduleFile}' existiert nicht."); } else { return; } } // Encoding e.g. for German Umlaute using (var reader = new StreamReader(scheduleFile, Encoding.GetEncoding("iso-8859-1"))) { reader.ReadLine(); var header = reader.ReadLine(); if (header.IsNullOrWhiteSpace()) { throw new OperationFailedException($"Die Datei '{scheduleFile}' hat ein falsches Format."); } if (!__GetBounds(header, "VON", out int startFrom, out int startLength) || !__GetBounds(header, "VT", out int daysFrom, out int daysLength) || !__GetBounds(header, "BEMERKUNGEN", out int remarkFrom, out int remarkLength) || !__GetBounds(header, "NACH", out int destinationFrom, out _)) { return; } while (!reader.EndOfStream) { string ScheduleLine = reader.ReadLine(); if (ScheduleLine.StartsWith("240000 999999")) { break; } if (ScheduleLine.Length < 91) { continue; } string sHour = ScheduleLine.Substring(0, 2); string sMinute = ScheduleLine.Substring(2, 2); string sStop = ScheduleLine.Substring(4, 2); string sHandling = ScheduleLine.Substring(6, 1); string sTrain = ScheduleLine.Substring(7, 6); string sDirection = ScheduleLine.Substring(13, 1); string Type = ScheduleLine.Substring(14, 3).Trim(); string sTrack = ScheduleLine.Substring(18, 5).Trim(); string Start = ScheduleLine.Substring(startFrom, startLength).Trim(); string sDays = ScheduleLine.Substring(daysFrom, daysLength).Trim().ToLower(); string Remark = ScheduleLine.Substring(remarkFrom, remarkLength).Trim(); string Destination = ScheduleLine.Substring(destinationFrom).Trim(); if (sTrain.Length > 5) { sTrain = sTrain.Substring(sTrain.Length - 5); } int TrainNr; if (!Int32.TryParse(sTrain, out TrainNr)) { continue; } if (tracks.Any() && !tracks.Contains(sTrack)) { continue; } var Train = new Train(TrainNr, Type, Start, Destination); __SetTrainLine(Train, station.ESTW.Area); Train = station.ESTW.Area.Trains.GetOrAdd(TrainNr, Train); int Hour; if (!Int32.TryParse(sHour, out Hour)) { continue; } int Minute; if (!Int32.TryParse(sMinute, out Minute)) { continue; } int Stop; if (!Int32.TryParse(sStop, out Stop)) { continue; } eScheduleDirection Direction; switch (sDirection) { case "<": Direction = eScheduleDirection.RightToLeft; break; case "L": Direction = eScheduleDirection.LeftToLeft; break; case "R": Direction = eScheduleDirection.RightToRight; break; default: Direction = eScheduleDirection.LeftToRight; break; } eHandling Handling = eHandling.Unknown; if (Stop == 60) { Handling = eHandling.Start; } else if (sHandling == " ") { Handling = eHandling.StopPassengerTrain; } else if (sHandling == "X") { Handling = eHandling.StopFreightTrain; } else if (sHandling == "A" || sHandling == "Ä") { Handling = eHandling.Destination; } else if (sHandling == "L") { Handling = eHandling.StaffChange; } else if (sHandling == "D" || sHandling == "d") { Handling = eHandling.Transit; } else if (sHandling == "(") { Handling = eHandling.Transit; Direction = eScheduleDirection.RightToLeft; } else if (sHandling == ")") { Handling = eHandling.Transit; Direction = eScheduleDirection.LeftToRight; } var Days = LeibitTime.ParseDays(sDays); LeibitTime Departure = new LeibitTime(Hour, Minute); LeibitTime Arrival; if (Handling == eHandling.Transit || Handling == eHandling.Start) { Arrival = null; } else if (Handling == eHandling.StaffChange && Stop == 0) { Arrival = Departure.AddMinutes(Constants.STAFF_CHANGE_STOPTIME * -1); } else if (Handling == eHandling.Destination) { Arrival = Departure; Departure = null; } else { Arrival = Departure.AddMinutes(Stop * -1); } Track Track = station.Tracks.FirstOrDefault(t => t.Name == sTrack); if (Track == null) { Track = new Track(sTrack, true, false, station, null); } var schedule = new Schedule(Train, Arrival, Departure, Track, Days, Direction, Handling, Remark); schedule.TrainType = Type; schedule.Start = Start; schedule.Destination = Destination; Train.Type = Train.Schedules.Select(s => s.TrainType).FirstOrDefault(t => t.IsPassengerTrain()) ?? Type; Train.Start = Train.Schedules.OrderBy(s => s.Time).First().Start; Train.Destination = Train.Schedules.OrderBy(s => s.Time).Last().Destination; } } }