Example #1
0
 public Schedule(Train train, Station station)
 {
     m_Train       = train;
     m_Station     = station;
     m_Days        = new List <eDaysOfService>();
     m_Direction   = eScheduleDirection.Unknown;
     m_Handling    = eHandling.Unknown;
     IsUnscheduled = true;
 }
Example #2
0
        public Schedule(Train train, LeibitTime arrival, LeibitTime departure, Track track, List <eDaysOfService> days, eScheduleDirection direction, eHandling handling, string remark)
        {
            m_Train     = train;
            m_Arrival   = arrival;
            m_Departure = departure;
            m_Track     = track;
            m_Days      = days;
            m_Direction = direction;
            m_Handling  = handling;
            m_Remark    = remark;

            if (m_Train != null)
            {
                m_Train.AddSchedule(this);
            }

            if (m_Track != null)
            {
                m_Track.Station.Schedules.Add(this);
                m_Station = m_Track.Station;
            }
        }
Example #3
0
        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);
                }
            }
        }
Example #4
0
 public Schedule(Train train, LeibitTime arrival, LeibitTime departure, Track track, List <eDaysOfService> days, eScheduleDirection direction, eHandling handling, string remark, string localOrders)
     : this(train, arrival, departure, track, days, direction, handling, remark)
 {
     m_LocalOrders = localOrders;
 }
Example #5
0
        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;
                }
            }
        }