private IList <VsixFileNode> CreateFileTree(IEnumerable <KeyValuePair <string, PackagePart> > parts, VsixFileNode parent) { List <VsixFileNode> list = new List <VsixFileNode>(); while (Enumerable.Count <KeyValuePair <string, PackagePart> >(parts) > 0) { string[] strArray = Enumerable.First <KeyValuePair <string, PackagePart> >(parts).Key.Split(new char[1] { '/' }, 2, StringSplitOptions.RemoveEmptyEntries); if (strArray.Length > 1) { string topNodeDirectory = strArray[0] + "/"; IEnumerable <KeyValuePair <string, PackagePart> > source = Enumerable.Where <KeyValuePair <string, PackagePart> >(parts, (Func <KeyValuePair <string, PackagePart>, bool>)(x => x.Key.StartsWith(topNodeDirectory))); SortedList <string, PackagePart> sortedList = new SortedList <string, PackagePart>(); foreach (KeyValuePair <string, PackagePart> keyValuePair in source) { sortedList.Add(keyValuePair.Key.Substring(topNodeDirectory.Length), keyValuePair.Value); } VsixFolderNode vsixFolderNode = new VsixFolderNode(strArray[0], parent); vsixFolderNode.Nodes = new SortedObservableCollection <VsixFileNode>((IEnumerable <VsixFileNode>) this.CreateFileTree((IEnumerable <KeyValuePair <string, PackagePart> >)sortedList, (VsixFileNode)vsixFolderNode)); list.Add((VsixFileNode)vsixFolderNode); parts = Enumerable.Skip <KeyValuePair <string, PackagePart> >(parts, Enumerable.Count <KeyValuePair <string, PackagePart> >(source)); } else { PackagePart part = Enumerable.First <KeyValuePair <string, PackagePart> >(parts).Value; list.Add(this.CreateFileNodeFromPart(part, parent)); parts = Enumerable.Skip <KeyValuePair <string, PackagePart> >(parts, 1); } } return((IList <VsixFileNode>)list); }
public void AddDirectory(VsixFileNode targetNode, string directoryPath) { VsixFolderNode vsixFolderNode = new VsixFolderNode(Path.GetFileName(directoryPath), targetNode); targetNode.Nodes.Add((VsixFileNode)vsixFolderNode); foreach (string directoryPath1 in Directory.GetDirectories(directoryPath)) { this.AddDirectory((VsixFileNode)vsixFolderNode, directoryPath1); } foreach (string filePath in Directory.GetFiles(directoryPath)) { this.AddFile((VsixFileNode)vsixFolderNode, filePath); } }