Beispiel #1
0
 /// <summary>
 /// Saves the configuration file.
 /// </summary>
 public static void Save(Configuration config, string file)
 {
     try
     {
         var cfg = JsonConvert.SerializeObject(config, Formatting.Indented);
         using (var sWriter = new StreamWriter(file))
         {
             sWriter.Write(cfg);
         }
     }
     catch
     {
     }
 }
Beispiel #2
0
        /// <summary>
        /// Attempts to parse the configuration file.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static Configuration Parse(string file)
        {
            // Ensure the config file exists..
            if (!System.IO.File.Exists(file))
            {
                var config = new Configuration();
                Configuration.Save(config, file);
                return config;
            }

            try
            {
                using (var sReader = new StreamReader(file))
                {
                    return JsonConvert.DeserializeObject<Configuration>(sReader.ReadToEnd());
                }
            }
            catch
            {
                return new Configuration();
            }
        }