/// <summary> /// View the song history of the client. /// </summary> /// <param name="start">The index of the first result.</param> /// <param name="count">The number of results to return.</param> /// <param name="userKey">client mobile key.</param> /// <returns>The outcome of the opearation.</returns> public List<SongHistory> MobileViewSongHistory(int start, int count, long userKey) { int mobileID = -1; List<SongHistory> songHistory = new List<SongHistory>(); using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection Response r = db.OpenConnection(); if (r.error) return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0); // Convert the userKey to MobileID r = MobileKeyToID(userKey, out mobileID, db); if (r.error) return (List<SongHistory>)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<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0); r = db.MobileGetSongHistory(mobileID, start, count); if (r.error) return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0); // Case of empty playlists. if (r.message.Trim().Length == 0) return songHistory; //"ID", "VenueID", "MobileID", "SongID", "DateSung" try { string[] songHistoryLines = r.message.Trim().Split('\n'); foreach (string songHistoryLine in songHistoryLines) { string[] songHistoryParts = Common.splitByDel(songHistoryLine); SongHistory sh = new SongHistory(); int vid; if (!int.TryParse(songHistoryParts[1], out vid)) return (List<SongHistory>)Common.LogError("MobileGetSongHistory venueID parse fail from MobileSongHistory.", Environment.StackTrace, null, 0); sh.venue = new Venue(); sh.venue.venueID = vid; r = db.GetVenueName(vid); if (r.error) return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0); sh.venue.venueName = r.message.Trim(); r = db.GetVenueAddress(vid); if (r.error) return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0); sh.venue.venueAddress = r.message.Trim(); int songID; if(!int.TryParse(songHistoryParts[3], out songID)) return (List<SongHistory>)Common.LogError("MobileGetSongHistory songID parse fail from MobileSongHistory.", Environment.StackTrace, null, 0); Song song; r = Common.GetSongInformation(songID, vid, mobileID,out song, db, false); if(r.error) return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0); sh.song = song; sh.date = Convert.ToDateTime(songHistoryParts[4]); songHistory.Add(sh); } return songHistory; } catch (Exception e) { return (List<SongHistory>)Common.LogError(e.Message, e.StackTrace, null, 0); } } }
/// <summary> /// View the song history of the client. /// </summary> /// <param name="start">The index of the first result.</param> /// <param name="count">The number of results to return.</param> /// <param name="userKey">client mobile key.</param> /// <returns>The outcome of the opearation.</returns> public List<SongHistory> MobileViewSongHistory(int start, int count, long userKey) { int mobileID = -1; List<SongHistory> songHistory = new List<SongHistory>(); using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection ExpResponse r = db.OpenConnection(); if (r.error) return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile); // Convert the userKey to MobileID r = MobileKeyToID(userKey, out mobileID, db); if (r.error) return Common.LogErrorRetGen<List<SongHistory>>(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<SongHistory>>(r, null, Common.LogFile.Mobile); if (!validStatus) { r.setErMsgStk(true, "User: "******" has invalid status", Environment.StackTrace); return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile); } r = db.MobileGetSongHistory(mobileID, start, count, out songHistory); if (r.error) return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile); for (int i = 0; i < songHistory.Count; i++) { r = db.GetVenueName(songHistory[i].venue.venueID); if (r.error) return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile); songHistory[i].venue.venueName = r.message.Trim(); r = db.GetVenueAddress(songHistory[i].venue.venueID); if (r.error) return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile); songHistory[i].venue.venueAddress = r.message.Trim(); Song song; r = Common.GetSongInformation(songHistory[i].song.ID, songHistory[i].venue.venueID, mobileID, out song, db, false); if (r.error) return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile); songHistory[i].song = song; } return songHistory; } }