Beispiel #1
0
        public void Save(Configuration config)
        {
            //Create XML configuration model
            XMLConfigurationModel xmlconfig = new XMLConfigurationModel(config);

            //Write XML file to FileLocation
            try
            {
                var serializer = new XmlSerializer(xmlconfig.GetType());
                var stream     = new FileStream(this.FileLocation, FileMode.Create);
                serializer.Serialize(stream, xmlconfig);
                stream.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #2
0
        private XMLConfigurationModel loadConfig()
        {
            XMLConfigurationModel config = new XMLConfigurationModel();

            if (!File.Exists(this.FileLocation))
            {
                this.createDefaultConfig();
            }

            try
            {
                var serializer = new XmlSerializer(config.GetType());
                var stream     = new FileStream(this.FileLocation, FileMode.Open);
                config = (XMLConfigurationModel)serializer.Deserialize(stream);
                stream.Close();
            }
            catch (Exception e)
            {
                this.isValid = false;
            }

            return(config);
        }
Beispiel #3
0
 public XMLConfigFile(String fileDestination)
 {
     this.FileLocation = fileDestination;
     this.xmlConfig    = this.loadConfig();
 }