public JsonTreeObjectPropertyDescriptor(JsonObject jsonObject) : base(jsonObject.Id, null) { _jsonObject = jsonObject; if (_jsonObject.JsonType == JsonType.Array) InitJsonObject(); }
public void Should_Contstruct_New_Fields_Correctly() { var parent = new JsonObject(); var fields = new JsonFields(parent); Assert.That(fields.Count, Is.EqualTo(0)); }
public bool CanVisualize(JsonObject jsonObject) { if (jsonObject.JsonType == JsonType.Value && jsonObject.Value is string) { string text = (string)jsonObject.Value; return (text.Length > 2 && text[0] == '@' && text[text.Length - 1] == '@'); } return false; }
public Control GetControl(JsonObject jsonObject) { if (tb == null) { tb = new TextBox(); tb.Multiline = true; } return tb; }
public string GetText(JsonObject jsonObject) { int year,month,day,hour,min,second,ms; year = (int)(long)jsonObject.Fields["y"].Value; month = (int)(long)jsonObject.Fields["M"].Value; day = (int)(long)jsonObject.Fields["d"].Value; hour = (int)(long)jsonObject.Fields["h"].Value; min = (int)(long)jsonObject.Fields["m"].Value; second = (int)(long)jsonObject.Fields["s"].Value; ms = (int)(long)jsonObject.Fields["ms"].Value; return new DateTime(year, month, day, hour, min, second, ms).ToString(); }
private void FillHeaders(JsonObject jsonObject) { foreach (JsonObject header in jsonObject.Fields) { JsonObject nameHeader = header.Fields["name"]; if (nameHeader.JsonType == JsonType.Value && nameHeader.Value is string) { string name = (string)nameHeader.Value; lvGrid.Columns.Add(name); } } }
private JsonObject CreateJsonObject(object jsonObject) { JsonObject obj = new JsonObject(); if (jsonObject is JavaScriptArray) obj.JsonType = JsonType.Array; else if (jsonObject is JavaScriptObject) obj.JsonType = JsonType.Object; else { obj.JsonType = JsonType.Value; obj.Value = jsonObject; } return obj; }
void IJsonVisualizer.Visualize(JsonObject jsonObject) { lvGrid.BeginUpdate(); try { lvGrid.Columns.Clear(); lvGrid.Items.Clear(); FillHeaders(jsonObject.Fields["headers"]); FillRows(jsonObject.Fields["rows"]); } finally { lvGrid.EndUpdate(); } }
private void FillRows(JsonObject jsonObject) { string value; foreach (JsonObject row in jsonObject.Fields) { List<string> rowValues = new List<string>(); foreach (JsonObject rowValue in row.Fields) { if (rowValue.JsonType == JsonType.Value && rowValue.Value != null) { value = rowValue.Value.ToString(); } else value = String.Empty; rowValues.Add(value); } ListViewItem rowItem = new ListViewItem(rowValues.ToArray()); lvGrid.Items.Add(rowItem); } }
private static void AddChildren(object jsonObject, JsonObject obj) { JavaScriptObject javaScriptObject = jsonObject as JavaScriptObject; if (javaScriptObject != null) { foreach (KeyValuePair<string, object> pair in javaScriptObject) { obj.Fields.Add(ConvertToObject(pair.Key, pair.Value)); } } else { JavaScriptArray javaScriptArray = jsonObject as JavaScriptArray; if (javaScriptArray != null) { for (int i = 0; i < javaScriptArray.Count; i++) { obj.Fields.Add(ConvertToObject("[" + i.ToString() + "]", javaScriptArray[i])); } } } }
public bool CanVisualize(JsonObject jsonObject) { return (jsonObject.JsonType == JsonType.Array) && (jsonObject.ContainsFields("[0]")); }
public JsonTreeObjectTypeDescriptor(JsonObject jsonObject) { _jsonObject = jsonObject; InitPropertyCollection(); }
private void AddNode(TreeNodeCollection nodes, JsonObject jsonObject) { if(!ckObjectsOnly.Checked || jsonObject.JsonType == JsonType.Object) { JsonViewerTreeNode newNode = new JsonViewerTreeNode(jsonObject); nodes.Add(newNode); newNode.Text = GetNodeLabel(jsonObject); newNode.Tag = jsonObject; newNode.ImageIndex = (int)jsonObject.JsonType; newNode.SelectedImageIndex = newNode.ImageIndex; foreach(JsonObject field in jsonObject.Fields) { AddNode(newNode.Nodes, field); } } }
public void Visualize(JsonObject jsonObject) { tb.Text = String.Format("Array {0} has {1} items", jsonObject.Id, jsonObject.Fields.Count); }
private string GetNodeLabel(JsonObject jsonObject) { string label = jsonObject.Text; if(txtLabelName.Text.Trim() != "") { JsonObject extraField = jsonObject.Fields[txtLabelName.Text.Trim()]; string extra = (extraField != null && extraField.JsonType == JsonType.Value)? ": "+extraField.Value : ""; label += extra; } else if(ParseTreeMode) { try { int srcIndexStart = Convert.ToInt32(GetValue(jsonObject, "srcIndexStart")); int srcLength = Convert.ToInt32(GetValue(jsonObject, "srcLength")); bool shortened=false; if(srcLength > 256) { srcLength = 256; shortened = true; } Util.ClampRange(ref srcIndexStart, ref srcLength, 0, parsedSrc.Length); string labelExtra = parsedSrc.Substring(srcIndexStart, srcLength).Trim(); int indexOfNewline = labelExtra.IndexOfAny(new char[]{'\n', '\r'}); if(indexOfNewline != -1) { labelExtra = labelExtra.Substring(0, indexOfNewline); shortened = true; } label += ": " + labelExtra; if(shortened && labelExtra.Trim() != "") label += "..."; } catch(ArgumentOutOfRangeException) { } catch(FormatException) { // It's ok, srcIndexStart and srcLength either didn't exist // or were invalid, so just don't add anything. } } return label; }
public bool CanVisualize(JsonObject jsonObject) { return jsonObject.ContainsFields("y","M","d","h","m","s","ms"); }
public string GetText(JsonObject jsonObject) { string text = (string)jsonObject.Value; return "Ajax.Net Date:"+ConvertJSTicksToDateTime(Convert.ToInt64(text.Substring(1, text.Length - 2))).ToString(); }
void IJsonVisualizer.Visualize(JsonObject jsonObject) { this.pgJsonObject.SelectedObject = new JsonTreeObjectTypeDescriptor(jsonObject); }
public JsonViewerTreeNode(JsonObject jsonObject) { _jsonObject = jsonObject; }
private void SelectNodeInSource(JsonObject obj) { if(obj != null && ParseTreeMode) { DehighlightParsedSrc(); try { int srcIndexStart = Convert.ToInt32(GetValue(obj, "srcIndexStart")); int srcLength = Convert.ToInt32(GetValue(obj, "srcLength")); Util.ClampRange(ref srcIndexStart, ref srcLength, 0, parsedSrc.Length); HighlightParsedSrc(srcIndexStart, srcLength); } catch(FormatException) { // It's ok, srcIndexStart and srcLength either didn't exist // or were invalid, so just don't highlight anything. } } }
void IJsonVisualizer.Visualize(JsonObject jsonObject) { this.pgJsonObject.SelectedObject = jsonObject; }
public JsonObjectTree(object rootObject) { _root = ConvertToObject("JSON", rootObject); }
bool IJsonViewerPlugin.CanVisualize(JsonObject jsonObject) { return(true); }
private string GetValue(JsonObject obj, string key) { return obj.ContainsField(key, JsonType.Value)? ""+obj.Fields[key].Value : ""; }
Control IJsonVisualizer.GetControl(JsonObject jsonObject) { return this; }
bool IJsonViewerPlugin.CanVisualize(JsonObject jsonObject) { return true; }
private static JsonObject CreateJsonObject(object jsonObject) { JsonObject obj = new JsonObject(); if (jsonObject is JavaScriptArray) obj.JsonType = JsonType.Array; else if (jsonObject is JavaScriptObject) obj.JsonType = JsonType.Object; else { if (typeof(string) == jsonObject.GetType()) { Match match = dateRegex.Match(jsonObject as string); if (match.Success) { // I'm not sure why this is match.Groups[1] and not match.Groups[0] // we need to convert milliseconds to windows ticks (one tick is one hundred nanoseconds (e-9)) Int64 ticksSinceEpoch = Int64.Parse(match.Groups[1].Value) * (Int64)10e3; jsonObject = DateTime.SpecifyKind(new DateTime(1970, 1, 1).Add(new TimeSpan(ticksSinceEpoch)), DateTimeKind.Utc); // Take care of the timezone offset if (!string.IsNullOrEmpty(match.Groups[2].Value)) { Int64 timeZoneOffset = Int64.Parse(match.Groups[2].Value); jsonObject = ((DateTime)jsonObject).AddHours(timeZoneOffset/100); // Some timezones like India Tehran and Nepal have fractional offsets from GMT jsonObject = ((DateTime)jsonObject).AddMinutes(timeZoneOffset%100); } } } obj.JsonType = JsonType.Value; obj.Value = jsonObject; } return obj; }
private void AddNode(TreeNodeCollection nodes, JsonObject jsonObject) { JsonViewerTreeNode newNode = new JsonViewerTreeNode(jsonObject); nodes.Add(newNode); newNode.Text = jsonObject.Text; newNode.Tag = jsonObject; newNode.ImageIndex = (int)jsonObject.JsonType; newNode.SelectedImageIndex = newNode.ImageIndex; foreach (JsonObject field in jsonObject.Fields) { AddNode(newNode.Nodes, field); } }
bool IJsonViewerPlugin.CanVisualize(JsonObject jsonObject) { return jsonObject.ContainsField("headers", JsonType.Array) && jsonObject.ContainsField("rows", JsonType.Array); }
Control IJsonVisualizer.GetControl(JsonObject jsonObject) { return(this); }