private void ExtractChildren(XmlNode parentXml, TreeNode parent)
 {
     IEnumerable<Tuple<XmlNode, TreeNode>> children = from childXml in parentXml.ChildNodes.OfType<XmlNode>()
                                                      where
                                                          childXml.Name == "Node" &&
                                                          childXml.Attributes["Id"] != null
                                                      let childNode =
                                                          _nodeManager.GetNodeById(
                                                              childXml.Attributes["Id"].Value)
                                                      let childTreeNode = parent.AddChild(childNode)
                                                      select Tuple.Create(childXml, childTreeNode);
     Parallel.ForEach(children, child => ExtractChildren(child.Item1, child.Item2));
 }
        public KnowledgeTreeManager(string xmlFilePath, INodeManager nodeManager)
        {
            XmlFilePath = xmlFilePath;
            _nodeManager = nodeManager;

            Root = new TreeNode(null);
            try
            {
                ReloadTree();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Debug.WriteLine(e.StackTrace);

                // Simply reset the Root object if load failed.
                ResetTree();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 给树节点增加子节点<paramref name="node"/>。
 /// </summary>
 public TreeNode AddChild(Node node)
 {
     var child = new TreeNode(node, this);
     _children.Add(child);
     return child;
 }
Esempio n. 4
0
 /// <summary>
 /// 构造一个<see cref="TreeNode"/>,
 /// 其对应节点为<paramref name="node"/>,父节点为<paramref name="parent"/>。
 /// </summary>
 public TreeNode(Node node, TreeNode parent = null)
 {
     _node = node;
     Parent = parent;
 }
 private static void WriteTreeNode(TreeNode node, XmlWriter writer)
 {
     writer.WriteStartElement("Node");
     writer.WriteAttributeString("Id", node.Id);
     foreach (TreeNode child in node.Children)
         WriteTreeNode(child, writer);
     writer.WriteEndElement();
 }
 public void ResetTree()
 {
     Root = new TreeNode(null);
 }
Esempio n. 7
0
 public TreeNodeViewModel(TreeNode treeNode, TreeViewItemViewModel parent) : base(parent)
 {
     _treeNode = treeNode;
     LoadChildren();
 }
Esempio n. 8
0
 public void AddChild(TreeNode treeNode)
 {
     ChildrenSource.Add(new TreeNodeViewModel(treeNode, this));
 }
Esempio n. 9
0
 public TreeNodeViewModel(TreeNode treeNode) : this(treeNode, null)
 {
 }