/// <summary> /// Allows a client to search for songs in a venue. If title or artist are blank, they are not used in the search. /// </summary> /// <param name="title">The title.</param> /// <param name="artist">The artist.</param> /// <param name="start">The index of the first result.</param> /// <param name="count">The number of results to return.</param> /// <param name="venueID">The venueID to search from.</param> /// <param name="userKey">The userKey of the mobile user.</param> /// <returns>The outcome of the operation.</returns> public List<Song> MobileSongSearch(string title, string artist, 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); // Make sure the venueID 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("MobileSongSeach venueID parse fail (bad venueID given?)", Environment.StackTrace, null, 0); // Complete the search. r = db.MobileSearchSongs(title.Trim(), artist.Trim(), venueID, start, count); if (r.error) return (List<Song>)Common.LogError(r.message, Environment.StackTrace, null, 0); if (r.message.Trim() == string.Empty) return songs; 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); } return songs; } }
/// <summary> /// Allows a client to search for songs in a venue. If title or artist are blank, they are not used in the search. /// </summary> /// <param name="title">The title.</param> /// <param name="artist">The artist.</param> /// <param name="start">The index of the first result.</param> /// <param name="count">The number of results to return.</param> /// <param name="venueID">The venueID to search from.</param> /// <param name="userKey">The userKey of the mobile user.</param> /// <returns>The outcome of the operation.</returns> public List<Song> MobileSongSearch(string title, string artist, 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); } // Make sure the venueID 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); } // Complete the search. r = db.MobileSearchSongs(title.Trim(), artist.Trim(), venueID, start, count); if (r.error) return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile); if (r.message.Trim() == string.Empty) return songs; 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); } return songs; } }