/// <summary>
        /// Load the dedicated server configuration file
        /// </summary>
        /// <param name="fileInfo">Path to the configuration file</param>
        /// <returns></returns>
        public static MyConfigDedicatedData Load(FileInfo fileInfo)
        {
            object fileContent;

            string filePath = fileInfo.FullName;

            if (!File.Exists(filePath))
            {
                throw new GameInstallationInfoException(GameInstallationInfoExceptionState.ConfigFileMissing, filePath);
            }

            try
            {
                XmlReaderSettings settings = new XmlReaderSettings
                {
                    IgnoreComments   = true,
                    IgnoreWhitespace = true,
                };

                using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
                {
                    MyConfigDedicatedDataSerializer serializer = (MyConfigDedicatedDataSerializer)Activator.CreateInstance(typeof(MyConfigDedicatedDataSerializer));
                    fileContent = serializer.Deserialize(xmlReader);
                }
            }
            catch
            {
                throw new GameInstallationInfoException(GameInstallationInfoExceptionState.ConfigFileCorrupted, filePath);
            }

            if (fileContent == null)
            {
                throw new GameInstallationInfoException(GameInstallationInfoExceptionState.ConfigFileEmpty, filePath);
            }

            return((MyConfigDedicatedData)fileContent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the dedicated server configuration file
        /// </summary>
        /// <param name="fileInfo">Path to the configuration file</param>
        /// <exception cref="FileNotFoundException">Thrown if configuration file cannot be found at the path specified.</exception>
        /// <returns></returns>
        /// <exception cref="ConfigurationErrorsException">Configuration file not understood. See inner exception for details. Ignore configuration file line number in outer exception.</exception>
        public static MyConfigDedicatedData Load(FileInfo fileInfo)
        {
            object fileContent;

            string filePath = fileInfo.FullName;

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Game configuration file not found.", filePath);
            }

            try
            {
                XmlReaderSettings settings = new XmlReaderSettings
                {
                    IgnoreComments   = true,
                    IgnoreWhitespace = true,
                };

                using (XmlReader xmlReader = XmlReader.Create(filePath, settings))
                {
                    MyConfigDedicatedDataSerializer serializer = (MyConfigDedicatedDataSerializer)Activator.CreateInstance(typeof(MyConfigDedicatedDataSerializer));
                    fileContent = serializer.Deserialize(xmlReader);
                }
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException("Configuration file not understood. See inner exception for details. Ignore configuration file line number in outer exception.", ex, filePath, -1);
            }

            if (fileContent == null)
            {
                throw new ConfigurationErrorsException("Configuration file empty.");
            }

            return((MyConfigDedicatedData)fileContent);
        }