public static bool LoadPlaylist(Playlist p_Playlist, bool p_Shuffle)
        {
            PlaylistActive = false;
            m_Entries.Clear();

            ActivePlaylist = p_Playlist;

            if (ActivePlaylist == null)
                return false;

            using (var s_Db = Database.GetConnection())
            {
                var s_Songs = s_Db.Select<PlaylistEntry>(p_Entry => p_Entry.PlaylistID == ActivePlaylist.ID);

                // Sort or shuffle the songs.
                if (!p_Shuffle)
                    s_Songs = s_Songs.OrderBy(p_Entry => p_Entry.Index).ToList();
                else
                    s_Songs = s_Songs.OrderBy(s_Song => Guid.NewGuid()).ToList();

                // Queue up all the songs.
                foreach (var s_Entry in s_Songs)
                    m_Entries.Enqueue(s_Entry);

                if (m_Entries.Count > 0)
                    PlaylistActive = true;

                return true;
            }
        }
        public static void ImportPlaylist(Int64 p_ExternalID)
        {
            var s_PlaylistData = Application.Library.User.GetPlaylistData(p_ExternalID);

            if (s_PlaylistData == null)
                return;

            using (var s_Db = Database.GetConnection())
            {
                var s_Playlist = s_Db.Single<Playlist>(p_Playlist => p_Playlist.GrooveSharkID == s_PlaylistData.PlaylistID);

                if (s_Playlist == null)
                {
                    s_Playlist = new Playlist()
                    {
                        Description = s_PlaylistData.About,
                        Name = s_PlaylistData.Name,
                        GrooveSharkID = s_PlaylistData.PlaylistID
                    };
                }

                // Insert/update the playlist.
                s_Db.Save(s_Playlist);

                var s_Songs = new List<PlaylistEntry>();
                var s_NewSongs = new List<SongEntry>();

                foreach (var s_Song in s_PlaylistData.Songs)
                {
                    s_Songs.Add(new PlaylistEntry() { PlaylistID = s_Playlist.ID, SongID = s_Song.SongID, Index = 0 });

                    var s_LocalSong = s_Db.SingleById<SongEntry>(s_Song.SongID);

                    if (s_LocalSong != null)
                        continue;

                    s_LocalSong = new SongEntry()
                    {
                        SongID = s_Song.SongID,
                        SongName = s_Song.Name,
                        ArtistID = s_Song.ArtistID,
                        ArtistName = s_Song.ArtistName,
                        AlbumID = s_Song.AlbumID,
                        AlbumName = s_Song.AlbumName,
                    };

                    s_NewSongs.Add(s_LocalSong);
                }

                s_Songs = s_Songs.DistinctBy(p_Entry => p_Entry.SongID).ToList();
                s_NewSongs = s_NewSongs.DistinctBy(p_Song => p_Song.SongID).ToList();

                // Calculate indexes.
                for (var i = 0; i < s_Songs.Count; ++i)
                    s_Songs[i].Index = i;

                // Add songs that don't exist to the collection.
                s_Db.SaveAll(s_NewSongs);

                // Delete old song entries.
                s_Db.Delete<PlaylistEntry>(p_Entry => p_Entry.PlaylistID == s_Playlist.ID);

                // Import the new ones.
                s_Db.SaveAll(s_Songs);
            }
        }