/// <summary> /// Add a node to the tree following initial build /// </summary> /// <param name="node"></param> public static void AddNode(MetaTreeNode node) { if (MetaTreeFactory == null) { DebugMx.DataException("MetaTreeFactory instance is not defined"); } if (Nodes == null) { DebugMx.DataException("Nodes dictionary is null"); } if (node == null) { DebugMx.DataException("Node parameter is null"); } if (Lex.IsNullOrEmpty(node.Name)) { DebugMx.DataException("Node name is not defined"); } if (Nodes.ContainsKey(node.Name.ToUpper())) { return; } Nodes.Add(node.Name.ToUpper(), node); return; }
/// <summary> /// Recursively add node children to hash of UserObject tables in contents tree /// </summary> /// <param name="parent"></param> static void AddNodeChildrenToUserObjectTables( MetaTreeNode parent) { foreach (MetaTreeNode mtn in parent.Nodes) { if (mtn.IsFolderType) { AddNodeChildrenToUserObjectTables(mtn); // go recursive } else if (mtn.Type == MetaTreeNodeType.Annotation || mtn.Type == MetaTreeNodeType.CalcField) { UserObjectTables[mtn.Target.Trim().ToUpper()] = null; } } }
/// <summary> /// Recursively update nodes dictionary /// </summary> /// <param name="nodes"></param> /// <param name="node"></param> public static void UpdateNodesDictForSubtree( Dictionary <string, MetaTreeNode> nodes, MetaTreeNode node) { //if (node.Label == "Libraries") node = node; // debug if (node.IsUserObjectType) { return; // don't include user objects } //if (!nodes.ContainsKey(node.Name)) // (no, should always update since may be new version with old name nodes[node.Name] = node; foreach (MetaTreeNode child in node.Nodes) { UpdateNodesDictForSubtree(nodes, child); } }
/// <summary> /// Lookup a MetaTreeNode by name /// </summary> /// <param name="name"></param> /// <returns></returns> public static MetaTreeNode GetNode( string name) { MetaTreeNode mtn; if (Nodes == null || name == null) { return(null); } name = name.Trim().ToUpper(); if (!Nodes.ContainsKey(name)) { return(null); } mtn = Nodes[name]; // public static string GetStats() if (Math.Abs(1) == 2) // disabled { Dictionary <MetaTreeNodeType, int> nodeStats = new Dictionary <MetaTreeNodeType, int>(); foreach (KeyValuePair <string, MetaTreeNode> kv in Nodes) { string mtnName = kv.Key; if (Lex.StartsWith(mtnName, "HIDDEN")) { continue; } MetaTreeNode mtn2 = kv.Value; if (!nodeStats.ContainsKey(mtn2.Type)) { nodeStats[mtn2.Type] = 0; } nodeStats[mtn2.Type]++; } nodeStats = nodeStats; } return(mtn); }
/// <summary> /// Get a list of the parent nodes for the specified node /// </summary> /// <param name="mtn"></param> /// <returns></returns> public static List <MetaTreeNode> GetParents( MetaTreeNode mtn) { List <MetaTreeNode> parents = new List <MetaTreeNode>(); if (Nodes == null) { return(parents); } foreach (MetaTreeNode parent in Nodes.Values) { foreach (MetaTreeNode child in parent.Nodes) { if (Lex.Eq(mtn.Name, child.Name)) // compare on name not address { parents.Add(parent); } } } return(parents); }