Beispiel #1
0
        private void CreateHierarchy(SlnProject project)
        {
            FileInfo      fileInfo      = new FileInfo(project.FullPath);
            DirectoryInfo directoryInfo = fileInfo.Directory;

            if (_pathToSlnFolderMap.TryGetValue(directoryInfo.FullName, out SlnFolder childFolder))
            {
                childFolder.Projects.Add(project);
                return;
            }
            childFolder = new SlnFolder(directoryInfo.FullName);
            childFolder.Projects.Add(project);
            _pathToSlnFolderMap.Add(directoryInfo.FullName, childFolder);
            directoryInfo = directoryInfo.Parent;
            while (!string.Equals(directoryInfo.FullName, _rootFolder.FullPath, StringComparison.OrdinalIgnoreCase))
            {
                if (!_pathToSlnFolderMap.TryGetValue(directoryInfo.FullName, out SlnFolder folder1))
                {
                    folder1 = new SlnFolder(directoryInfo.FullName);
                    _pathToSlnFolderMap.Add(directoryInfo.FullName, folder1);
                }
                childFolder.Parent = folder1;
                if (!folder1.Folders.Contains(childFolder))
                {
                    folder1.Folders.Add(childFolder);
                }
                directoryInfo = directoryInfo.Parent;
                childFolder   = folder1;
            }
            if (!_rootFolder.Folders.Contains(childFolder))
            {
                _rootFolder.Folders.Add(childFolder);
                childFolder.Parent = _rootFolder;
            }
        }
Beispiel #2
0
 private IEnumerable <SlnFolder> EnumerateFolders(SlnFolder folder)
 {
     foreach (SlnFolder child in folder.Folders)
     {
         foreach (SlnFolder enumerateFolder in EnumerateFolders(child))
         {
             yield return(enumerateFolder);
         }
     }
     yield return(folder);
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SlnHierarchy" /> class.
 /// </summary>
 /// <param name="projects">The set of projects that should be placed in the hierarchy.</param>
 /// <param name="collapseFolders">An optional value indicating whether or not folders containing a single item should be collapsed into their parent folder.</param>
 public SlnHierarchy(IReadOnlyList <SlnProject> projects, bool collapseFolders = false)
 {
     _rootFolder = GetRootFolder(projects);
     foreach (SlnProject project in projects.Where(i => !i.IsMainProject))
     {
         CreateHierarchy(project);
     }
     if (collapseFolders)
     {
         CollapseFolders(_rootFolder.Folders);
     }
 }
Beispiel #4
0
 private void CollapseFolders(IReadOnlyCollection <SlnFolder> folders)
 {
     foreach (SlnFolder folder in folders)
     {
         CollapseFolders(folder.Folders);
     }
     foreach (SlnFolder folderWithSingleChild in folders.Where(i => i.Folders.Count == 1))
     {
         SlnFolder child = folderWithSingleChild.Folders.First();
         folderWithSingleChild.Name = $"{folderWithSingleChild.Name}-{child.Name}";
         folderWithSingleChild.Projects.AddRange(child.Projects);
         folderWithSingleChild.Folders.Clear();
     }
 }