/// <summary> /// Form the initial population from all the genres and albums that can be reached from the specified initial set of genres /// </summary> /// <param name="startingGenres"></param> public void AddAllReachableGenres(IEnumerable <string> startingGenres) { List <string> newGenres = null; List <Album> newAlbums = null; int expansionCount = 0; // Start with the initial genres List <string> currentGenres = startingGenres.ToList(); do { // Are there any genres that have not been seen before newGenres = currentGenres.Where(gen => GenresAlreadyIncluded.Add(gen) == true).ToList(); if (newGenres.Count > 0) { // Are there any albums associated with these genres that have not been seen before newAlbums = GetAlbumsFromGenres(newGenres); if (newAlbums.Count > 0) { // Get all the genres associated with these new albums currentGenres = newAlbums.SelectMany(alb => alb.Genre.Split(';')).ToList(); } } }while ((newGenres.Count > 0) && (newAlbums.Count > 0) && ((FastSpreadLimit == 0) || (++expansionCount < FastSpreadLimit))); // Unload the genres and albums from the HashSets and use to generate the first population Populations.Add(new Population(GenrePopulations.CreatePopulation(Id, Populations.Count, GenresAlreadyIncluded.ToList()), GenresAlreadyIncluded.ToList(), Albums.AlbumCollection.Where(alb => AlbumsAlreadyIncluded.Contains(alb.Id)))); }
/// <summary> /// Add the genres and their associated albums either to the next or a new population /// </summary> /// <param name="populationIndex"></param> /// <param name="genres"></param> public void AddToPopulation(int populationIndex, IEnumerable <string> genres) { // Make sure that there are some genres and albums that have not been seen before // Use a List here as having the GenresAlreadyIncluded modifier in the .where seems to cause problems with Linq lazy evaluation List <string> newGenres = genres.Where(gen => GenresAlreadyIncluded.Add(gen) == true).ToList(); if (newGenres.Count > 0) { // Are there any albums associated with these genres that have not been seen before List <Album> newAlbums = GetAlbumsFromGenres(newGenres); if (newAlbums.Count > 0) { // Add these entries to the next population to the one just used. If the one just used was the last one then create a new population if (populationIndex == (Populations.Count - 1)) { // A new population is required Populations.Add(new Population(GenrePopulations.CreatePopulation(Id, Populations.Count, newGenres), newGenres, newAlbums)); } else { // Add the genres and albums to the existing Population Populations[populationIndex + 1].Add(newGenres, newAlbums); } } } }
/// <summary> /// Read all the managed collections and then tell any registered listeners /// </summary> private static async void ReadManagedCollections() { await Songs.GetDataAsync(); await Albums.GetDataAsync(); await Sources.GetDataAsync(); await Artists.GetDataAsync(); await ArtistAlbums.GetDataAsync(); await Libraries.GetDataAsync(); await Playback.GetDataAsync(); await Playlists.GetDataAsync(); await Autoplays.GetDataAsync(); await Tags.GetDataAsync(); await TaggedAlbums.GetDataAsync(); await GenrePopulations.GetDataAsync(); // Carry out some one-off data linking await PopulateArtistsAsync(); await FilterManagementController.FormGenreTagsAsync(); DataAvailable = true; new StorageDataAvailableMessage().Send(); }
/// <summary> /// Clear the Population and SeedGenres entries /// </summary> public void Clear() { foreach (Population population in Populations) { GenrePopulations.RemovePopulation(population.SeedPopulation); } if (SeedGenres != null) { GenrePopulations.RemovePopulation(SeedGenres); SeedGenres = null; } Populations.Clear(); GenresAlreadyIncluded.Clear(); AlbumsAlreadyIncluded.Clear(); }
/// <summary> /// Generate a new GenrePopulation to contain the seed genres and add it to the GenrePopulation collection /// </summary> /// <param name="genres"></param> public void SaveSeedGenres(IEnumerable <string> genres) => SeedGenres = GenrePopulations.CreatePopulation(Id, -1, genres);