/// <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> /// 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> /// Constructor. /// </summary> /// <param name="data">The navigation related data.</param> public NavigateTreeNode(NavigationData data) { this.data = data; this.children = new List<NavigateTreeNode>(); }
/// <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> /// Constructor. /// </summary> /// <param name="data">The navigation related data.</param> public NavigateTreeNode(NavigationData data) { this.data = data; this.children = new List <NavigateTreeNode>(); }