Esempio n. 1
0
        private string __GetDataFilesPath()
        {
            var SettingsResult = SettingsBLL.GetSettings();

            ValidateResult(SettingsResult);

            if (SettingsResult.Result.EstwOnlinePath == null)
            {
                return(String.Empty);
            }

            var IniPath = Path.Combine(SettingsResult.Result.EstwOnlinePath, Constants.ESTWONLINE_SETTINGS_FILE);

            if (!File.Exists(IniPath))
            {
                throw new OperationFailedException("Ini-Datei von ESTWonline nicht gefunden!");
            }

            using (var reader = new StreamReader(IniPath))
            {
                while (!reader.EndOfStream)
                {
                    var Line = reader.ReadLine();

                    if (Line.StartsWith(String.Format("{0}=", Constants.ESTWONLINE_DIRECTORY_KEY), StringComparison.InvariantCultureIgnoreCase))
                    {
                        var Parts = Line.Split('=');
                        return(Path.Combine(SettingsResult.Result.EstwOnlinePath, Parts[1].Trim()));
                    }
                }
            }

            throw new OperationFailedException(String.Format("Ungültige Ini-Datei '{0}'!", IniPath));
        }
Esempio n. 2
0
        public OperationResult <bool> JustifyDelay(DelayInfo delay, string reason, int?causedBy)
        {
            try
            {
                if (reason.IsNullOrWhiteSpace())
                {
                    return new OperationResult <bool> {
                               Message = "Bitte Grund angeben!"
                    }
                }
                ;

                var SettingsResult = SettingsBLL.GetSettings();
                ValidateResult(SettingsResult);
                var Settings = SettingsResult.Result;

                if (Settings.CheckPlausibility)
                {
                    __CheckDelayJustificationPlausibility(delay, causedBy);
                }

                delay.Reason   = reason;
                delay.CausedBy = causedBy;

                if (delay.Type == eDelayType.Arrival && delay.Schedule.Schedule.TwinScheduleArrival != null)
                {
                    __SynchronizeDelayToTwinSchedule(delay, delay.Schedule.Schedule.TwinScheduleArrival);
                }

                if (delay.Type == eDelayType.Departure && delay.Schedule.Schedule.TwinScheduleDeparture != null)
                {
                    __SynchronizeDelayToTwinSchedule(delay, delay.Schedule.Schedule.TwinScheduleDeparture);
                }

                var Result = new OperationResult <bool>();
                Result.Result    = true;
                Result.Succeeded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <bool> {
                    Message = ex.Message
                });
            }
        }
Esempio n. 3
0
        public OperationResult <bool> JustifyDelay(DelayInfo delay, string reason, int?causedBy)
        {
            try
            {
                if (reason.IsNullOrWhiteSpace())
                {
                    return new OperationResult <bool> {
                               Message = "Bitte Grund angeben!"
                    }
                }
                ;

                var SettingsResult = SettingsBLL.GetSettings();
                ValidateResult(SettingsResult);
                var Settings = SettingsResult.Result;

                if (Settings.CheckPlausibility)
                {
                    __CheckDelayJustificationPlausibility(delay, causedBy);
                }

                delay.Reason   = reason;
                delay.CausedBy = causedBy;

                var Result = new OperationResult <bool>();
                Result.Result    = true;
                Result.Succeeded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <bool> {
                    Message = ex.Message
                });
            }
        }
Esempio n. 4
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. 5
0
 public CalculationBLL()
     : base()
 {
     m_SettingsBll = new SettingsBLL();
 }
Esempio n. 6
0
        public OperationResult <bool> LoadESTW(ESTW Estw)
        {
            try
            {
                var Result = new OperationResult <bool>();

                if (Estw.IsLoaded)
                {
                    Result.Succeeded = true;
                    return(Result);
                }

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

                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)
                    {
                        var 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);
                            }
                        }

                        if (PathResult.Result.IsNotNullOrWhiteSpace())
                        {
                            __GetSchedule(Station, PathResult.Result);
                            __ResolveDuplicates(Station.Schedules);
                            __DetectTwinSchedules(Station.Schedules);
                            __GetLocalOrders(Station, PathResult.Result);
                        }
                    }
                }

                if (PathResult.Result.IsNotNullOrWhiteSpace())
                {
                    __LoadTrainCompositions(Estw, PathResult.Result);
                    __LoadTrainRelations(Estw, PathResult.Result);
                }

                Estw.SchedulesLoaded = PathResult.Result.IsNotNullOrWhiteSpace();
                Estw.IsLoaded        = true;
                Result.Result        = true;
                Result.Succeeded     = true;
                return(Result);
            }
            catch (Exception ex)
            {
                Estw.Stations.Clear();
                Estw.Blocks.Clear();
                Estw.IsLoaded = false;

                foreach (var train in Estw.Area.Trains.Values)
                {
                    var schedulesToDelete = train.Schedules.Where(s => s.Station.ESTW.Id == Estw.Id).ToList();
                    schedulesToDelete.ForEach(train.RemoveSchedule);
                }

                return(new OperationResult <bool> {
                    Message = ex.ToString()
                });
            }
        }