-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from odedshimon/refactor-data-context
Refactor data context
- Loading branch information
Showing
32 changed files
with
512 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System.Windows.Forms; | ||
|
||
namespace BruteSharkDesktop | ||
{ | ||
// Originally taken from https://stackoverflow.com/questions/39673815/how-to-recursively-populate-a-treeview-with-json-data | ||
// Did some customizations for BruteShark needs. | ||
public static class JsonTreeViewLoader | ||
{ | ||
public static void LoadJsonToTreeView(this TreeView treeView, string json, string rootNodeText) | ||
{ | ||
var root = JToken.Parse(json); | ||
DisplayTreeView(treeView, root, rootNodeText); | ||
} | ||
|
||
private static void DisplayTreeView(TreeView treeView, JToken root, string rootName) | ||
{ | ||
treeView.BeginUpdate(); | ||
try | ||
{ | ||
treeView.Nodes.Clear(); | ||
var tNode = treeView.Nodes[treeView.Nodes.Add(new TreeNode(rootName))]; | ||
tNode.Tag = root; | ||
|
||
AddNode(root, tNode); | ||
|
||
treeView.ExpandAll(); | ||
} | ||
finally | ||
{ | ||
treeView.EndUpdate(); | ||
} | ||
} | ||
|
||
private static void AddNode(JToken token, TreeNode inTreeNode) | ||
{ | ||
if (token == null) | ||
return; | ||
if (token is JValue) | ||
{ | ||
var childNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(token.ToString()))]; | ||
childNode.Tag = token; | ||
} | ||
else if (token is JObject jObject) | ||
{ | ||
foreach (var property in jObject.Properties()) | ||
{ | ||
var childNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(property.Name))]; | ||
childNode.Tag = property; | ||
AddNode(property.Value, childNode); | ||
} | ||
} | ||
else if (token is JArray jArray) | ||
{ | ||
foreach (JValue jv in jArray) | ||
{ | ||
var childNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(jv.ToString()))]; | ||
} | ||
} | ||
else | ||
{ | ||
// TODO: log | ||
// Debug.WriteLine(string.Format("{0} not implemented", token.Type)); // JConstructor, JRaw | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 38 additions & 2 deletions
40
...eShark/BruteSharkDesktop/UserControls/NetworkMapControl/NetworkMapUserControl.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.