public JsonTreeObjectPropertyDescriptor(JsonObject jsonObject)
     : base(jsonObject.Id, null)
 {
     _jsonObject = jsonObject;
     if (_jsonObject.JsonType == JsonType.Array)
         InitJsonObject();
 }
示例#2
0
        public void Should_Contstruct_New_Fields_Correctly()
        {
            var parent = new JsonObject();
            var fields = new JsonFields(parent);

            Assert.That(fields.Count, Is.EqualTo(0));
        }
示例#3
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;
 }
示例#4
0
 public Control GetControl(JsonObject jsonObject)
 {
     if (tb == null)
     {
         tb = new TextBox();
         tb.Multiline = true;
     }
     return tb;
 }
示例#5
0
 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();
 }
示例#6
0
 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);
         }
     }
 }
示例#7
0
 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;
 }
示例#8
0
 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();
     }
 }
示例#9
0
 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);
     }
 }
示例#10
0
 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]));
             }
         }
     }
 }
示例#11
0
 public bool CanVisualize(JsonObject jsonObject)
 {
     return (jsonObject.JsonType == JsonType.Array) && (jsonObject.ContainsFields("[0]"));
 }
 public JsonTreeObjectTypeDescriptor(JsonObject jsonObject)
 {
     _jsonObject = jsonObject;
     InitPropertyCollection();
 }
示例#13
0
        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);
                }
            }
        }
示例#14
0
 public void Visualize(JsonObject jsonObject)
 {
     tb.Text = String.Format("Array {0} has {1} items", jsonObject.Id, jsonObject.Fields.Count);
 }
示例#15
0
        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;
        }
示例#16
0
 public bool CanVisualize(JsonObject jsonObject)
 {
     return jsonObject.ContainsFields("y","M","d","h","m","s","ms");
 }
示例#17
0
 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);
 }
示例#19
0
 void IJsonVisualizer.Visualize(JsonObject jsonObject)
 {
     this.pgJsonObject.SelectedObject = new JsonTreeObjectTypeDescriptor(jsonObject);
 }
示例#20
0
 public JsonViewerTreeNode(JsonObject jsonObject)
 {
     _jsonObject = jsonObject;
 }
示例#21
0
 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.
         }
     }
 }
示例#22
0
 void IJsonVisualizer.Visualize(JsonObject jsonObject)
 {
     this.pgJsonObject.SelectedObject = jsonObject;
 }
示例#23
0
 public JsonObjectTree(object rootObject)
 {
     _root = ConvertToObject("JSON", rootObject);
 }
示例#24
0
 bool IJsonViewerPlugin.CanVisualize(JsonObject jsonObject)
 {
     return(true);
 }
示例#25
0
 private string GetValue(JsonObject obj, string key)
 {
     return obj.ContainsField(key, JsonType.Value)?
         ""+obj.Fields[key].Value : "";
 }
示例#26
0
 Control IJsonVisualizer.GetControl(JsonObject jsonObject)
 {
     return this;
 }
 bool IJsonViewerPlugin.CanVisualize(JsonObject jsonObject)
 {
     return true;
 }
示例#28
0
 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;
 }
示例#29
0
        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);
            }
        }
示例#30
0
 bool IJsonViewerPlugin.CanVisualize(JsonObject jsonObject)
 {
     return jsonObject.ContainsField("headers", JsonType.Array) &&
         jsonObject.ContainsField("rows", JsonType.Array);
 }
示例#31
0
 Control IJsonVisualizer.GetControl(JsonObject jsonObject)
 {
     return(this);
 }