Esempio n. 1
0
        public void CalculationBLLTest_GetFollowUpService_WrongDay()
        {
            var estw = new ESTW("ID", "Name", string.Empty, null);

            estw.Time = new LeibitTime(eDaysOfService.Saturday, 14, 45);

            var train = new Train(1);

            new Schedule(train, new LeibitTime(14, 56), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);

            var relation = new TrainRelation(2);

            relation.Days.Add(eDaysOfService.Monday);
            relation.Days.Add(eDaysOfService.Tuesday);
            relation.Days.Add(eDaysOfService.Wednesday);
            relation.Days.Add(eDaysOfService.Thursday);
            relation.Days.Add(eDaysOfService.Friday);
            train.FollowUpServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetFollowUpService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.IsNull(result.Result);
        }
Esempio n. 2
0
        internal static TrainInformation TestTrainDelayDeparture(ESTW estw)
        {
            var Train = estw.Area.Trains[2007];

            var Result = new TrainInformation(Train);

            Result.Direction = eBlockDirection.Right;
            Result.Delay     = 4;
            Result.Block     = estw.Blocks["32G12"].First();

            var ProbeSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TPRB"));

            ProbeSchedule.LiveArrival       = new LeibitTime(eDaysOfService.Thursday, 13, 0);
            ProbeSchedule.LiveDeparture     = new LeibitTime(eDaysOfService.Thursday, 13, 2);
            ProbeSchedule.LiveTrack         = ProbeSchedule.Schedule.Track;
            ProbeSchedule.ExpectedArrival   = ProbeSchedule.LiveArrival;
            ProbeSchedule.ExpectedDeparture = ProbeSchedule.LiveDeparture;
            Result.AddSchedule(ProbeSchedule);

            var TestdorfSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TTST"));

            TestdorfSchedule.LiveArrival       = new LeibitTime(eDaysOfService.Thursday, 13, 07);
            TestdorfSchedule.LiveDeparture     = new LeibitTime(eDaysOfService.Thursday, 13, 12);
            TestdorfSchedule.LiveTrack         = TestdorfSchedule.Schedule.Track;
            TestdorfSchedule.ExpectedArrival   = TestdorfSchedule.LiveArrival;
            TestdorfSchedule.ExpectedDeparture = TestdorfSchedule.LiveDeparture;
            TestdorfSchedule.AddDelay(3, eDelayType.Departure);
            Result.AddSchedule(TestdorfSchedule);

            return(Result);
        }
Esempio n. 3
0
        public void InitializationBLLTest_LoadESTW()
        {
            using (var scope = new ESTWTestDataScope(BLL))
            {
                var Area = new Area("myTestArea", "Testland");
                var Estw = new ESTW("TTST", "Testdorf", "leibit_TEST.dat", Area);
                new ESTW("TREH", "Rechtsheim", "leibit_RECHTSHEI.dat", Area);
                var Expected = ExpectedValuesOfInitializationBLLTest.LoadTestdorfESTW();

                //int progress = 0;
                //bool finished = false;
                //OperationResult<bool> BllResult = null;

                //var worker = new BackgroundWorker();
                //worker.WorkerReportsProgress = true;
                //worker.ProgressChanged += (sender, e) => progress = e.ProgressPercentage;
                //worker.DoWork += (sender, e) => BllResult = BLL.LoadESTW(Estw, sender as BackgroundWorker);
                //worker.RunWorkerCompleted += (sender, e) => finished = true;
                //worker.RunWorkerAsync();

                //while (!finished) ;

                OperationResult <bool> BllResult = BLL.LoadESTW(Estw);

                DefaultChecks.IsOperationSucceeded(BllResult);
                Assert.IsTrue(BllResult.Result, "Result is false.");
                AreaComparer.Instance.Compare(Expected, Area);
                //Assert.AreEqual(100, progress);
            }
        }
Esempio n. 4
0
        public OperationResult <int?> GetFollowUpService(Train train, ESTW estw)
        {
            try
            {
                // Performance optimization. This covers most of the cases so that no complex calculation is needed.
                if (train.FollowUpServices.Count == 1 && train.FollowUpServices[0].Days.Count == 7)
                {
                    return(OperationResult <int?> .Ok(train.FollowUpServices[0].TrainNumber));
                }

                var destinationSchedule = train.Schedules.FirstOrDefault(s => s.Handling == eHandling.Destination);

                if (destinationSchedule != null && train.FollowUpServices.Any())
                {
                    var dayOfService = __GetDayOfService(destinationSchedule, estw.Time);
                    var relation     = train.FollowUpServices.FirstOrDefault(r => r.Days.Contains(dayOfService));

                    if (relation != null)
                    {
                        return(OperationResult <int?> .Ok(relation.TrainNumber));
                    }
                }

                return(OperationResult <int?> .Ok(null));
            }
            catch (Exception ex)
            {
                return(OperationResult <int?> .Fail(ex.ToString()));
            }
        }
Esempio n. 5
0
        private Station __GetStation(XmlNode node, ESTW estw)
        {
            if (node == null)
            {
                return(null);
            }

            var StationName    = node.Attributes["name"];
            var StationShort   = node.Attributes["short"];
            var StationNumber  = node.Attributes["refNr"];
            var ScheduleFile   = node.Attributes["scheduleFile"];
            var LocalOrderFile = node.Attributes["localOrderFile"];

            if (StationName == null || StationShort == null || StationNumber == null)
            {
                return(null);
            }

            short number;

            if (!Int16.TryParse(StationNumber.InnerText, out number))
            {
                return(null);
            }

            string Schedule    = ScheduleFile == null ? null : ScheduleFile.InnerText;
            string LocalOrders = LocalOrderFile == null ? null : LocalOrderFile.InnerText;

            return(new Station(StationName.InnerText, StationShort.InnerText, number, Schedule, LocalOrders, estw));
        }
Esempio n. 6
0
        private void __RefreshLiveSchedules(TrainInformation Train, ESTW estw)
        {
            lock (Train.LockSchedules)
            {
                var OldSchedules = Train.Schedules.ToList();
                Train.TruncateSchedules();

                var SchedulesResult = CalculationBLL.GetSchedulesByTime(Train.Train.Schedules, estw.Time);
                ValidateResult(SchedulesResult);

                foreach (var Schedule in SchedulesResult.Result)
                {
                    var LiveSchedule = OldSchedules.FirstOrDefault(s => s.Schedule.Station.ESTW.Id == Schedule.Station.ESTW.Id &&
                                                                   s.Schedule.Station.ShortSymbol == Schedule.Station.ShortSymbol &&
                                                                   s.Schedule.Time == Schedule.Time);

                    if (LiveSchedule == null)
                    {
                        LiveSchedule = new LiveSchedule(Train, Schedule);
                    }
                    else
                    {
                        OldSchedules.Remove(LiveSchedule);
                    }

                    Train.AddSchedule(LiveSchedule);
                }

                foreach (var OldSchedule in OldSchedules)
                {
                    Train.AddSchedule(OldSchedule);
                }
            }
        }
Esempio n. 7
0
        internal static TrainInformation TestLoadSharedDelay_NonExisting(ESTW estw)
        {
            var Train = estw.Area.Trains[2007];

            var Result = new TrainInformation(Train);

            Result.Direction = eBlockDirection.Right;
            Result.Delay     = 6;
            Result.Block     = estw.Blocks["32G12"].First();

            var ProbeSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TPRB"));

            ProbeSchedule.LiveArrival       = new LeibitTime(eDaysOfService.Thursday, 13, 7);
            ProbeSchedule.LiveDeparture     = new LeibitTime(eDaysOfService.Thursday, 13, 8);
            ProbeSchedule.LiveTrack         = ProbeSchedule.Schedule.Track;
            ProbeSchedule.ExpectedArrival   = ProbeSchedule.LiveArrival;
            ProbeSchedule.ExpectedDeparture = ProbeSchedule.LiveDeparture;
            Result.AddSchedule(ProbeSchedule);

            var TestdorfSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TTST"));

            TestdorfSchedule.LiveArrival       = new LeibitTime(eDaysOfService.Thursday, 13, 12);
            TestdorfSchedule.LiveDeparture     = new LeibitTime(eDaysOfService.Thursday, 13, 14);
            TestdorfSchedule.LiveTrack         = TestdorfSchedule.Schedule.Track;
            TestdorfSchedule.ExpectedArrival   = TestdorfSchedule.LiveArrival;
            TestdorfSchedule.ExpectedDeparture = TestdorfSchedule.LiveDeparture;
            Result.AddSchedule(TestdorfSchedule);

            var Delay = TestdorfSchedule.AddDelay(4, eDelayType.Departure);

            Delay.Reason   = "Keine Ahnung";
            Delay.CausedBy = 4711;

            return(Result);
        }
Esempio n. 8
0
        internal static TrainInformation TestMisdirectedTrain(ESTW estw)
        {
            var Train = estw.Area.Trains[4711];

            var Result = new TrainInformation(Train);

            Result.Direction = eBlockDirection.Right;
            Result.Delay     = 0;
            Result.Block     = estw.Blocks["32G11"].First();

            var ProbeSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TPRB"));

            ProbeSchedule.LiveArrival       = new LeibitTime(eDaysOfService.Thursday, 14, 4);
            ProbeSchedule.LiveDeparture     = new LeibitTime(eDaysOfService.Thursday, 14, 5);
            ProbeSchedule.LiveTrack         = ProbeSchedule.Schedule.Track;
            ProbeSchedule.ExpectedArrival   = ProbeSchedule.LiveArrival;
            ProbeSchedule.ExpectedDeparture = ProbeSchedule.LiveDeparture;
            Result.AddSchedule(ProbeSchedule);

            var TestdorfSchedule = new LiveSchedule(Result, new Schedule(Train, estw.Stations.FirstOrDefault(s => s.ShortSymbol == "TTST")));

            TestdorfSchedule.Schedule.Arrival   = new LeibitTime(14, 11);
            TestdorfSchedule.LiveArrival        = new LeibitTime(eDaysOfService.Thursday, 14, 11);
            TestdorfSchedule.Schedule.Departure = new LeibitTime(14, 12);
            TestdorfSchedule.LiveDeparture      = new LeibitTime(eDaysOfService.Thursday, 14, 12);
            TestdorfSchedule.LiveTrack          = TestdorfSchedule.Schedule.Station.Tracks.FirstOrDefault(t => t.Name == "1A");
            TestdorfSchedule.ExpectedArrival    = TestdorfSchedule.LiveArrival;
            TestdorfSchedule.ExpectedDeparture  = TestdorfSchedule.LiveDeparture;
            Result.AddSchedule(TestdorfSchedule);

            Train.AddSchedule(TestdorfSchedule.Schedule);
            return(Result);
        }
        public ESTWSelectionESTWViewModel(ESTW Estw)
            : base()
        {
            if (Estw == null)
            {
                throw new ArgumentNullException("Estw must not be null");
            }

            m_Estw = Estw;
            __InitializeStations();
        }
Esempio n. 10
0
        public PathViewModel(ESTW estw, string path)
        {
            if (estw == null)
            {
                throw new ArgumentNullException("estw must not be null");
            }

            m_Estw = estw;
            Path   = path;

            m_BrowseCommand = new CommandHandler(__Browse, true);
        }
Esempio n. 11
0
 private Stream __GetEstwXmlStream(ESTW estw)
 {
     if (CustomEstwXmlStream == null)
     {
         var assembly = typeof(Resources).Assembly;
         return(assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Data.{estw.Area.Id}.{estw.Id}.xml"));
     }
     else
     {
         return(CustomEstwXmlStream(estw));
     }
 }
Esempio n. 12
0
        private TrainInformation __GetOrCreateLiveTrainInformation(int trainNumber, ESTW estw)
        {
            if (estw.Area.LiveTrains.ContainsKey(trainNumber))
            {
                return(estw.Area.LiveTrains[trainNumber]);
            }

            var train = __CreateLiveTrainInformation(trainNumber, estw);

            train.CreatedOn = estw.Time;
            return(estw.Area.LiveTrains.GetOrAdd(trainNumber, train));
        }
Esempio n. 13
0
        private Station __GetStation(XmlNode node, ESTW estw)
        {
            if (node == null)
            {
                return(null);
            }

            var StationName    = node.Attributes["name"];
            var StationShort   = node.Attributes["short"];
            var StationNumber  = node.Attributes["refNr"];
            var ScheduleFile   = node.Attributes["scheduleFile"];
            var LocalOrderFile = node.Attributes["localOrderFile"];
            var DisplayName    = node.Attributes["displayName"];

            if (StationName == null || StationShort == null || StationNumber == null)
            {
                return(null);
            }

            short number;

            if (!Int16.TryParse(StationNumber.InnerText, out number))
            {
                return(null);
            }

            string Schedule    = ScheduleFile == null ? null : ScheduleFile.InnerText;
            string LocalOrders = LocalOrderFile == null ? null : LocalOrderFile.InnerText;

            var station = new Station(StationName.InnerText, StationShort.InnerText, number, Schedule, LocalOrders, estw);

            if (DisplayName != null)
            {
                station.DisplayName = DisplayName.InnerText;
            }

            foreach (XmlNode scheduleFileNode in node.SelectNodes("scheduleFile"))
            {
                var fileName = scheduleFileNode.Attributes["fileName"];

                if (fileName == null || fileName.InnerText.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var scheduleFile = new ScheduleFile(fileName.InnerText);
                scheduleFile.Tracks = scheduleFileNode.SelectNodes("track").Cast <XmlNode>().Select(x => x.InnerText).ToList();
                station.ScheduleFiles.Add(scheduleFile);
            }

            return(station);
        }
Esempio n. 14
0
        public void InitializationBLLTest_LoadMultipleScheduleFiles()
        {
            using (var scope = new ESTWTestDataScope(BLL))
            {
                var area     = new Area("scheduleArea", "Schedules");
                var estw     = new ESTW("ST", "ScheduleTest", "leibit_ST.dat", area);
                var Expected = ExpectedValuesOfInitializationBLLTest.LoadScheduleTestESTW();

                OperationResult <bool> BllResult = BLL.LoadESTW(estw);
                DefaultChecks.IsOperationSucceeded(BllResult);
                Assert.IsTrue(BllResult.Result, "Result is false.");
                AreaComparer.Instance.Compare(Expected, area);
            }
        }
Esempio n. 15
0
        public ESTWOnlineScope(ESTW estw, string estwOnlineDirectory, string dataFilePath)
        {
            m_Estw = estw;

            m_OldDataFilePath = Field.GetValue(m_Estw) as string;
            Field.SetValue(m_Estw, dataFilePath);

            var SettingsResult = m_SettingsBll.GetSettings();

            if (SettingsResult.Succeeded)
            {
                m_OldEstwOnlinePath = SettingsResult.Result.EstwOnlinePath;
                SettingsResult.Result.EstwOnlinePath = Path.Combine(Environment.CurrentDirectory, estwOnlineDirectory);
            }
        }
        internal static List <Area> GetAreaInformation()
        {
            var Result = new List <Area>();

            var Testland   = new Area("myTestArea", "Testland");
            var Testdorf   = new ESTW("TTST", "Testdorf", "leibit_TEST.dat", Testland);
            var Rechtsheim = new ESTW("TREH", "Rechtsheim", "leibit_RECHTSHEI.dat", Testland);

            Result.Add(Testland);

            var Paradies        = new Area("another", "Paradies");
            var Paradiesbahnhof = new ESTW("PPP", "Paradiesbahnhof", "leibit_PARADIES.dat", Paradies);

            Result.Add(Paradies);

            return(Result);
        }
Esempio n. 17
0
        public OperationResult <int?> GetPreviousService(Train train, ESTW estw)
        {
            try
            {
                // Performance optimization. This covers most of the cases so that no complex calculation is needed.
                if (train.PreviousServices.Count == 1 && train.PreviousServices[0].Days.Count == 7)
                {
                    return(OperationResult <int?> .Ok(train.PreviousServices[0].TrainNumber));
                }

                if (train.PreviousServices.Any())
                {
                    foreach (var relation in train.PreviousServices)
                    {
                        Schedule previousTrainSchedule = null;

                        if (estw.Area.LiveTrains.ContainsKey(relation.TrainNumber))
                        {
                            previousTrainSchedule = estw.Area.LiveTrains[relation.TrainNumber].Schedules.FirstOrDefault(s => s.Schedule.Handling == eHandling.Destination)?.Schedule;
                        }
                        else
                        {
                            var previousTrainSchedules = __GetSchedulesByTime(estw.Area.Trains[relation.TrainNumber].Schedules, estw.Time);
                            previousTrainSchedule = previousTrainSchedules.FirstOrDefault(s => s.Handling == eHandling.Destination);
                        }

                        if (previousTrainSchedule != null)
                        {
                            var dayOfService = __GetDayOfService(previousTrainSchedule, estw.Time);

                            if (relation.Days.Contains(dayOfService))
                            {
                                return(OperationResult <int?> .Ok(relation.TrainNumber));
                            }
                        }
                    }
                }

                return(OperationResult <int?> .Ok(null));
            }
            catch (Exception ex)
            {
                return(OperationResult <int?> .Fail(ex.ToString()));
            }
        }
Esempio n. 18
0
        internal static Area LoadScheduleTestESTW()
        {
            var area = new Area("scheduleArea", "Schedules");
            var estw = new ESTW("ST", "ScheduleTest", "leibit_ST.dat", area);

            var station1 = new Station("Station1", "S1", 1, null, "bf1_____.abf", estw);
            var track1   = new Track("1", true, true, station1, null);
            var track2   = new Track("2", true, true, station1, null);
            var track3   = new Track("3", true, true, station1, null);

            var train111 = new Train(111, "RE", "A-Dorf", "B-Heim");

            area.Trains.TryAdd(111, train111);
            new Schedule(train111, null, new LeibitTime(0, 10), track1, _ALL_DAYS, eScheduleDirection.RightToLeft, eHandling.Transit, String.Empty, "* RE  111 :  tgl\r\n\t-> Durchfahrt Gl. 1");

            var train222 = new Train(222, "RE", "B-Heim", "A-Dorf");

            area.Trains.TryAdd(222, train222);
            new Schedule(train222, null, new LeibitTime(0, 20), track2, _ALL_DAYS, eScheduleDirection.LeftToRight, eHandling.Transit, String.Empty, null);

            var train333 = new Train(333, "RE", "B-Heim", "A-Dorf");

            area.Trains.TryAdd(333, train333);
            new Schedule(train333, null, new LeibitTime(0, 30), track2, _ALL_DAYS, eScheduleDirection.LeftToRight, eHandling.Transit, String.Empty, "* RE  333 :  tgl\r\n\t-> Durchfahrt Gl. 2");

            var train444 = new Train(444, "RE", "A-Dorf", "B-Heim");

            area.Trains.TryAdd(444, train444);
            new Schedule(train444, null, new LeibitTime(0, 40), track1, _ALL_DAYS, eScheduleDirection.RightToLeft, eHandling.Transit, String.Empty, null);

            var train555 = new Train(555, "RE", "C-Stadt", "D-Hausen");

            area.Trains.TryAdd(555, train555);
            new Schedule(train555, null, new LeibitTime(0, 15), track3, _ALL_DAYS, eScheduleDirection.RightToLeft, eHandling.Transit, String.Empty, null);

            var train888 = new Train(888, "RE", "C-Stadt", "D-Hausen");

            area.Trains.TryAdd(888, train888);
            new Schedule(train888, null, new LeibitTime(0, 45), track3, _ALL_DAYS, eScheduleDirection.RightToLeft, eHandling.Transit, String.Empty, null);

            estw.SchedulesLoaded = true;
            estw.IsLoaded        = true;
            return(area);
        }
Esempio n. 19
0
        private void __LoadTrainCompositions(ESTW estw, string path)
        {
            var compositionFilesPath = Path.Combine(path, Constants.TRAIN_COMPOSITION_FOLDER);

            if (!Directory.Exists(compositionFilesPath))
            {
                return;
            }

            foreach (var file in Directory.EnumerateFiles(compositionFilesPath, "*.zug"))
            {
                var fileInfo     = new FileInfo(file);
                var sTrainNumber = fileInfo.Name.Replace(fileInfo.Extension, string.Empty).Replace("_", string.Empty);

                if (!int.TryParse(sTrainNumber, out int trainNumber))
                {
                    continue;
                }

                if (!estw.Area.Trains.ContainsKey(trainNumber))
                {
                    continue;
                }

                using (var streamReader = new StreamReader(file, Encoding.GetEncoding("iso-8859-1")))
                {
                    var content = streamReader.ReadToEnd();

                    if (content != null)
                    {
                        content = content.Trim();
                    }

                    if (content.IsNotNullOrEmpty())
                    {
                        estw.Area.Trains[trainNumber].Composition = content;
                    }
                }
            }
        }
Esempio n. 20
0
        public void CalculationBLLTest_GetPreviousService_SimpleCase()
        {
            var estw  = new ESTW("ID", "Name", string.Empty, null);
            var train = new Train(1);

            var relation = new TrainRelation(2);

            relation.Days.Add(eDaysOfService.Monday);
            relation.Days.Add(eDaysOfService.Tuesday);
            relation.Days.Add(eDaysOfService.Wednesday);
            relation.Days.Add(eDaysOfService.Thursday);
            relation.Days.Add(eDaysOfService.Friday);
            relation.Days.Add(eDaysOfService.Saturday);
            relation.Days.Add(eDaysOfService.Sunday);
            train.PreviousServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetPreviousService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(2, result.Result);
        }
Esempio n. 21
0
        internal static TrainInformation TestSpecialTrainDelay(ESTW estw)
        {
            var Train = new Train(98765);

            var Result = new TrainInformation(Train);

            Result.Direction = eBlockDirection.Left;
            Result.Delay     = 11;
            Result.Block     = estw.Blocks["31G1"].First();

            var TestdorfSchedule = new LiveSchedule(Result, new Schedule(Train, estw.Stations.FirstOrDefault(s => s.ShortSymbol == "TTST")));

            TestdorfSchedule.Schedule.Arrival   = new LeibitTime(18, 26);
            TestdorfSchedule.LiveArrival        = new LeibitTime(eDaysOfService.Thursday, 18, 29);
            TestdorfSchedule.Schedule.Departure = new LeibitTime(18, 28);
            TestdorfSchedule.LiveDeparture      = new LeibitTime(eDaysOfService.Thursday, 18, 35);
            TestdorfSchedule.LiveTrack          = TestdorfSchedule.Schedule.Station.Tracks.FirstOrDefault(t => t.Name == "3");
            TestdorfSchedule.ExpectedArrival    = TestdorfSchedule.LiveArrival;
            TestdorfSchedule.ExpectedDeparture  = TestdorfSchedule.LiveDeparture;
            TestdorfSchedule.AddDelay(4, eDelayType.Departure);
            Result.AddSchedule(TestdorfSchedule);

            var ProbeSchedule = new LiveSchedule(Result, new Schedule(Train, estw.Stations.FirstOrDefault(s => s.ShortSymbol == "TPRB")));

            ProbeSchedule.Schedule.Arrival   = new LeibitTime(18, 33);
            ProbeSchedule.LiveArrival        = new LeibitTime(eDaysOfService.Thursday, 18, 43);
            ProbeSchedule.Schedule.Departure = new LeibitTime(18, 33);
            ProbeSchedule.LiveDeparture      = new LeibitTime(eDaysOfService.Thursday, 18, 44);
            ProbeSchedule.LiveTrack          = ProbeSchedule.Schedule.Station.Tracks.FirstOrDefault(t => t.Name == "1");
            ProbeSchedule.ExpectedArrival    = ProbeSchedule.LiveArrival;
            ProbeSchedule.ExpectedDeparture  = ProbeSchedule.LiveDeparture;
            ProbeSchedule.AddDelay(3, eDelayType.Arrival);
            Result.AddSchedule(ProbeSchedule);

            Train.AddSchedule(TestdorfSchedule.Schedule);
            Train.AddSchedule(ProbeSchedule.Schedule);
            return(Result);
        }
Esempio n. 22
0
        internal static TrainInformation TestExpectedTimesPremature(ESTW estw)
        {
            var Train = estw.Area.Trains[12345];

            var Result = new TrainInformation(Train);

            Result.Direction = eBlockDirection.Left;
            Result.Delay     = -5;
            Result.Block     = estw.Blocks["33BP"].First();

            var TestdorfSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TTST"));

            TestdorfSchedule.ExpectedArrival   = new LeibitTime(13, 01);
            TestdorfSchedule.ExpectedDeparture = new LeibitTime(13, 10);
            Result.AddSchedule(TestdorfSchedule);

            var ProbeSchedule = new LiveSchedule(Result, Train.Schedules.FirstOrDefault(s => s.Station.ShortSymbol == "TPRB"));

            ProbeSchedule.ExpectedArrival = new LeibitTime(13, 15);
            Result.AddSchedule(ProbeSchedule);

            return(Result);
        }
Esempio n. 23
0
        private TrainInformation __CreateLiveTrainInformation(int trainNumber, ESTW estw)
        {
            if (estw.Area.Trains.ContainsKey(trainNumber))
            {
                var Train  = estw.Area.Trains[trainNumber];
                var Result = new TrainInformation(Train);

                var SchedulesResult = CalculationBLL.GetSchedulesByTime(Train.Schedules, estw.Time);
                ValidateResult(SchedulesResult);

                foreach (var Schedule in SchedulesResult.Result)
                {
                    var LiveSchedule = new LiveSchedule(Result, Schedule);
                    Result.AddSchedule(LiveSchedule);
                }

                // Don't validate result here. When this fails, it's not so dramatic...
                var prevResult = CalculationBLL.GetPreviousService(Train, estw);
                if (prevResult.Succeeded)
                {
                    Result.PreviousService = prevResult.Result;
                }

                var followUpResult = CalculationBLL.GetFollowUpService(Train, estw);
                if (followUpResult.Succeeded)
                {
                    Result.FollowUpService = followUpResult.Result;
                }

                return(Result);
            }
            else
            {
                var Train = estw.Area.Trains.GetOrAdd(trainNumber, new Train(trainNumber));
                return(new TrainInformation(Train));
            }
        }
Esempio n. 24
0
        public void CalculationBLLTest_GetFollowUpService_BeforeMidnight()
        {
            var estw = new ESTW("ID", "Name", string.Empty, null);

            estw.Time = new LeibitTime(eDaysOfService.Thursday, 23, 55);

            var train = new Train(0);

            new Schedule(train, new LeibitTime(0, 5), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);

            var relation = new TrainRelation(1);

            relation.Days.Add(eDaysOfService.Monday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(2);
            relation.Days.Add(eDaysOfService.Tuesday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(3);
            relation.Days.Add(eDaysOfService.Wednesday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(4);
            relation.Days.Add(eDaysOfService.Thursday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(5);
            relation.Days.Add(eDaysOfService.Friday);
            train.FollowUpServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetFollowUpService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(5, result.Result);
        }
Esempio n. 25
0
        private TrainInformation __CreateLiveTrainInformation(int trainNumber, ESTW estw)
        {
            if (estw.Area.Trains.ContainsKey(trainNumber))
            {
                var Train  = estw.Area.Trains[trainNumber];
                var Result = new TrainInformation(Train);

                var SchedulesResult = CalculationBLL.GetSchedulesByTime(Train.Schedules, estw.Time);
                ValidateResult(SchedulesResult);

                foreach (var Schedule in SchedulesResult.Result)
                {
                    var LiveSchedule = new LiveSchedule(Result, Schedule);
                    Result.AddSchedule(LiveSchedule);
                }

                return(Result);
            }
            else
            {
                var Train = new Train(trainNumber);
                return(new TrainInformation(Train));
            }
        }
Esempio n. 26
0
        public void CalculationBLLTest_CalculateDelay_Unscheduled()
        {
            var bll  = new CalculationBLL();
            var estw = new ESTW("meep", "bla", string.Empty, null);

            var train     = new Train(4711);
            var liveTrain = new TrainInformation(train);

            var station1 = new Station("Bahnhof A", "A", 1, string.Empty, string.Empty, estw);
            var station2 = new Station("Bahnhof B", "B", 2, string.Empty, string.Empty, estw);
            var station3 = new Station("Bahnhof C", "C", 3, string.Empty, string.Empty, estw);
            var track1   = new Track("dummy", true, true, station1, null);
            var track2   = new Track("dummy", true, true, station2, null);
            var track3   = new Track("dummy", true, true, station3, null);

            var schedule1 = new Schedule(train, null, new LeibitTime(8, 20), track1, new List <eDaysOfService> {
                eDaysOfService.Tuesday
            }, eScheduleDirection.LeftToRight, eHandling.Transit, string.Empty, null);
            var schedule2 = new Schedule(train, null, new LeibitTime(8, 30), track2, new List <eDaysOfService> {
                eDaysOfService.Tuesday
            }, eScheduleDirection.LeftToRight, eHandling.Transit, string.Empty, null);

            train.AddSchedule(schedule1);
            train.AddSchedule(schedule2);

            var liveSchedule1 = new LiveSchedule(liveTrain, schedule1);
            var liveSchedule2 = new LiveSchedule(liveTrain, schedule2);

            liveTrain.AddSchedule(liveSchedule1);
            liveTrain.AddSchedule(liveSchedule2);

            liveSchedule1.LiveArrival   = new LeibitTime(8, 21);
            liveSchedule1.LiveDeparture = new LeibitTime(8, 22);

            estw.Time = new LeibitTime(eDaysOfService.Tuesday, 8, 25);
            var result = bll.CalculateDelay(liveTrain, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(2, result.Result);

            liveTrain.Delay = result.Result.Value;
            estw.Time       = new LeibitTime(eDaysOfService.Tuesday, 8, 39);

            var liveSchedule3 = new LiveSchedule(liveTrain, station3);

            liveTrain.AddSchedule(liveSchedule3);
            train.AddSchedule(liveSchedule3.Schedule);

            liveSchedule3.LiveArrival   = estw.Time;
            liveSchedule3.LiveDeparture = estw.Time;

            Assert.AreEqual(new LeibitTime(eDaysOfService.Tuesday, 8, 37), liveSchedule3.Schedule.Arrival);
            Assert.AreEqual(new LeibitTime(eDaysOfService.Tuesday, 8, 37), liveSchedule3.Schedule.Departure);

            result = bll.CalculateDelay(liveTrain, estw);
            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(2, result.Result);

            estw.Time = new LeibitTime(eDaysOfService.Tuesday, 8, 45);
            liveSchedule2.LiveArrival   = estw.Time;
            liveSchedule2.LiveDeparture = estw.Time;

            result = bll.CalculateDelay(liveTrain, estw);
            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(15, result.Result);
        }
Esempio n. 27
0
        public OperationResult <int?> CalculateDelay(TrainInformation Train, ESTW Estw)
        {
            try
            {
                var Result = new OperationResult <int?>();

                bool HasPreviousSchedule = false;
                int  PreviousDelay       = 0;

                var settingsResult = m_SettingsBll.GetSettings();
                ValidateResult(settingsResult);
                var delayJustificationEnabled = settingsResult.Result.DelayJustificationEnabled;
                var delayJustificationMinutes = settingsResult.Result.DelayJustificationMinutes;

                foreach (var Schedule in Train.Schedules.OrderBy(s => s.LiveArrival))
                {
                    if (Schedule.LiveArrival == null)
                    {
                        continue;
                    }

                    var Arrival      = Schedule.Schedule.Arrival == null ? Schedule.Schedule.Departure : Schedule.Schedule.Arrival;
                    var DelayArrival = (Schedule.LiveArrival - Arrival).TotalMinutes;

                    if (delayJustificationEnabled && HasPreviousSchedule && DelayArrival - PreviousDelay >= delayJustificationMinutes && !Schedule.Delays.Any(d => d.Type == eDelayType.Arrival))
                    {
                        Schedule.AddDelay(DelayArrival - PreviousDelay, eDelayType.Arrival);
                    }

                    PreviousDelay = DelayArrival < 0 ? 0 : DelayArrival;

                    if (Schedule.Schedule.Departure != null)
                    {
                        if (Schedule.LiveDeparture != null)
                        {
                            var DelayDeparture = (Schedule.LiveDeparture - Schedule.Schedule.Departure).TotalMinutes;

                            if (delayJustificationEnabled && DelayDeparture - PreviousDelay >= delayJustificationMinutes && !Schedule.Delays.Any(d => d.Type == eDelayType.Departure))
                            {
                                Schedule.AddDelay(DelayDeparture - PreviousDelay, eDelayType.Departure);
                            }

                            PreviousDelay = DelayDeparture < 0 ? 0 : DelayDeparture;
                            Result.Result = DelayDeparture;
                        }
                        else
                        {
                            var Delay = (Estw.Time - Schedule.Schedule.Departure).TotalMinutes;
                            Result.Result = Delay < DelayArrival ? DelayArrival : Delay;
                        }
                    }
                    else
                    {
                        Result.Result = DelayArrival;
                    }

                    HasPreviousSchedule = true;
                }

                Result.Succeeded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <int?> {
                    Message = ex.Message
                });
            }
        }
Esempio n. 28
0
        public OperationResult <bool> LoadESTW(ESTW Estw)
        {
            try
            {
                var Result = new OperationResult <bool>();
                Estw.Stations.Clear();
                Estw.Blocks.Clear();
                Estw.IsLoaded = false;

                var PathResult = SettingsBLL.GetPath(Estw.Id);
                ValidateResult(PathResult);

                if (PathResult.Result.IsNullOrWhiteSpace())
                {
                    Result.Succeeded = true;
                    return(Result);
                }

                using (var xmlStream = __GetEstwXmlStream(Estw))
                {
                    if (xmlStream == null)
                    {
                        Result.Message   = "ESTW-Projektierung nicht gefunden";
                        Result.Succeeded = false;
                        return(Result);
                    }

                    var xml = new XmlDocument();
                    xml.Load(xmlStream);
                    var EstwNode = xml.DocumentElement;

                    if (EstwNode == null)
                    {
                        Result.Message   = "Ungültiges ESTW";
                        Result.Succeeded = false;
                        return(Result);
                    }

                    var Stations = EstwNode.SelectNodes("station");
                    Result.Result = true;

                    foreach (XmlNode StationNode in Stations)
                    {
                        Station Station = null;

                        try
                        {
                            Station = __GetStation(StationNode, Estw);
                            if (Station == null)
                            {
                                continue;
                            }

                            var Tracks = StationNode.SelectNodes("track");

                            foreach (XmlNode TrackNode in Tracks)
                            {
                                var Track = __GetTrack(TrackNode, Station);
                                if (Track == null)
                                {
                                    continue;
                                }

                                foreach (XmlNode ChildTrackNode in TrackNode.SelectNodes("track"))
                                {
                                    __GetTrack(ChildTrackNode, Station, Track);
                                }
                            }

                            foreach (XmlNode TrackNode in Tracks)
                            {
                                var TrackName = TrackNode.Attributes["name"];
                                if (TrackName == null)
                                {
                                    continue;
                                }

                                var Track = Station.Tracks.FirstOrDefault(t => t.Name == TrackName.InnerText);
                                if (Track == null)
                                {
                                    continue;
                                }

                                __GetAlternatives(TrackNode, Track);

                                foreach (XmlNode ChildTrackNode in TrackNode.SelectNodes("track"))
                                {
                                    var ChildTrackName = ChildTrackNode.Attributes["name"];
                                    if (ChildTrackName == null)
                                    {
                                        continue;
                                    }

                                    var ChildTrack = Station.Tracks.FirstOrDefault(t => t.Name == ChildTrackName.InnerText);
                                    if (ChildTrack == null)
                                    {
                                        continue;
                                    }

                                    __GetAlternatives(ChildTrackNode, ChildTrack);
                                }
                            }

                            __GetSchedule(Station, PathResult.Result);
                            __ResolveDuplicates(Station.Schedules);
                            __GetLocalOrders(Station, PathResult.Result);
                            Result.Succeeded = true;
                        }
                        catch (Exception ex)
                        {
                            if (Station != null)
                            {
                                Estw.Stations.Remove(Station);
                            }

                            Result.Message = ex.Message;
                            Result.Result  = false;
                        }
                    }
                }

                Estw.IsLoaded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <bool> {
                    Message = ex.Message
                });
            }
        }
Esempio n. 29
0
        public void CalculationBLLTest_SortSchedules_NormalCase()
        {
            var estw = new ESTW("meep", "bla", string.Empty, null);

            var station1 = new Station("Bahnhof A", "A", 1, string.Empty, string.Empty, estw);
            var station2 = new Station("Bahnhof B", "B", 2, string.Empty, string.Empty, estw);
            var station3 = new Station("Bahnhof C", "C", 3, string.Empty, string.Empty, estw);

            var track1 = new Track("dummy", true, true, station1, null);
            var track2 = new Track("dummy", true, true, station2, null);
            var track3 = new Track("dummy", true, true, station3, null);

            var train = new Train(4711);

            var schedule1 = new Schedule(train: train,
                                         arrival: null,
                                         departure: new LeibitTime(eDaysOfService.Monday, 16, 1),
                                         track: track1,
                                         days: new List <eDaysOfService> {
                eDaysOfService.Monday
            },
                                         direction: eScheduleDirection.LeftToRight,
                                         handling: eHandling.Transit,
                                         remark: string.Empty);

            var schedule2 = new Schedule(train: train,
                                         arrival: null,
                                         departure: new LeibitTime(eDaysOfService.Monday, 16, 5),
                                         track: track2,
                                         days: new List <eDaysOfService> {
                eDaysOfService.Monday
            },
                                         direction: eScheduleDirection.LeftToRight,
                                         handling: eHandling.Transit,
                                         remark: string.Empty);

            var schedule3 = new Schedule(train: train,
                                         arrival: null,
                                         departure: new LeibitTime(eDaysOfService.Monday, 16, 9),
                                         track: track3,
                                         days: new List <eDaysOfService> {
                eDaysOfService.Monday
            },
                                         direction: eScheduleDirection.LeftToRight,
                                         handling: eHandling.Transit,
                                         remark: string.Empty);

            var liveTrain = new TrainInformation(train);

            var liveSchedule1 = new LiveSchedule(liveTrain, schedule1);
            var liveSchedule2 = new LiveSchedule(liveTrain, schedule2);
            var liveSchedule3 = new LiveSchedule(liveTrain, schedule3);

            liveTrain.AddSchedule(liveSchedule1);
            liveTrain.AddSchedule(liveSchedule2);
            liveTrain.AddSchedule(liveSchedule3);

            liveSchedule1.LiveArrival   = new LeibitTime(eDaysOfService.Monday, 16, 2);
            liveSchedule1.LiveDeparture = new LeibitTime(eDaysOfService.Monday, 16, 3);

            Assert.AreEqual(0, liveTrain.Schedules.IndexOf(liveSchedule1));
            Assert.AreEqual(1, liveTrain.Schedules.IndexOf(liveSchedule2));
            Assert.AreEqual(2, liveTrain.Schedules.IndexOf(liveSchedule3));
        }
Esempio n. 30
0
        public void CalculationBLLTest_GetPreviousService_BeforeMidnight()
        {
            var area = new Area("ID", "Name");
            var estw = new ESTW("ID", "Name", string.Empty, area);

            estw.Time = new LeibitTime(eDaysOfService.Thursday, 23, 45);

            var train = new Train(0);

            var train1 = new Train(1);

            new Schedule(train1, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(1, train1);

            var train2 = new Train(2);

            new Schedule(train2, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(2, train2);

            var train3 = new Train(3);

            new Schedule(train3, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(3, train3);

            var train4 = new Train(4);

            new Schedule(train4, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(4, train4);

            var train5 = new Train(5);

            new Schedule(train5, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(5, train5);

            var relation = new TrainRelation(1);

            relation.Days.Add(eDaysOfService.Monday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(2);
            relation.Days.Add(eDaysOfService.Tuesday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(3);
            relation.Days.Add(eDaysOfService.Wednesday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(4);
            relation.Days.Add(eDaysOfService.Thursday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(5);
            relation.Days.Add(eDaysOfService.Friday);
            train.PreviousServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetPreviousService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(5, result.Result);
        }