コード例 #1
0
ファイル: EntityUtils.cs プロジェクト: zaevi/Dopamine
        public static async Task <List <TrackViewModel> > OrderTracksAsync(IList <TrackViewModel> tracks, TrackOrder trackOrder)
        {
            var orderedTracks = new List <TrackViewModel>();

            await Task.Run(() =>
            {
                switch (trackOrder)
                {
                case TrackOrder.Alphabetical:
                    orderedTracks = tracks.OrderBy((t) => !string.IsNullOrEmpty(FormatUtils.GetSortableString(t.TrackTitle)) ? FormatUtils.GetSortableString(t.TrackTitle) : FormatUtils.GetSortableString(t.FileName)).ToList();
                    break;

                case TrackOrder.ByAlbum:
                    orderedTracks = tracks.OrderBy((t) => FormatUtils.GetSortableString(t.AlbumArtist)).ThenBy((t) => FormatUtils.GetSortableString(t.AlbumTitle)).ThenBy((t) => t.DiscNumber).ThenBy((t) => t.SortTrackNumber).ToList();
                    break;

                case TrackOrder.ByFileName:
                    orderedTracks = tracks.OrderBy((t) => FormatUtils.GetSortableString(t.FileName)).ToList();
                    break;

                case TrackOrder.ByRating:
                    orderedTracks = tracks.OrderByDescending((t) => t.Rating).ToList();
                    break;

                case TrackOrder.ReverseAlphabetical:
                    orderedTracks = tracks.OrderByDescending((t) => !string.IsNullOrEmpty(FormatUtils.GetSortableString(t.TrackTitle)) ? FormatUtils.GetSortableString(t.TrackTitle) : FormatUtils.GetSortableString(t.FileName)).ToList();
                    break;

                case TrackOrder.None:
                    orderedTracks = tracks.ToList();
                    break;

                default:
                    // By album
                    orderedTracks = tracks.OrderBy((t) => FormatUtils.GetSortableString(t.AlbumTitle)).ThenBy((t) => t.DiscNumber).ThenBy((t) => t.SortTrackNumber).ToList();
                    break;
                }
            });

            return(orderedTracks);
        }
コード例 #2
0
        public async Task <IList <AlbumViewModel> > OrderAlbumsAsync(IList <AlbumViewModel> albums, AlbumOrder albumOrder)
        {
            var orderedAlbums = new List <AlbumViewModel>();

            await Task.Run(() =>
            {
                switch (albumOrder)
                {
                case AlbumOrder.Alphabetical:
                    orderedAlbums = albums.OrderBy((a) => FormatUtils.GetSortableString(a.AlbumTitle)).ToList();
                    break;

                case AlbumOrder.ByDateAdded:
                    orderedAlbums = albums.OrderByDescending((a) => a.DateAdded).ToList();
                    break;

                case AlbumOrder.ByDateCreated:
                    orderedAlbums = albums.OrderByDescending((a) => a.DateFileCreated).ToList();
                    break;

                case AlbumOrder.ByAlbumArtist:
                    orderedAlbums = albums.OrderBy((a) => FormatUtils.GetSortableString(a.AlbumArtist, true)).ToList();
                    break;

                case AlbumOrder.ByYear:
                    orderedAlbums = albums.OrderByDescending((a) => a.SortYear).ToList();
                    break;

                default:
                    // Alphabetical
                    orderedAlbums = albums.OrderBy((a) => FormatUtils.GetSortableString(a.AlbumTitle)).ToList();
                    break;
                }

                foreach (AlbumViewModel alb in orderedAlbums)
                {
                    string mainHeader = alb.AlbumTitle;
                    string subHeader  = alb.AlbumArtist;

                    switch (albumOrder)
                    {
                    case AlbumOrder.ByAlbumArtist:
                        mainHeader = alb.AlbumArtist;
                        subHeader  = alb.AlbumTitle;
                        break;

                    case AlbumOrder.ByYear:
                        mainHeader = alb.Year;
                        subHeader  = alb.AlbumTitle;
                        break;

                    case AlbumOrder.Alphabetical:
                    case AlbumOrder.ByDateAdded:
                    case AlbumOrder.ByDateCreated:
                    default:
                        // Do nothing
                        break;
                    }

                    alb.MainHeader = mainHeader;
                    alb.SubHeader  = subHeader;
                }
            });

            return(orderedAlbums);
        }
コード例 #3
0
ファイル: CollectionService.cs プロジェクト: zaevi/Dopamine
        public async Task <IList <ArtistViewModel> > GetAllArtistsAsync()
        {
            IList <string> artists = await this.trackRepository.GetArtistsAsync();

            IList <ArtistViewModel> orderedArtists = (await this.GetUniqueArtistsAsync(artists)).OrderBy(a => FormatUtils.GetSortableString(a.ArtistName, true)).ToList();

            // Workaround to make sure the "#" GroupHeader is shown at the top of the list
            List <ArtistViewModel> tempArtistViewModels = new List <ArtistViewModel>();

            tempArtistViewModels.AddRange(orderedArtists.Where((avm) => avm.Header.Equals("#")));
            tempArtistViewModels.AddRange(orderedArtists.Where((avm) => !avm.Header.Equals("#")));

            return(tempArtistViewModels);
        }
コード例 #4
0
ファイル: CollectionService.cs プロジェクト: zaevi/Dopamine
        public async Task <IList <GenreViewModel> > GetAllGenresAsync()
        {
            IList <string> genres = await this.trackRepository.GetGenresAsync();

            IList <GenreViewModel> orderedGenres = (await this.GetUniqueGenresAsync(genres)).OrderBy(g => FormatUtils.GetSortableString(g.GenreName, true)).ToList();

            // Workaround to make sure the "#" GroupHeader is shown at the top of the list
            List <GenreViewModel> tempGenreViewModels = new List <GenreViewModel>();

            tempGenreViewModels.AddRange(orderedGenres.Where((gvm) => gvm.Header.Equals("#")));
            tempGenreViewModels.AddRange(orderedGenres.Where((gvm) => !gvm.Header.Equals("#")));

            return(tempGenreViewModels);
        }
コード例 #5
0
ファイル: CollectionService.cs プロジェクト: Mniwyl/Dopamine
        public async Task <IList <ArtistViewModel> > GetAllArtistsAsync(ArtistType artistType)
        {
            IList <string> artists = null;

            switch (artistType)
            {
            case ArtistType.All:
                IList <string> trackArtiss = await this.trackRepository.GetTrackArtistsAsync();

                IList <string> albumArtists = await this.trackRepository.GetAlbumArtistsAsync();

                ((List <string>)trackArtiss).AddRange(albumArtists);
                artists = trackArtiss;
                break;

            case ArtistType.Track:
                artists = await this.trackRepository.GetTrackArtistsAsync();

                break;

            case ArtistType.Album:
                artists = await this.trackRepository.GetAlbumArtistsAsync();

                break;

            default:
                // Can't happen
                break;
            }

            IList <ArtistViewModel> orderedArtists = (await this.GetUniqueArtistsAsync(artists)).OrderBy(a => FormatUtils.GetSortableString(a.ArtistName, true)).ToList();

            // Workaround to make sure the "#" GroupHeader is shown at the top of the list
            List <ArtistViewModel> tempArtistViewModels = new List <ArtistViewModel>();

            tempArtistViewModels.AddRange(orderedArtists.Where((avm) => avm.Header.Equals("#")));
            tempArtistViewModels.AddRange(orderedArtists.Where((avm) => !avm.Header.Equals("#")));

            return(tempArtistViewModels);
        }
コード例 #6
0
ファイル: ArtistRepository.cs プロジェクト: xhanb/Dopamine
        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) => FormatUtils.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);
        }