void AddChilds(XmlWriter xmlwr, BaseNode parentNode, FlagType flagMask, bool onlyChanges) { foreach (BaseNode child in parentNode.Children) { if (onlyChanges && !child.AnyChanges()) { continue; } xmlwr.WriteStartElement(child.Name); BaseNode childNode = child; if (resolveMirrors && (child.GetType() == typeof(MirrorNode))) { MirrorNode mirror = (child as MirrorNode); if (mirror.IsLinked()) { childNode = mirror.MirrorSource; } } AddNodeAttributes(xmlwr, childNode, onlyChanges); if (childNode.Children.Count > 0) { AddChilds(xmlwr, childNode, flagMask, onlyChanges); } xmlwr.WriteEndElement(); } }
public static BaseNode CreateNode(String nodeType, String nodeName) { BaseNode newNode = null; NodeTypes eNodeType = NodeTypes.nodeNode; if (GetNodeType(nodeType, ref eNodeType)) { switch (eNodeType) { case NodeTypes.nodeNode: newNode = new BaseNode(nodeName); break; case NodeTypes.mirrorNode: newNode = new MirrorNode(nodeName); break; case NodeTypes.boolNode: newNode = new BoolNode(nodeName); break; case NodeTypes.uint16Node: newNode = new UInt16Node(nodeName); break; case NodeTypes.uint32Node: newNode = new UInt32Node(nodeName); break; case NodeTypes.int32Node: newNode = new Int32Node(nodeName); break; case NodeTypes.int64Node: newNode = new Int64Node(nodeName); break; case NodeTypes.floatNode: newNode = new FloatNode(nodeName); break; case NodeTypes.doubleNode: newNode = new DoubleNode(nodeName); break; case NodeTypes.pos3D_32fNode: newNode = new Pos3D_32f_Node(nodeName); break; case NodeTypes.stringNode: newNode = new StringNode(nodeName); break; default: break; } } return(newNode); }
public void AddMirror(MirrorNode mirror) { // Check if the mirror is already in the list. if (mirrors.Contains(mirror)) { return; } // Add mirror to list of mirrors. mirrors.Add(mirror); }
public bool LinkAllMirrors() { bool success = true; MirrorNode mirror = this as MirrorNode; if (mirror != null) // Check if this node is a mirror. { success &= mirror.LinkMirror(); } // Recursively try to link any mirrors. foreach (BaseNode child in children) { success &= child.LinkAllMirrors(); } return(success); }
private void AddChildrenToNodeTree(BaseNode parentNode, TreeNode tnode) { foreach (BaseNode childNode in parentNode.Children) { TreeNode childTNode = tnode.Nodes.Add(childNode.Name); BaseNode child = childNode; if (childNode is MirrorNode) { MirrorNode mirror = childNode as MirrorNode; if (mirror.IsLinked()) { child = mirror.MirrorSource; } } childTNode.Tag = child; if (child.Children.Count > 0) { AddChildrenToNodeTree(child, childTNode); } } }
public void RemoveMirror(MirrorNode mirror) { mirrors.Remove(mirror); }
// The argument nodePath contains the relative or absolute path to the node to search for. // An absolute path is specified with a leading "/" eg. "/node1/node2/nodeToFind", in which case the function will begin the search from the root node. // The syntax of a relative path is "node2/nodeToFind" or "../node1/node2/nodeToFind" and the search is started from this node. // Return value: If the node is found a pointer to the requested node is returned, otherwise null is returned. private BaseNode FindNodeInternal(String nodePath, int strPos, bool allowPartialMatch, bool resolveMirrors) { if (resolveMirrors && (this.GetType() == typeof(MirrorNode))) { MirrorNode mirror = this as MirrorNode; if (mirror == null || mirror.MirrorSource == null) { // ToDo: Handle error. return(null); } return(mirror.MirrorSource.FindNodeInternal(nodePath, strPos, allowPartialMatch, resolveMirrors)); } if (nodePath == null) { return(null); } // Special case for an empty string - just return this. if (nodePath.Length <= strPos) { return(this); } // Special case if first character is a pathDelimiter we should start the search from the root node. if (strPos == 0 && nodePath[0] == pathDelimiter) { BaseNode node = GetRoot(); return(node.FindNodeInternal(nodePath, 1, allowPartialMatch, resolveMirrors)); } // Special case if first two characters are ".." - then return the parent if not null. if (nodePath[strPos] == '.' && strPos <= nodePath.Length && nodePath[strPos + 1] == '.' && ParentNode != null) { if (strPos + 2 == nodePath.Length) { return(ParentNode); } if (nodePath[strPos + 2] == pathDelimiter) { return(parentNode.FindNodeInternal(nodePath, strPos + 3, allowPartialMatch, resolveMirrors)); } } // Otherwise lookup (next) node name in nodePath. int sepPos = nodePath.IndexOf(pathDelimiter, strPos); if (sepPos == -1) { sepPos = nodePath.Length; } string nodeName = nodePath.Substring(strPos, sepPos - strPos); // Otherwise search children for at string match with next node. BaseNode partialMatchNode = null; foreach (BaseNode child in children) { if (allowPartialMatch) { if (child.name.StartsWith(nodeName)) { if (partialMatchNode != null) { // ambiguity - More than one child node have a partial match. return(null); } partialMatchNode = child; } } else { if (child.name.Equals(nodeName)) { return(child.FindNodeInternal(nodePath, sepPos + 1, allowPartialMatch, resolveMirrors)); } } } if (allowPartialMatch && partialMatchNode != null) { if (sepPos >= nodePath.Length) { if (resolveMirrors && (partialMatchNode.GetType() == typeof(MirrorNode))) { MirrorNode mirror = partialMatchNode as MirrorNode; if (mirror == null || mirror.MirrorSource == null) { // ToDo: Handle error. return(null); } return(mirror.MirrorSource); } return(partialMatchNode); } return(partialMatchNode.FindNodeInternal(nodePath, sepPos + 1, allowPartialMatch, resolveMirrors)); // (+1) It must have been a delimiter. Move one pos forward. } return(null); }