/// <summary> /// Add the child to the navigation tree node. /// </summary> /// <param name="child">The child node.</param> public void AddChild(NavigateTreeNode child) { if (null != child) { this.children.Add(child); } }
/// <summary> /// Parse to a navigation tree node using the entity-type short name. /// </summary> /// <param name="entityTypeShortName"></param> /// <returns></returns> public static NavigateTreeNode Parse(string entityTypeShortName) { NavigateTreeNode.Path = string.Empty; // Construct the root node. var navigData = new NavigationData("root", entityTypeShortName, string.Empty, string.Empty, false, string.Empty, false); var rootNode = new NavigateTreeNode(navigData); rootNode.parent = null; return(Construct(rootNode)); }
/// <summary> /// Construct all the child nodes for the current navigation tree node. /// </summary> /// <param name="node">The current navigation tree node.</param> /// <returns>Returns the current node with all its child nodes.</returns> private static NavigateTreeNode Construct(NavigateTreeNode node) { if (null == node || !node.data.TypeShortName.IsSpecifiedEntityTypeShortNameExist()) { return(node); } NavigateTreeNode.Path += node.data.Name != "root" ? "/" + node.data.Name + "/" + node.data.TypeFullName : string.Empty; var navigationPropertyElems = MetadataHelper.GetNavigProperties(node.data.TypeShortName, NavigateTreeNode.Path); foreach (var navigationPropertyElem in navigationPropertyElems) { if (null != navigationPropertyElem.Item1.Attribute("Name") && null != navigationPropertyElem.Item1.Attribute("Type")) { string navigationPropName = navigationPropertyElem.Item1.GetAttributeValue("Name"); string entityTypeFullName = navigationPropertyElem.Item1.GetAttributeValue("Type").RemoveCollectionFlag(); string entityTypeShortName = entityTypeFullName.GetLastSegment(); string path = navigationPropertyElem.Item2; bool isCollection = navigationPropertyElem.Item1.GetAttributeValue("Type").StartsWith("Collection("); string partner = null != navigationPropertyElem.Item1.Attribute("Partner") ? navigationPropertyElem.Item1.GetAttributeValue("Partner") : string.Empty; bool containsTarget = null != navigationPropertyElem.Item1.Attribute("ContainsTarget") ? Convert.ToBoolean(navigationPropertyElem.Item1.GetAttributeValue("ContainsTarget")) : false; var data = new NavigationData(navigationPropName, entityTypeShortName, entityTypeFullName, path, isCollection, partner, containsTarget); var childNode = new NavigateTreeNode(data); childNode.parent = node; if (childNode.data.ContainsTarget && !IsEntityTypeTraverse(entityTypeShortName, node)) { node.AddChild(NavigateTreeNode.Construct(childNode)); } else { node.AddChild(childNode); } } } return(node); }
/// <summary> /// Verify wether the entity-type short name has been exist on the navigation tree node or its child nodes. /// </summary> /// <param name="entityTypeShortName">The entity-type short name.</param> /// <param name="node">The node of the navigation tree.</param> /// <returns>Returns the verification result.</returns> private static bool IsEntityTypeTraverse(string entityTypeShortName, NavigateTreeNode node) { if (!entityTypeShortName.IsSpecifiedEntityTypeShortNameExist() || null == node) { return(false); } do { if (node.data.TypeShortName == entityTypeShortName) { return(true); } node = node.parent; }while (null != node); return(false); }
/// <summary> /// Parse to a navigation tree node using the entity-type short name. /// </summary> /// <param name="entityTypeShortName"></param> /// <returns></returns> public static NavigateTreeNode Parse(string entityTypeShortName) { NavigateTreeNode.Path = string.Empty; // Construct the root node. var navigData = new NavigationData("root", entityTypeShortName, string.Empty, string.Empty, false, string.Empty, false); var rootNode = new NavigateTreeNode(navigData); rootNode.parent = null; return Construct(rootNode); }
/// <summary> /// Verify wether the entity-type short name has been exist on the navigation tree node or its child nodes. /// </summary> /// <param name="entityTypeShortName">The entity-type short name.</param> /// <param name="node">The node of the navigation tree.</param> /// <returns>Returns the verification result.</returns> private static bool IsEntityTypeTraverse(string entityTypeShortName, NavigateTreeNode node) { if (!entityTypeShortName.IsSpecifiedEntityTypeShortNameExist() || null == node) { return false; } do { if (node.data.TypeShortName == entityTypeShortName) { return true; } node = node.parent; } while (null != node); return false; }
/// <summary> /// Construct all the child nodes for the current navigation tree node. /// </summary> /// <param name="node">The current navigation tree node.</param> /// <returns>Returns the current node with all its child nodes.</returns> private static NavigateTreeNode Construct(NavigateTreeNode node) { if (null == node || !node.data.TypeShortName.IsSpecifiedEntityTypeShortNameExist()) { return node; } NavigateTreeNode.Path += node.data.Name != "root" ? "/" + node.data.Name + "/" + node.data.TypeFullName : string.Empty; var navigationPropertyElems = MetadataHelper.GetNavigProperties(node.data.TypeShortName, NavigateTreeNode.Path); foreach (var navigationPropertyElem in navigationPropertyElems) { if (null != navigationPropertyElem.Item1.Attribute("Name") && null != navigationPropertyElem.Item1.Attribute("Type")) { string navigationPropName = navigationPropertyElem.Item1.GetAttributeValue("Name"); string entityTypeFullName = navigationPropertyElem.Item1.GetAttributeValue("Type").RemoveCollectionFlag(); string entityTypeShortName = entityTypeFullName.GetLastSegment(); string path = navigationPropertyElem.Item2; bool isCollection = navigationPropertyElem.Item1.GetAttributeValue("Type").StartsWith("Collection("); string partner = null != navigationPropertyElem.Item1.Attribute("Partner") ? navigationPropertyElem.Item1.GetAttributeValue("Partner") : string.Empty; bool containsTarget = null != navigationPropertyElem.Item1.Attribute("ContainsTarget") ? Convert.ToBoolean(navigationPropertyElem.Item1.GetAttributeValue("ContainsTarget")) : false; var data = new NavigationData(navigationPropName, entityTypeShortName, entityTypeFullName, path, isCollection, partner, containsTarget); var childNode = new NavigateTreeNode(data); childNode.parent = node; if (childNode.data.ContainsTarget && !IsEntityTypeTraverse(entityTypeShortName, node)) { node.AddChild(NavigateTreeNode.Construct(childNode)); } else { node.AddChild(childNode); } } } return node; }
/// <summary> /// Add the child to the navigation tree node. /// </summary> /// <param name="child">The child node.</param> public void AddChild(NavigateTreeNode child) { if (null != child) { this.children.Add(child); } }