Example #1
0
    /// <summary>
    /// Get the collection of tracks which comprise an album
    /// </summary>
    /// <param name="albumId"></param>
    /// <returns></returns>
    public static TrackData[] GetTracksByAlbumId(
        string albumId)
    {
        AlbumData album = AlbumList.GetById(albumId);

        return(album == null ? null : album.Tracks);
    }
Example #2
0
    /// <summary>
    /// For all tracks in all albums, build the albumsByArtistId, albumsByInitialLetter, artistsByInitialLetter and artistIdByName indexes
    /// </summary>
    private static void BuildIndexByArtist()
    {
        albumsByArtistId       = new SortedDictionary <string, AlbumCollection>();
        albumsByInitialLetter  = new SortedDictionary <string, AlbumCollection>();
        artistsByInitialLetter = new SortedDictionary <string, SortedDictionary <string, string> >();
        artistIdByName         = new SortedDictionary <string, string>();

        foreach (var albumId in AlbumList.Keys)
        {
            var album = AlbumList.GetById(albumId);
            if (!IsClassicalAlbum(album))
            {
                var track0     = album.Track0.Info;
                var artistName = album.GetArtistName();
                var albumName  = track0.ContainsKey("Album") ? track0["Album"] : "?";

                if (!string.IsNullOrEmpty(artistName) && !string.IsNullOrEmpty(albumName))
                {
                    var initialArtistLetter = artistName.Substring(0, 1);
                    if (!artistsByInitialLetter.ContainsKey(initialArtistLetter))
                    {
                        artistsByInitialLetter[initialArtistLetter] = new SortedDictionary <string, string>();
                    }
                    artistsByInitialLetter[initialArtistLetter][artistName] = artistName;

                    var initialAlbumLetter = albumName.Substring(0, 1);
                    if (!albumsByInitialLetter.ContainsKey(initialAlbumLetter))
                    {
                        albumsByInitialLetter[initialAlbumLetter] = new AlbumCollection();
                    }
                    albumsByInitialLetter[initialAlbumLetter].Add(albumId, album);

                    string artistId;
                    if (!artistIdByName.ContainsKey(artistName))
                    {
                        artistId = track0["Key"];
                        albumsByArtistId[artistId] = new AlbumCollection();
                        artistIdByName[artistName] = artistId;
                    }
                    else
                    {
                        artistId = artistIdByName[artistName];
                    }

                    albumsByArtistId[artistId].Add(albumId, album);
                }
            }
        }
    }