private async Task GetArtistsAsync(ArtistOrder artistOrder) { try { // Get all artists from the database IList <Artist> artists = await this.artistRepository.GetArtistsAsync(artistOrder); // Create new ObservableCollection ObservableCollection <ArtistViewModel> artistViewModels = new ObservableCollection <ArtistViewModel>(); await Task.Run(() => { List <ArtistViewModel> tempArtistViewModels = new List <ArtistViewModel>(); // Workaround to make sure the "#" GroupHeader is shown at the top of the list tempArtistViewModels.AddRange(artists.Select(art => new ArtistViewModel { Artist = art, IsHeader = false }).Where(avm => avm.Header.Equals("#"))); tempArtistViewModels.AddRange(artists.Select(art => new ArtistViewModel { Artist = art, IsHeader = false }).Where(avm => !avm.Header.Equals("#"))); foreach (ArtistViewModel avm in tempArtistViewModels) { artistViewModels.Add(avm); } }); // Unbind to improve UI performance if (this.ArtistsCvs != null) { this.ArtistsCvs.Filter -= new FilterEventHandler(ArtistsCvs_Filter); } this.Artists = null; this.ArtistsCvs = null; // Populate ObservableCollection this.Artists = new ObservableCollection <ISemanticZoomable>(artistViewModels); } catch (Exception ex) { LogClient.Error("An error occured while getting Artists. Exception: {0}", ex.Message); // Failed getting Artists. Create empty ObservableCollection. this.Artists = new ObservableCollection <ISemanticZoomable>(); } // Populate CollectionViewSource this.ArtistsCvs = new CollectionViewSource { Source = this.Artists }; this.ArtistsCvs.Filter += new FilterEventHandler(ArtistsCvs_Filter); // Update count this.ArtistsCount = this.ArtistsCvs.View.Cast <ISemanticZoomable>().Count(); // Update Semantic Zoom Headers this.UpdateSemanticZoomHeaders(); }
protected void UpdateArtistOrderText(ArtistOrder artistOrder) { switch (artistOrder) { case ArtistOrder.All: this.artistOrderText = ResourceUtils.GetStringResource("Language_All"); break; case ArtistOrder.Track: this.artistOrderText = ResourceUtils.GetStringResource("Language_Song"); break; case ArtistOrder.Album: this.artistOrderText = ResourceUtils.GetStringResource("Language_Album"); break; default: // Cannot happen, but just in case. this.artistOrderText = ResourceUtils.GetStringResource("Language_All"); break; } OnPropertyChanged(() => this.ArtistOrderText); }
private void UpdateArtistOrderText(ArtistOrder artistOrder) { switch (artistOrder) { case ArtistOrder.All: this.artistOrderText = ResourceUtils.GetString("Language_All_Artists"); break; case ArtistOrder.Track: this.artistOrderText = ResourceUtils.GetString("Language_Song_Artists"); break; case ArtistOrder.Album: this.artistOrderText = ResourceUtils.GetString("Language_Album_Artists"); break; default: // Cannot happen, but just in case. this.artistOrderText = ResourceUtils.GetString("Language_All_Artists"); break; } RaisePropertyChanged(nameof(this.ArtistOrderText)); }
public override Task <List <Artist> > GetArtistsAsync(ArtistOrder artistOrder) { throw new NotImplementedException(); }
public async Task <List <Artist> > GetArtistsAsync(ArtistOrder artistOrder) { var artists = new List <Artist>(); await Task.Run(() => { try { using (var conn = this.Factory.GetConnection()) { try { var trackArtists = new List <Artist>(); var albumArtists = new List <string>(); // Get the Track Artists trackArtists = conn.Query <Artist>("SELECT DISTINCT art.ArtistID, " + $"REPLACE(art.ArtistName,'{Defaults.UnknownArtistText}','{this.info.UnknownArtistText}') ArtistName " + "FROM Artist art " + "INNER JOIN Track tra ON art.ArtistID=tra.ArtistID " + "INNER JOIN FolderTrack ft ON ft.TrackID=tra.TrackID " + "INNER JOIN Folder fol ON ft.FolderID=fol.FolderID AND ft.TrackID=tra.TrackID " + "WHERE fol.ShowInCollection=1"); // Get the Album Artists var albums = conn.Query <Album>("SELECT DISTINCT alb.AlbumID, " + $"REPLACE(alb.AlbumTitle,'{Defaults.UnknownAlbumText}','{this.info.UnknownAlbumText}') AlbumTitle, " + $"REPLACE(alb.AlbumArtist,'{Defaults.UnknownArtistText}','{this.info.UnknownArtistText}') AlbumArtist, " + "alb.Year, alb.ArtworkID, alb.DateLastSynced, alb.DateAdded FROM Album alb " + "INNER JOIN Track tra ON alb.AlbumID=tra.AlbumID " + "INNER JOIN FolderTrack ft ON ft.TrackID=tra.TrackID " + "INNER JOIN Folder fol ON ft.FolderID=fol.FolderID AND ft.TrackID=tra.TrackID " + "INNER JOIN Artist art ON tra.ArtistID=art.ArtistID " + "WHERE tra.AlbumID=alb.AlbumID AND tra.ArtistID=tra.ArtistID AND fol.ShowInCollection=1"); albumArtists = albums.Select((a) => a.AlbumArtist).ToList(); if (artistOrder == ArtistOrder.All | artistOrder == ArtistOrder.Track) { foreach (Artist trackArtist in trackArtists) { artists.Add(trackArtist); } } if (artistOrder == ArtistOrder.All | artistOrder == ArtistOrder.Album) { foreach (string albumArtist in albumArtists) { if (!artists.Select((art) => art.ArtistName).Contains(albumArtist)) { artists.Add(new Artist { ArtistName = albumArtist }); } } } // Orders the artists artists = artists.OrderBy((a) => DatabaseUtils.GetSortableString(a.ArtistName, true)).ToList(); } catch (Exception ex) { LogClient.Error("Could not get the Artists. Exception: {0}", ex.Message); } } } catch (Exception ex) { LogClient.Error("Could not connect to the database. Exception: {0}", ex.Message); } }); return(artists); }
public abstract Task <List <Artist> > GetArtistsAsync(ArtistOrder artistOrder);