private IStreamTreeNode AddPath(string[] path, IStreamMetadata streamMetadata, int depth) { var child = this.InternalChildren.FirstOrDefault(p => p.Name == path[depth - 1]) as StreamTreeNode; if (child == null) { child = new StreamTreeNode(this.Partition) { Path = string.Join(".", path.Take(depth)), Name = path[depth - 1], }; this.InternalChildren.Add(child); } // if we are at the last segement of the path name then we are at the leaf node if (path.Length == depth) { Debug.Assert(child.StreamMetadata == null, "There should never be two leaf nodes"); child.StreamMetadata = streamMetadata; child.TypeName = streamMetadata.TypeName; child.StreamName = streamMetadata.Name; return(child); } // we are not at the last segment so recurse in return(child.AddPath(path, streamMetadata, depth + 1)); }
/// <summary> /// Initializes a new instance of the <see cref="DerivedMemberStreamTreeNode"/> class. /// </summary> /// <param name="parent">The parent stream tree node.</param> /// <param name="memberInfo">The member information.</param> /// <param name="memberType">The type of the member.</param> /// <param name="generateNullable">Indicates whether this is an auto-generated nullable expansion.</param> public DerivedMemberStreamTreeNode(StreamTreeNode parent, MemberInfo memberInfo, Type memberType, bool generateNullable) : base( parent.PartitionViewModel, $"{parent.Path}.{memberInfo.Name}", memberInfo.Name, parent.SourceStreamMetadata) { this.DataTypeName = generateNullable ? typeof(Nullable <>).MakeGenericType(memberType).AssemblyQualifiedName : memberType.AssemblyQualifiedName; this.MemberPath = parent is DerivedMemberStreamTreeNode expandedMemberParent ? $"{expandedMemberParent.MemberPath}.{memberInfo.Name}" : memberInfo.Name; this.IsAutoGeneratedNullableMember = generateNullable; }
/// <summary> /// Recursively searches for a stream with a given name, and if it is found selects it and ensures all parent nodes are expanded. /// </summary> /// <param name="streamName">The name of the stream to find.</param> /// <returns>A stream tree node, or null if the stream was not found.</returns> public StreamTreeNode SelectNode(string streamName) { if (this.StreamName == streamName) { this.IsTreeNodeSelected = true; return(this); } foreach (StreamTreeNode streamTreeNode in this.Children) { StreamTreeNode foundStream = streamTreeNode.SelectNode(streamName); if (foundStream != null) { this.IsTreeNodeExpanded = true; return(foundStream); } } return(null); }