示例#1
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
                });
            }
        }
示例#2
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()
                });
            }
        }