Exemplo n.º 1
0
        /// <summary>
        /// Allows a mobile user to browse through a DJ's songs. Depending on isArtist, returns songs whose title/artist start with firstletter.
        /// </summary>
        /// <param name="firstLetter">The string to start matching on.</param>
        /// <param name="isArtist">Whether firstLetter is an artist or title.</param>
        /// <param name="start">The index of the first result.</param>
        /// <param name="count">The number of results.</param>
        /// <param name="venueID">The venueID to search songs from.</param>
        /// <param name="userKey">The userKey of the client.</param>
        /// <returns>The outcome of the operation.</returns>
        public List<Song> MobileSongBrowse(string firstLetter, bool isArtist, int start, int count, int venueID, long userKey)
        {
            int venueStatus;
            int mobileID = -1;
            List<Song> songs = new List<Song>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (List<Song>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return (List<Song>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Make sure the client isn't already logged out.
                r = MobileCheckStatus(mobileID, "!0", db);
                if (r.error)
                    return (List<Song>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Check to make sure the venue exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return (List<Song>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                if (!int.TryParse(r.message.Trim(), out venueStatus))
                    return (List<Song>)Common.LogError("MobileSongBrose venueID parse fail (bad venueID given?)", Environment.StackTrace, null, 0);

                r = db.MobileBrowseSongs(firstLetter, isArtist, start, count, venueID);
                if (r.error)
                    return (List<Song>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                if (r.message.Trim() == string.Empty)
                    return songs;

                int count2 = 0;
                string[] songLines = r.message.Trim().Split('\n');
                foreach (string songLine in songLines)
                {
                    string[] songParts = Common.splitByDel(songLine);
                    Song song = new Song();
                    int id;
                    if (!int.TryParse(songParts[0], out id))
                        return (List<Song>)Common.LogError("Exception in MobileListSongsSQL: could not parse song id", Environment.StackTrace, null, 0);
                    song.ID = id;
                    song.title = songParts[1];
                    song.artist = songParts[2];
                    song.duration = int.Parse(songParts[3]);
                    Common.LoadSongRating(ref song, mobileID, db);
                    song.pathOnDisk = "";
                    songs.Add(song);
                    count2++;
                }
                return songs;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows a mobile user to browse through a DJ's songs. Depending on isArtist, returns songs whose title/artist start with firstletter.
        /// </summary>
        /// <param name="firstLetter">The string to start matching on.</param>
        /// <param name="isArtist">Whether firstLetter is an artist or title.</param>
        /// <param name="start">The index of the first result.</param>
        /// <param name="count">The number of results.</param>
        /// <param name="venueID">The venueID to search songs from.</param>
        /// <param name="userKey">The userKey of the client.</param>
        /// <returns>The outcome of the operation.</returns>
        public List<Song> MobileSongBrowse(string firstLetter, bool isArtist, int start, int count, int venueID, long userKey)
        {
            int venueStatus;
            int mobileID = -1;
            List<Song> songs = new List<Song>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsgStk(true, "User: "******" has invalid status", Environment.StackTrace);
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                }

                // Check to make sure the venue exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.setErMsgStk(true, "VenueID parse fail", Environment.StackTrace);
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                }

                r = db.MobileBrowseSongs(firstLetter, isArtist, start, count, venueID);
                if (r.error)
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                if (r.message.Trim() == string.Empty)
                    return songs;

                int count2 = 0;
                string[] songLines = r.message.Trim().Split('\n');
                foreach (string songLine in songLines)
                {
                    string[] songParts = Common.splitByDel(songLine);
                    Song song = new Song();
                    int id;
                    if (!int.TryParse(songParts[0], out id))
                    {
                        r.setErMsgStk(true, "Could not parse song ID", Environment.StackTrace);
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                    }
                    song.ID = id;
                    song.title = songParts[1];
                    song.artist = songParts[2];
                    song.duration = int.Parse(songParts[3]);
                    Common.LoadSongRating(ref song, mobileID, db);
                    song.pathOnDisk = "";
                    songs.Add(song);
                    count2++;
                }
                return songs;
            }
        }