Exemplo n.º 1
0
        /// <summary>
        /// Loads the star system.
        /// </summary>
        /// <param name="starSystemName">Name of the star system.</param>
        /// <param name="dataService">The data service, providig access to data stream.</param>
        /// <returns></returns>
        public StarSystem LoadStarSystem(string starSystemName, IGalaxyMapDataStreamProvider dataService)
        {
            logger.Info("Loading star system: {0}", starSystemName);
            this.HasValidationFailed = false;

            XmlReaderSettings readerSettings = new XmlReaderSettings();

            readerSettings.IgnoreComments = true;

            // Pro validaci při načítání, možnost zvýšení výkonu.
            //readerSettings.ValidationType = ValidationType.Schema;
            //readerSettings.ValidationFlags = readerSettings.ValidationFlags | XmlSchemaValidationFlags.ReportValidationWarnings;
            //readerSettings.Schemas.Add(this.StarSystemSchema);

            using (XmlReader reader = XmlReader.Create(dataService.GetStarSystemStream(starSystemName), readerSettings))
            {
                XmlDocument doc = new XmlDocument();
                doc.Schemas.Add(this.StarSystemSchema);
                doc.Load(reader);
                doc.Validate(ValidationEventHandler);

                if (this.HasValidationFailed)
                {
                    throw new XmlException(String.Format("Xml validation failed for '{0}'", starSystemName));
                }

                XmlNode starSystemNode = doc.GetElementsByTagName("starsystem")[0];

                StarSystem starSystem = starSystemNode.ParseStarSystem();

                return(starSystem);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the star systems defined in the map.
        /// </summary>
        /// <param name="starSystems">The list of star systems.</param>
        /// <param name="streamProvider">Provider of map data streams.</param>
        /// <param name="map">The map.</param>
        private void LoadStarSystems(IList <string> starSystems, IGalaxyMapDataStreamProvider streamProvider, GalaxyMap map)
        {
            StarSystemLoader loader = new StarSystemLoader();
            StarSystem       starSystem;

            foreach (string starSystemName in starSystems)
            {
                starSystem = loader.LoadStarSystem(starSystemName, streamProvider);
                if (map.ContainsKey(starSystem.Name))
                {
                    throw new XmlException("Duplicate star system name in starsystems");
                }
                else
                {
                    map.Add(starSystem);
                }
            }
        }
Exemplo n.º 3
0
        public GalaxyMap LoadGalaxyMap(string mapName, IGalaxyMapDataStreamProvider dataService)
        {
            using (Stream stream = dataService.GetGalaxyMapStream(mapName))
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                readerSettings.IgnoreComments = true;
                using (XmlReader reader = XmlReader.Create(stream, readerSettings))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(reader);
                    XmlNode galaxyNode = doc.GetElementsByTagName("galaxy")[0];

                    GalaxyMap map = new GalaxyMap();
                    map.MapName = galaxyNode.Attributes["name"].Value.ToString();
                    IList <string> starSystemNames          = null;
                    IList <GalaxyMapConnection> connections = null;
                    foreach (XmlNode childNode in galaxyNode.ChildNodes)
                    {
                        switch (childNode.Name.ToLowerInvariant())
                        {
                        case "starsystems":
                            starSystemNames = childNode.ParseStarSystems();
                            break;

                        case "wormholes":
                            connections = childNode.ParseWormholes();
                            break;

                        default:
                            throw new XmlException("Unexpected childNode.");
                        }
                    }
                    Debug.Assert(starSystemNames != null, "starSystemNames is null");
                    Debug.Assert(connections != null, "connections is null");


                    this.LoadStarSystems(starSystemNames, dataService, map);
                    this.ApplyConnections(connections, map);

                    return(map);
                }
            }
        }