private Album GetRootImpl() { var rootAlbum = new NaiveAlbum() { Id = Album.RootAlbumId, Name = Album.RootAlbumId, PhysicalDir = RootPath, }; int dirsTraversed = 0; int contentItemsTraversed = 0; _log.Info(x => x("Populating items recursively in {0}", RootPath)); rootAlbum.Items = GetItemsRecoursive(rootAlbum, RootPath, ref dirsTraversed, ref contentItemsTraversed); _log.Info(x => x("Traversed {0} directories and {1} content files", dirsTraversed, contentItemsTraversed)); return rootAlbum; }
private IEnumerable<AlbumItem> GetItemsRecoursive(Album currentAlbum, string currentDir, ref int dirsTraversed, ref int contentItemsTraversed) { dirsTraversed += 1; var result = new List<AlbumItem>(); string[] subDirs = System.IO.Directory.GetDirectories(currentDir); foreach (var subDir in subDirs) { var dirInfo = new System.IO.DirectoryInfo(subDir); var subAlbum = new NaiveAlbum() { Id = dirInfo.Name, Name = dirInfo.Name, ParentAlbum = currentAlbum, PhysicalDir = subDir, }; subAlbum.Items = GetItemsRecoursive(subAlbum, subDir, ref dirsTraversed, ref contentItemsTraversed); result.Add(subAlbum); } foreach(var photo in GetPhotosStraghtIn(currentDir)) { photo.ParentAlbum = currentAlbum; contentItemsTraversed += 1; result.Add(photo); } return result; }