Example #1
0
 /// <summary>
 /// settings loaded from a file
 /// </summary>
 /// <param name="fileName">file name</param>
 public XmlFileSettings(string fileName)
 {
     try
     {
         _fileInfo = ReadedFileInfo.Create(fileName,
                                           stream => { _root = XDocument.Load(stream).Root; });
     }
     catch (SystemException ex)
     {
         throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex);
     }
 }
Example #2
0
 public IniFileSettings(string fileName)
 {
     try
     {
         var context = new ParseContext();
         _fileInfo = ReadedFileInfo.Create(fileName, stream =>
         {
             using (var sr = new StreamReader(stream, Encoding.UTF8))
                 context.ParseSource(sr.ReadToEnd());
         });
         _sections = new List <Section>(context.Sections);
     }
     catch (SystemException ex)
     {
         throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex);
     }
 }
Example #3
0
        public JsonFileSettings(string fileName)
        {
            try
            {
                JValue val = null;
                _fileInfo = ReadedFileInfo.Create(fileName, stream =>
                {
                    using (var sr = new StreamReader(stream, Encoding.UTF8))
                        val = JValue.Parse(sr.ReadToEnd());
                });

                if (val.Type != TokenType.Object)
                {
                    throw new FormatException("required json object in content");
                }

                _obj = (JObject)val;
            }
            catch (SystemException ex)
            {
                throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex);
            }
        }