public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { var data = new Dictionary <string, object>(); WriteJSONFields(data, options); JSONWriter.WriteMap(wri, data, nestingLevel, options); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONDataMap map = new JSONDataMap { { "unit", UnitName }, { "value", Value } }; map.ToJSON(wri, options); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$oid", Convert.ToBase64String(Bytes)) ); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$timestamp", new { t = EpochSeconds, i = Increment }) ); }
public override void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$maxKey", 1) ); }
public override void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$numberLong", Value) ); }
public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { wri.Write('"'); wri.Write(Era); wri.Write(':'); wri.Write(ID); wri.Write('"'); }
public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { wri.Write('{'); wri.Write("\"iso\":"); JSONWriter.EncodeString(wri, m_CurrencyISO, options); wri.Write(','); wri.Write("\"v\":"); wri.Write(m_Value); wri.Write('}'); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$regex", Pattern), new DictionaryEntry("$options", Options.ToBSONString()) ); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$type", Type), new DictionaryEntry("$binary", Convert.ToBase64String(Data)) ); }
/// <summary> /// Writes schema as JSON. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class /// </summary> public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { var map = new Dictionary <string, object> { { "Name", "JSON" + m_Name.GetHashCode() }, { "FieldDefs", m_FieldDefs } }; JSONWriter.WriteMap(wri, map, nestingLevel, options); }
/// <summary> /// Writes an object as JSON. Does nothing if object is null /// </summary> public void WriteJSON(object data, JSONWritingOptions options = null) { if (data == null) { return; } setWasWrittenTo(); m_NetResponse.ContentType = NFX.Web.ContentType.JSON; JSONWriter.Write(data, new NonClosingStreamWrap(getStream()), options, Encoding); }
/// <summary> /// Saves configuration into a JSON file /// </summary> public void SaveAs(string filename, JSONWritingOptions options = null, Encoding encoding = null) { var data = ToConfigurationJSONDataMap(); if (options == null) { options = JSONWritingOptions.PrettyPrint; } JSONWriter.WriteToFile(data, filename, options, encoding); base.SaveAs(filename); }
public NFXJson(TestingSystem context, IConfigSectionNode conf) : base(context, conf) { var nopt = conf[CONFIG_OPTIONS_SECTION]; if (nopt.Exists) { m_Options = new JSONWritingOptions(); m_Options.Configure(nopt); } else { m_Options = JSONWritingOptions.Compact; } }
protected override void DoConfigure(IConfigSectionNode node) { base.DoConfigure(node); if (node == null) { return; } var on = node[CONFIG_JSON_OPT_SECTION]; if (on.Exists) { m_Options = FactoryUtils.MakeAndConfigure <JSONWritingOptions>(on, typeof(JSONWritingOptions)); } }
protected virtual void WriteJSONFields(IDictionary <string, object> data, JSONWritingOptions options) { data["cnt"] = this.Count; data["sd"] = this.UTCTime; data["ed"] = this.UTCEndTime; data["rate"] = this.Rate; data["val"] = this.ValueAsObject; data["plt"] = this.PlotValue; if (options != null && options.Purpose >= JSONSerializationPurpose.Marshalling) { data["src"] = this.Source; data["aggr"] = this.IsAggregated; data["tp"] = this.GetType().FullName; data["descr"] = this.Description; data["unit"] = this.ValueUnitName; } }
public JSONResult(Exception error, JSONWritingOptions options) { var http = WebConsts.STATUS_500; var descr = WebConsts.STATUS_500_DESCRIPTION; if (error != null) { descr = error.Message; var httpError = error as HTTPStatusException; if (httpError != null) { http = httpError.StatusCode; descr = httpError.StatusDescription; } } Data = new { OK = false, http = http, descr = descr }; Options = options; }
public override void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { if (Value.ToUniversalTime() >= MiscUtils.UNIX_EPOCH_START_DATE) { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$date", Value.ToMillisecondsSinceUnixEpochStart()) ); } else { JSONWriter.WriteMap(wri, nestingLevel + 1, options, new DictionaryEntry("$date", "{{ \"$numberLong\" : {0} }}".Args(Value.Ticks / TimeSpan.TicksPerMillisecond)) ); } }
/// <summary> /// Writes row as JSON either as an array or map depending on JSONWritingOptions.RowsAsMap setting. /// Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class /// </summary> public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { if (options == null || !options.RowsAsMap) { JSONWriter.WriteArray(wri, this, nestingLevel, options); return; } var map = new Dictionary <string, object>(); foreach (var fd in Schema) { string name; var val = FilterJSONSerializerField(fd, options, out name); if (name.IsNullOrWhiteSpace()) { continue; } map[name] = val; } if (this is IAmorphousData) { var amorph = (IAmorphousData)this; if (amorph.AmorphousDataEnabled) { foreach (var kv in amorph.AmorphousData) { var key = kv.Key; while (map.ContainsKey(key)) { key += "_"; } map.Add(key, kv.Value); } } } JSONWriter.WriteMap(wri, map, nestingLevel, options); }
public void NLSMap_SerializeOnlyOneExisting() { var content = "eng{n='Cucumber' d='It is green'} deu{n='Gurke' d='Es ist grün'}"; var nls = new NLSMap(content); var options = new JSONWritingOptions { NLSMapLanguageISO = "deu", Purpose = JSONSerializationPurpose.UIFeed }; var json = nls.ToJSON(options); Console.WriteLine(json); dynamic read = json.JSONToDynamic(); Assert.IsNotNull(read); Assert.AreEqual("Gurke", read.n); Assert.AreEqual("Es ist grün", read.d); }
/// <summary> /// Writes rowset as JSON including schema information. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class /// </summary> public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { var tp = GetType(); var metadata = options != null && options.RowsetMetadata; var map = new Dictionary <string, object> //A root JSON object is needed for security, as some browsers can EXECUTE a valid JSON root array { { "Rows", m_List } }; if (metadata) { map.Add("Instance", m_InstanceGUID.ToString("D")); map.Add("Type", tp.FullName); map.Add("IsTable", typeof(Table).IsAssignableFrom(tp)); map.Add("Schema", m_Schema); } JSONWriter.WriteMap(wri, map, nestingLevel, options); }
public void NLSMap_SerializeOnlyOneNoneExisting() { var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}"; var nls = new NLSMap(content); var options = new JSONWritingOptions { NLSMapLanguageISO = "rus", Purpose = JSONSerializationPurpose.UIFeed }; var json = nls.ToJSON(options); Console.WriteLine(json); dynamic read = json.JSONToDynamic(); Aver.IsNotNull(read); Aver.AreEqual("Cucumber", read.n); Aver.AreEqual("It is green", read.d); }
/// <summary> /// Override to filter-out some fields from serialization to JSON, or change field values. /// Return name null to indicate that field should be filtered-out(excluded from serialization to JSON) /// </summary> protected virtual object FilterJSONSerializerField(Schema.FieldDef def, JSONWritingOptions options, out string name) { var tname = options != null ? options.RowMapTargetName : null; if (tname.IsNotNullOrWhiteSpace()) { FieldAttribute attr; name = def.GetBackendNameForTarget(tname, out attr); if (attr != null) { if (attr.StoreFlag == StoreFlag.None || attr.StoreFlag == StoreFlag.OnlyLoad) { name = null; return(null); } var dflt = attr.Default; if (dflt != null) { var value = GetFieldValue(def); if (dflt.Equals(value)) { name = null; return(null); } return(value); } } } else { name = def.Name; } return(name.IsNotNullOrWhiteSpace() ? GetFieldValue(def) : null); }
/// <summary> /// Writes fielddef as JSON. Do not call this method directly, instead call rowset.ToJSON() or use JSONWriter class /// </summary> public void WriteAsJSON(System.IO.TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { var attr = this[null]; if (attr != null && attr.NonUI) { wri.Write("{}"); return; //nothing to write for NONUI } bool typeIsNullable; string tp = JSONMappings.MapCLRTypeToJSON(m_Type, out typeIsNullable); var map = new Dictionary <string, object> { { "Name", m_Name }, { "Order", m_Order }, { "Type", tp }, { "Nullable", typeIsNullable } }; if (attr != null) { map.Add("IsKey", attr.Key); map.Add("IsRequired", attr.Required); map.Add("Visible", attr.Visible); if (attr.Default != null) { map.Add("Default", attr.Default); } if (attr.CharCase != CharCase.AsIs) { map.Add("CharCase", attr.CharCase); } if (attr.Kind != DataKind.Text) { map.Add("Kind", attr.Kind); } if (attr.MinLength != 0) { map.Add("MinLen", attr.MinLength); } if (attr.MaxLength != 0) { map.Add("MaxLen", attr.MaxLength); } if (attr.Min != null) { map.Add("Min", attr.Min); } if (attr.Max != null) { map.Add("Max", attr.Max); } if (attr.ValueList != null) { map.Add("ValueList", attr.ValueList); } if (attr.Description != null) { map.Add("Description", attr.Description); } //metadata content is in the internal format and not dumped } JSONWriter.WriteMap(wri, map, nestingLevel, options); }
/// <summary> /// Serializes this dosument into a TextWriter - this method is used by JSON serializer(JSONWriter) /// </summary> public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { //this will throw nesting exception in case of cyclical graph JSONWriter.WriteMap(wri, this.Select(elm => new DictionaryEntry(elm.Name, elm)), nestingLevel + 1, options); }
/// <summary> /// Saves JSON configuration to string /// </summary> public string SaveToString(JSONWritingOptions options = null) { var data = ToConfigurationJSONDataMap(); return(JSONWriter.Write(data, options)); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.WriteMap(wri, m_Content, nestingLevel, options); }
public void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { ToJSONDataMap().ToJSON(wri, options); }
public virtual void WriteAsJSON(TextWriter wri, int nestingLevel, JSONWritingOptions options = null) { JSONWriter.Write(this.ObjectValue, wri, options); }
public JSONResult(object data, JSONWritingOptions options) { Data = data; Options = options; }