Ejemplo n.º 1
0
        public static SerializedTreeNode CreateTree(object item, string name)
        {
            Dictionary <string, object> dic;

            if (IsPrimitive(item))
            {
                //dic = new Dictionary<string, object> {{name, item}};
                return(new SerializedTreeNode {
                    Value = item.ToString()
                });
            }
            else
            {
                var jss      = new JavaScriptSerializer();
                var settings = new JsonSerializerSettings {
                    StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
                };
                var serialized = JsonConvert.SerializeObject(item, settings);
                dic = jss.Deserialize <Dictionary <string, object> >(serialized);

                var root = new SerializedTreeNode {
                    Name = name
                };
                BuildTree(dic, root);
                return(root);
            }
        }
Ejemplo n.º 2
0
        public void SetData(string header, SerializedTreeNode treeNode = null, Type type = null)
        {
            _responseTree.BeginUpdate();
            _responseTree.Nodes.Clear();

            var documentation = "";
            var command       = "";

            if (type != null)
            {
                documentation = type.GetDocumentation();
            }

            if (treeNode != null)
            {
                command = "Response";

                var firstNode = _responseTree.Nodes.Add(treeNode.ToString());
                AddElements(firstNode, treeNode);
                firstNode.Expand();
                _responseTree.SelectedNode = _responseTree.Nodes[0];
            }

            webBrowser.DocumentText = VaultAssembly.Html("Response Type", header, documentation, command);
            _responseTree.EndUpdate();
        }
Ejemplo n.º 3
0
 private void AddElements(TreeNode node, SerializedTreeNode tree)
 {
     foreach (var childTree in tree.Children)
     {
         var nextNode = node.Nodes.Add(childTree.ToString());
         AddElements(nextNode, childTree);
     }
 }
Ejemplo n.º 4
0
 private static void BuildTree(object item, SerializedTreeNode node)
 {
     if (item is KeyValuePair <string, object> )
     {
         var kv           = (KeyValuePair <string, object>)item;
         var keyValueNode = new SerializedTreeNode
         {
             Name  = kv.Key,
             Value = GetValueAsString(kv.Value)
         };
         node.Children.Add(keyValueNode);
         BuildTree(kv.Value, keyValueNode);
     }
     else if (item is ArrayList)
     {
         var list  = (ArrayList)item;
         var index = 0;
         foreach (var value in list)
         {
             var arrayItem = new SerializedTreeNode
             {
                 Name  = $"[{index}]",
                 Value = IsPrimitive(value) ? value.ToString() : ""
             };
             node.Children.Add(arrayItem);
             BuildTree(value, arrayItem);
             index++;
         }
     }
     else if (item is Dictionary <string, object> )
     {
         var dictionary = (Dictionary <string, object>)item;
         foreach (var d in dictionary)
         {
             BuildTree(d, node);
         }
     }
 }