public static int Do(bool UseMultiThreading) { string[] ArtistDirs = Directory.GetDirectories(MusicsInfo.GetMusicPath()); int NumberofMusics = 0; TagLib.File file; Console.WriteLine(); ServerMusics.Clear(); var indexationStopWatch = new Stopwatch(); indexationStopWatch.Start(); long startMemory = GC.GetTotalMemory(false); foreach (var n in ArtistDirs) { Author CurrentArtist = new Author(Path.GetFileName(n), n); GetArtistImage(n, CurrentArtist); string[] AlbumOfArtist = Directory.GetDirectories(n); Console.WriteLine(n); foreach (var a in AlbumOfArtist) { if (!Path.GetFileNameWithoutExtension(a).Contains("-ignore")) { var CurrentAlbum = new Album(CurrentArtist, Path.GetFileName(a), a); var musics = new ConcurrentBag <Music>(); CurrentArtist.Albums.Add(CurrentAlbum); Console.Write($" {CurrentAlbum.Name} ["); if (UseMultiThreading) { Parallel.ForEach(Directory.GetFiles(a), m => { file = AddMusicToindexation(m, ref NumberofMusics, CurrentArtist, CurrentAlbum, musics); }); } else { foreach (var m in Directory.GetFiles(a)) { file = AddMusicToindexation(m, ref NumberofMusics, CurrentArtist, CurrentAlbum, musics); } } CurrentAlbum.Musics = musics.OrderBy(x => x.N).ToList(); CurrentAlbum.Image = musics.First().Image; Console.WriteLine("]"); } } ServerMusics.Add(CurrentArtist); } indexationStopWatch.Stop(); MyServer.Log.Debug("Indexation finished in " + indexationStopWatch.ElapsedMilliseconds + " Ms, with " + ((GC.GetTotalMemory(false) - startMemory) / 1000000) + " Mo of memory"); return(NumberofMusics); }
public static void InitRepository() { MusicsInfo.SetupMusics(); string musicsDBPath = MusicsInfo.GetMusicPath(); if (!Directory.Exists(musicsDBPath)) { Directory.CreateDirectory(musicsDBPath); } Console.WriteLine("Directory created."); }