public JsonStringSettings(string text) { var val = JValue.Parse(text); if (val.Type != TokenType.Object) throw new FormatException("required json object in content"); _obj = (JObject)val; }
public JsonStringSettings(string text) : base(Global.PlainConverter, Global.GenericDeserializer) { var val = JValue.Parse(text); if (val.Type != TokenType.Object) throw new FormatException("required json object in content"); _obj = (JObject)val; }
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); } }
public JsonFileSettings(string fileName, IStringConverter converter, IGenericDeserializer deserializer) : base(converter, deserializer) { try { fileName = System.IO.Path.GetFullPath(fileName); var content = File.ReadAllBytes(fileName); var val = JValue.Parse(Encoding.UTF8.GetString(content)); if (val.Type != TokenType.Object) throw new FormatException("required json object in content"); _obj = (JObject)val; Identity = this.GetIdentitySource(fileName); Path = System.IO.Path.GetDirectoryName(fileName); _fm = this.GetMonitoring(fileName, content); } catch(SystemException ex) { throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex); } }
internal JObject ReadObject() { var result = new JObject(); if (!MoveTo('\"', '}')) throw new FormatException("unexpected end in the reading of object"); if (Current == '}') return result; while (true) { var propName = ReadString(); if (!MoveTo(':')) throw new FormatException("unexpected end in the reading of object"); var propValue = ReadValue(true); result.Properties.Add(new KeyValuePair<string, JValue>(propName.Value, propValue)); if (!MoveTo(',', '}')) throw new FormatException("unexpected end in the reading of object"); if (Current == '}') return result; if (!MoveTo('\"')) throw new FormatException("unexpected end in the reading of object"); } }
/// <summary> /// The mapping JSON-document to nodes of configuration /// </summary> /// <param name="converter">string converter into a simple values</param> /// <param name="obj">JSON object</param> public ViewObject(JObject obj) { _obj = obj; }