public void WriteAsJson(TextWriter output, string mode, ISerializationAnnotator annotator, bool pretty = false, int level = 0) { var jw = new JsonWriter(output,pretty:pretty,level:level); jw.OpenObject(); if (0 != Meta.Count) { jw.WriteProperty("meta",Meta); } if (null == Parent && null != Collectors && 0!=Collectors.Length) { jw.WriteProperty("collectors", Collectors.OfType<ICollector>().Select( c => new { key = c.Key, name = c.Name ?? c.Key, shortname = c.ShortName ?? c.Name ?? c.Key, group = c.Group, condition = c.Condition }.jsonify()).ToArray()); } if (null == Parent && null != Routs && 0 != Routs.Length) { jw.WriteProperty("routs", Routs.Select( c => new { key = c.Key ?? "nokey", name = c.Name ?? c.Key, shortname = c.ShortName ?? c.Name ?? c.Key, level = c.Level, parent = null == c.Parent ? "" : c.Parent.Key, }.jsonify()).ToArray()); } jw.WriteProperty("id",Id); jw.WriteProperty("isbucket",IsBucket); if (null != RouteKey) { jw.WriteProperty("key",RouteKey.Key); jw.WriteProperty("name",RouteKey.Name); jw.WriteProperty("sortkey",RouteKey.SortKey); jw.WriteProperty("comment",RouteKey.Comment); } jw.OpenProperty("values"); jw.OpenArray(); foreach (var value in Values) { jw.WriteObject(new {key=value.Key,value=value.Value}); } jw.CloseArray(); jw.CloseProperty(); if (null != _children && 0 != _children.Count) { jw.OpenProperty("aggs"); jw.OpenArray(); foreach (var node in Children) { jw.WriteObject(node.Value); } jw.CloseArray(); jw.CloseProperty(); } jw.CloseObject(); }
protected override void WriteJsonInternal(JsonWriter jw, string mode) { mode = mode ?? ""; base.WriteJsonInternal(jw, mode); jw.WriteProperty("onform",OnForm,true); jw.WriteProperty("onquery",OnQuery,true); jw.WriteProperty("toolview",ToolView,true); if (!mode.Contains("noagents")) { jw.OpenProperty("agents"); jw.OpenArray(); foreach (var agentDefinition in Agents) { jw.WriteObject(agentDefinition, mode); } jw.CloseArray(); jw.CloseProperty(); } if (!mode.Contains("noparams")) { jw.WriteProperty("parameters", Parameters.Select(_=>_.Value as object).ToArray()); } }
public void WriteAsJson(TextWriter output, string mode, ISerializationAnnotator annotator, bool pretty = false, int level = 0) { if (string.IsNullOrWhiteSpace(mode)) { mode = "admin"; } var jw = new JsonWriter(output,pretty:pretty,level:level); jw.OpenObject(); jw.WriteProperty("name",Name); jw.WriteProperty("isauth",IsAuthenticated); jw.WriteProperty("authtype",AuthenticationType); jw.WriteProperty("isadmin",IsAdmin,true); jw.WriteProperty("isguest",IsGuest,true); jw.WriteProperty("iserror",IsError,true); jw.WriteProperty("state",State,true); jw.WriteProperty("stateinfo",StateInfo,true); if (null != Token) { jw.OpenProperty("token"); jw.WriteNative(Token.stringify(mode)); jw.CloseProperty(); } if (null != User) { jw.OpenProperty("user"); jw.WriteNative(User.stringify(mode)); jw.CloseProperty(); } jw.CloseObject(); }