private Attempt <TreeNodeCollection> TryLoadFromLegacyTree(ApplicationTree appTree, string id, FormDataCollection formCollection) { //This is how the legacy trees worked.... var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias); if (treeDef == null) { return(new Attempt <TreeNodeCollection>(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias))); } var bTree = treeDef.CreateInstance(); var treeParams = new TreeParams(); //we currently only support an integer id or a string id, we'll refactor how this works //later but we'll get this working first int startId; if (int.TryParse(id, out startId)) { treeParams.StartNodeID = startId; } else { treeParams.NodeKey = id; } var xTree = new XmlTree(); bTree.SetTreeParameters(treeParams); bTree.Render(ref xTree); return(new Attempt <TreeNodeCollection>(true, LegacyTreeDataAdapter.ConvertFromLegacy(xTree))); }
protected void _printChildren(TreeParams p, TreeChildGroup [] groups) { int count_groups = groups.Count(cg => cg.IsDisplayed()); int i = 0; foreach (var child_group in groups) { if (!child_group.IsDisplayed()) { continue; } bool is_last_group = i + 1 == count_groups; TreeParams p4 = new TreeParams(p, diff: 4, is_not_last: !is_last_group, add_line: !is_last_group); if (!string.IsNullOrEmpty(child_group.Name)) { _printLine(p4, $"{_getBranchSymbol (is_last: is_last_group)}── {child_group.Name}:"); int count_children = child_group.Children.Length; int k = 0; foreach (var child in child_group.Children) { bool is_last_child_of_group = k + 1 == count_children; bool is_last_child_ever = is_last_group && is_last_child_of_group; child.Print(new TreeParams(p4, diff: 4, is_not_last: !is_last_child_of_group, add_line: !is_last_child_of_group)); k++; } } else { int count_children = child_group.Children.Length; int k = 0; foreach (var child in child_group.Children) { bool is_last_child_of_group = k + 1 == count_children; bool is_last_child_ever = is_last_group && is_last_child_of_group; child.Print(new TreeParams(p4, is_not_last: !is_last_child_of_group, add_line: !is_last_child_ever)); k++; } } i++; } }
protected void _printLine(TreeParams p, string value) { if (value.Contains('\n')) { value = value.Replace("\n", "\\n"); } string line = $"[ ] {p.indent_str} {value}"; if (p.write_line is Action <string> write_line) { write_line(line); } else { Log.Debug(line); } }
public TreeParams(TreeParams p, int diff = 0, bool is_not_last = false, bool add_line = false, Action <string> write_line = null) { this.write_line = write_line ?? p.write_line; this.indent = p.indent + diff; this.is_not_last_child = is_not_last; this.lines = p.lines; if (add_line) { if (lines.IsDefaultOrEmpty) { lines = ImmutableArray.Create(indent + 1); } else { lines = lines.Add(indent + 1); } } StringBuilder sb = new StringBuilder(p.indent_str); while (sb.Length < indent) { sb.Append(' '); } if (!lines.IsDefaultOrEmpty) { foreach (int i in lines) { if (i < indent) { sb [i] = '|'; } } } indent_str = sb.ToString(); }
private Attempt<TreeNodeCollection> TryLoadFromLegacyTree(ApplicationTree appTree, string id, FormDataCollection formCollection) { //This is how the legacy trees worked.... var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias); if (treeDef == null) { return new Attempt<TreeNodeCollection>(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias)); } var bTree = treeDef.CreateInstance(); var treeParams = new TreeParams(); //we currently only support an integer id or a string id, we'll refactor how this works //later but we'll get this working first int startId; if (int.TryParse(id, out startId)) { treeParams.StartNodeID = startId; } else { treeParams.NodeKey = id; } var xTree = new XmlTree(); bTree.SetTreeParameters(treeParams); bTree.Render(ref xTree); return new Attempt<TreeNodeCollection>(true, LegacyTreeDataAdapter.ConvertFromLegacy(xTree)); }
protected virtual void _printSelf(TreeParams p) { _printLine(p, $"{_getBranchSymbol (is_last: !p.is_not_last_child)}── {GetTypeName ()}"); }
public void Print(TreeParams p = default) { _printSelf(p); _printChildren(p, _getChildren()); }