Пример #1
0
        /// <summary>
        /// Check the status of the DJ. Returns whether the desired status was found.
        /// </summary>
        /// <param name="DJID">The DJID for the DJ.</param>
        /// <param name="desiredStatus">The desired status, 2 or !1 etc.</param>
        /// <param name="db">The database object to use.</param>
        /// <returns>The outcome of the operation.</returns>
        private Response DJValidateStatus(int DJID, string desiredStatus, DatabaseConnectivity db)
        {
            Response r;
            int DJStatus, desired;
            bool notStatus = false;
            // Get the status of the DJ.
            r = db.DJGetStatus(DJID);
            if (r.error)
                return r;

            // Attempt to parse that status of the DJ.
            if (!int.TryParse(r.message.Trim(), out DJStatus))
            {
                r.error = true;
                r.message = "Exception in DJCheckStatus: Unable to parse status from DB!";
                return r;
            }

            if (desiredStatus[0] == '!')
            {
                notStatus = true;
                desiredStatus = desiredStatus.Substring(1);
            }

            if(!int.TryParse(desiredStatus, out desired))
            {
                r.error = true;
                r.message = "Exception in DJCheckStatus: Cannot parse desired Status";
                return r;
            }

            if (!notStatus)
            {
                if (DJStatus != desired)
                {
                    r.error = true;
                    if (desired == 0)
                        r.message = "You are not signed out.";
                    else if (desired == 1)
                        r.message = "You are not signed in.";
                    else
                        r.message = "You are in the wrong state, possibly not created a session?";
                    return r;
                }
            }
            else if (DJStatus == desired)
            {
                r.error = true;
                if (desired == 0)
                    r.message = "You are signed out and cannot do that.";
                else if (desired == 1)
                    r.message = "You are signed in and cannot do that.";
                else
                    r.message = "You are in the wrong state, do you have a session running?";
                return r;
            }

            r.result = DJStatus;
            return r;
        }
Пример #2
0
        /// <summary>
        /// Get the playlists for a client.
        /// </summary>
        /// <param name="venueID">The venue to select playlists from. If set to -1, all venues are used.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public List<Playlist> MobileGetPlayLists(int venueID, long userKey)
        {
            int mobileID = -1;
            int venueStatus;
            List<Playlist> playLists;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (List<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return (List<Playlist>)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<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Validate venueID if the any venueID not given.
                if (venueID != -1)
                {
                    // Make sure the venueID exists.
                    r = db.DJGetStatus(venueID);
                    if (r.error)
                        return (List<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                    if (!int.TryParse(r.message.Trim(), out venueStatus))
                        return (List<Playlist>)Common.LogError("MobileGetPlayLists venueID parse fail (Bad venueID given?)", Environment.StackTrace, null, 0);
                }

                r = db.MobileGetPlaylists(venueID, mobileID, out playLists);
                if (r.error)
                    return (List<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Finish inserting information into the playlists.
                foreach (Playlist p in playLists)
                {
                    // Insert venue information.
                    r = db.GetVenueName(p.venue.venueID);
                    if (r.error)
                        return (List<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                    p.venue.venueName = r.message.Trim();

                    r = db.GetVenueAddress(p.venue.venueID);
                    if (r.error)
                        return (List<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                    p.venue.venueAddress = r.message.Trim();

                    for (int i = 0; i < p.songs.Count; i++)
                    {
                        Song fullSong;
                        r = Common.GetSongInformation(p.songs[i].ID, p.venue.venueID, mobileID, out fullSong, db);
                        if (r.error)
                            return (List<Playlist>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                        p.songs[i] = fullSong;
                    }
                }
                return playLists;
            }
        }
Пример #3
0
        /// <summary>
        /// Rate a song.
        /// </summary>
        /// <param name="songID">The songID.</param>
        /// <param name="rating">The rating -1 to 5.</param>
        /// <param name="venueID">The venueID of the song.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileRateSong(int songID, int rating, int venueID, long userKey)
        {
            int mobileID = -1;
            int venueStatus;
            int songExists;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                Response r = new Response();
                if (rating < -1 || rating > 5)
                {
                    r.error = true;
                    r.message = "Rating must be between -1 and 5 (inclusive).";
                    return r;
                }

                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

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

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

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.error = true;
                    r.message= "MobileGetPlayLists venueID parse fail (Bad venueID given?)";
                    return r;
                }

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.error = true;
                    r.message = "Could not find song";
                    return r;
                }

                // Set the song rating.
                r = db.MobileSetSongRating(mobileID, songID, rating);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                return r;
            }
        }
Пример #4
0
        /// <summary>
        /// Check to see if a status of a venue is equal to the desired status. 
        /// </summary>
        /// <param name="venueID">The venueID.</param>
        /// <param name="desiredStatus">The desired status "2" or "!3" etc.</param>
        /// <param name="db">The database connectivity.</param>
        /// <returns>The outcome of the operation.</returns>
        private Response VenueCheckStatus(int venueID, string desiredStatus, DatabaseConnectivity db)
        {
            Response r;
            int DJStatus, desired;
            bool notStatus = false;
            // Get the status of the DJ.
            r = db.DJGetStatus(venueID);
            if (r.error)
                return r;

            // Attempt to parse that status of the DJ.
            if (!int.TryParse(r.message.Trim(), out DJStatus))
            {
                r.error = true;
                r.message = "Exception in VenueCheckStatus: Unable to parse status from DB!";
                return r;
            }

            if (desiredStatus[0] == '!')
            {
                notStatus = true;
                desiredStatus = desiredStatus.Substring(1);
            }

            if (!int.TryParse(desiredStatus, out desired))
            {
                r.error = true;
                r.message = "Exception in VenueCheckStatus: Cannot parse desired Status";
                return r;
            }

            if (!notStatus)
            {
                if (DJStatus != desired)
                {
                    r.error = true;
                    if (desired == 0)
                        r.message = "Venue is online.";
                    else if (desired == 1)
                        r.message = "Venue is not online.";
                    else
                        r.message = "Venue does not have a session running";
                    return r;
                }
            }
            else if (DJStatus == desired)
            {
                r.error = true;
                if (desired == 0)
                    r.message = "Venue is not online.";
                else if (desired == 1)
                    r.message = "Venue is online.";
                else
                    r.message = "Venue has a session running.";
                return r;
            }

            r.result = DJStatus;
            return r;
        }
Пример #5
0
        /// <summary>
        /// Create a playlist. Returns the ID of the playlist in message.
        /// </summary>
        /// <param name="name">Playlist Name</param>
        /// <param name="venueID">VenueID the playlist is associated with.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileCreatePlaylist(string name, int venueID, long userKey)
        {
            Response r = new Response();
            if (name.Length < 1 || name.Length > 20)
            {
                r.error = true;
                r.message = "Name must be between 1 and 20 characters.";
                return r;
            }

            int mobileID = -1;
            int venueStatus;

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

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

                // Make sure the client isn't already logged out.
                r = MobileCheckStatus(mobileID, "!0", db);
                if (r.error)
                    return r;

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.error = true;
                    r.message = "Could not validate venue";
                    if (r.error)
                        return r;
                }

                r = db.MobileCreatePlaylist(name, venueID, mobileID, DateTime.Now);
                if(r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                return r;
            }
        }
Пример #6
0
        /// <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;
            }
        }
Пример #7
0
        /// <summary>
        /// View a song rating.
        /// </summary>
        /// <param name="songID">The songID.</param>
        /// <param name="venueID">The venueID.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileViewSongRating(int songID, int venueID, long userKey)
        {
            int mobileID = -1;
            int venueStatus;
            int songExists;
            int rating;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

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

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

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.error = true;
                    r.message = "MobileGetPlayLists venueID parse fail (Bad venueID given?)";
                    return r;
                }

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.error = true;
                    r.message = "Could not find song";
                    return r;
                }

                // Set the song rating.
                r = db.MobileGetSongRating(mobileID, songID);
                if(r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                if (r.message.Trim().Length == 0)
                {
                    r.message = "-1";
                    r.result = -1;
                    return r;
                }

                if (!int.TryParse(r.message.Trim(), out rating))
                {
                    r.error = true;
                    r.message = "Could not parse rating";
                    return r;
                }

                r.message = rating.ToString();
                r.result = rating;
                return r;
            }
        }
Пример #8
0
        /// <summary>
        /// Suggest songs for the user to sing. Based off of the song history of the current user.
        /// Some song suggestions given based on collaborative filtering with other user's song histories.
        /// Some suggestions based on other songs by artists sang. Returns most popular songs if prior
        /// information not available.
        /// </summary>
        /// <param name="venueID">The venue to suggest songs at.</param>
        /// <param name="userKey">The user's key.</param>
        /// <param name="start">Ignored.</param>
        /// <param name="count">The number of song suggestions.</param>
        /// <returns>The outcome of the operation</returns>
        public List<Song> MobileGetSongSuggestions(int venueID, long userKey, int start, int count)
        {
            start = 0;
            int count1 = count - count / 4;
            try
            {
                int mobileID = -1;
                using (DatabaseConnectivity db = new DatabaseConnectivity())
                {
                    #region SongSuggestionBoilerPlate
                    List<Song> finalSuggestions = new List<Song>();

                    // 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 venueID exists.
                    r = db.DJGetStatus(venueID);
                    if (r.error)
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                    int venueStatus;
                    if (!int.TryParse(r.message.Trim(), out venueStatus))
                    {
                        r.setErMsgStk(true, "MobileGetPlayLists venueID parse fail (Bad venueID given?)", Environment.StackTrace);
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                    }

                    #endregion

                    // The user's distinct song history.
                    List<KeyValuePair<string[], int>> songsAndCount; // Song Title/Artist and how many times it shows up.
                    r = db.MobileGetDistictSongHistory(mobileID, 0, 10, out songsAndCount);
                    if (r.error)
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                    // Get song suggestions based on what other people sang.
                    List<Song> suggestCollab;
                    r = SuggestCollabFilter(songsAndCount, mobileID, venueID, count1, out suggestCollab, db);
                    if (r.error)
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                    // Add these songs to fill up to half of the final suggestions.
                    for (int i = 0; i < suggestCollab.Count; i++)
                    {
                        Song s = suggestCollab[i];
                        r = Common.LoadSongRating(ref s, mobileID, db);
                        if (r.error)
                            return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                        finalSuggestions.Add(s);
                    }

                    if (finalSuggestions.Count < count)
                    {
                        // Get song suggestions based off of artist
                        List<Song> suggestByArtist;
                        // Suggest songs not sung by the user, but which have an artist the user has sung.
                        r = SuggestSongsNotSungByMostSungArtists(count - finalSuggestions.Count, mobileID, venueID, out suggestByArtist, db);
                        if (r.error)
                            return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                        // Add the artist suggestions to fill out the suggetsions.
                        foreach (Song s in suggestByArtist)
                        {
                            Song song;
                            r = Common.GetSongInformation(s.ID, venueID, mobileID, out song, db, false);
                            if (r.error)
                                return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                            finalSuggestions.Add(song);
                        }
                    }

                    if (finalSuggestions.Count < count)
                    {
                        // If we are lacking songs still, get from popular songs.
                        List<Song> popSongs;
                        List<int> popCounts;
                        r = db.GetMostPopularSongs(venueID, 0, count - finalSuggestions.Count, out popSongs, out popCounts);
                        if (r.error)
                            return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                        foreach (Song s in popSongs)
                        {
                            Song song;
                            r = Common.GetSongInformation(s.ID, venueID, mobileID, out song, db, false);
                            if (r.error)
                                return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                            finalSuggestions.Add(song);
                        }
                    }

                    return finalSuggestions;
                }
            }
            catch (Exception e)
            {
                ExpResponse r = new ExpResponse(true, "Exception in Suggest Song:", e.StackTrace);
                return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
            }
        }
Пример #9
0
        /// <summary>
        /// Get the achievements the mobile user has NOT earned at the given venue that are marked as visible by the DJ.
        /// If given venue is -1, all NOT earned achievements are returned.
        /// </summary>
        /// <param name="venueID">The venueID to get achievements form.</param>
        /// <param name="userKey">The mobile user's key</param>
        /// <param name="start">The starting index of the returned achievements.</param>
        /// <param name="count">The number of achievements to return.</param>
        /// <returns></returns>
        public List<MobileAchievement> MobileGetUnearnedAchievements(int venueID, long userKey, int start, int count)
        {
            int mobileID = -1;
            int venueStatus;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetGen<List<MobileAchievement>>(r, null, Common.LogFile.Mobile);

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

                // Validate venueID if the any venueID not given.
                if (venueID != -1)
                {
                    // Make sure the venueID exists.
                    r = db.DJGetStatus(venueID);
                    if (r.error)
                        return Common.LogErrorRetGen<List<MobileAchievement>>(r, null, Common.LogFile.Mobile);

                    if (!int.TryParse(r.message.Trim(), out venueStatus))
                    {
                        r.setErMsgStk(true, "MobileGetPlayLists venueID parse fail (Bad venueID given?)", Environment.StackTrace);
                        return Common.LogErrorRetGen<List<MobileAchievement>>(r, null, Common.LogFile.Mobile);
                    }
                }

                List<Achievement> unearnedAchievements;

                r = db.MobileGetUnearnedVisibleAchievements(mobileID, venueID, out unearnedAchievements, start, count);
                if (r.error)
                    return Common.LogErrorRetGen<List<MobileAchievement>>(r, null, Common.LogFile.Mobile);

                List<MobileAchievement> mobileUnearnedAchievements = new List<MobileAchievement>();
                foreach (Achievement a in unearnedAchievements)
                {
                    MobileAchievement ma = new MobileAchievement();
                    ma.ID = a.ID;
                    ma.name = a.name;
                    ma.description = a.description;
                    ma.image = a.image.ToString() + ".png";
                    mobileUnearnedAchievements.Add(ma);
                }

                return mobileUnearnedAchievements;
            }
        }
Пример #10
0
        /// <summary>
        /// Gets the most popular songs associated with a venue or all venues.
        /// </summary>
        /// <param name="venueID">The venueID of the venue, if -1, searches all venues.</param>
        /// <param name="start">The starting index of results.</param>
        /// <param name="count">The count of results.</param>
        /// <returns></returns>
        public List<Song> MobileGetMostPopularSongs(int venueID, int start, int count)
        {
            List<Song> songs = new List<Song>();
            List<int> counts = new List<int>();
            List<Song> songIDs;
            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);

                // Validate venueID if the any venueID not given.
                if (venueID != -1)
                {
                    // Make sure the venueID exists.
                    r = db.DJGetStatus(venueID);
                    if (r.error)
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                    int venueStatus;
                    if (!int.TryParse(r.message.Trim(), out venueStatus))
                    {
                        r.setErMsgStk(true, "Could not parse venueID", Environment.StackTrace);
                        return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);
                    }
                }

                r = db.GetMostPopularSongs(venueID, start, count, out songIDs, out counts);
                if (r.error)
                    return Common.LogErrorRetGen<List<Song>>(r, null, Common.LogFile.Mobile);

                foreach (Song s in songIDs)
                {
                    Song fullSong;
                    Common.GetSongInformation(s.ID, venueID, -1, out fullSong, db, false);
                    songs.Add(fullSong);
                }
                return songs;
            }
        }
Пример #11
0
        /// <summary>
        /// Check to see if a status of a venue is equal to the desired status. 
        /// </summary>
        /// <param name="venueID">The venueID.</param>
        /// <param name="desiredStatus">The desired status "2" or "!3" etc.</param>
        /// <param name="db">The database connectivity.</param>
        /// <returns>The outcome of the operation.</returns>
        private ExpResponse VenueCheckStatus(int venueID, string desiredStatus, DatabaseConnectivity db, out bool validStatus)
        {
            ExpResponse r;
            int DJStatus, desired;
            bool notStatus = false;
            validStatus = false;
            // Get the status of the DJ.
            r = db.DJGetStatus(venueID);
            if (r.error)
                return r;

            // Attempt to parse that status of the DJ.
            if (!int.TryParse(r.message.Trim(), out DJStatus))
            {
                r.setErMsgStk(true, "Exception in VenueCheckStatus: Unable to parse status from DB!", Environment.StackTrace);
                return r;
            }

            if (desiredStatus[0] == '!')
            {
                notStatus = true;
                desiredStatus = desiredStatus.Substring(1);
            }

            if (!int.TryParse(desiredStatus, out desired))
            {
                r.setErMsgStk(true, "Exception in VenueCheckStatus: Cannot parse desired Status", Environment.StackTrace);
                return r;
            }

            if (!notStatus)
            {
                if (DJStatus != desired)
                {
                    return r;
                }
            }
            else if (DJStatus == desired)
            {
                return r;
            }

            r.result = DJStatus;
            validStatus = true;
            return r;
        }
Пример #12
0
        /// <summary>
        /// Create a playlist. Returns the ID of the playlist in message.
        /// </summary>
        /// <param name="name">Playlist Name</param>
        /// <param name="venueID">VenueID the playlist is associated with.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileCreatePlaylist(string name, int venueID, long userKey)
        {
            ExpResponse r = new ExpResponse();
            if (name.Length < 1 || name.Length > 20)
            {
                r.setErMsg(true, Messages.ERR_PLYLST_NAME_LONG);
                return r;
            }

            int mobileID = -1;
            int venueStatus;

            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, 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.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.setErMsg(true, Messages.ERR_BAD_SERVER_INPUT);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                r = db.MobileCreatePlaylist(name, venueID, mobileID, DateTime.Now);
                if(r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                return r;
            }
        }
Пример #13
0
        /// <summary>
        /// View a song rating.
        /// </summary>
        /// <param name="songID">The songID.</param>
        /// <param name="venueID">The venueID.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileViewSongRating(int songID, int venueID, long userKey)
        {
            int mobileID = -1;
            int venueStatus;
            int songExists;
            int rating;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, 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.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Make sure the venueID exists.
                r = db.DJGetStatus(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (!int.TryParse(r.message.Trim(), out venueStatus))
                {
                    r.setErMsgStk(true, "MobileGetPlayLists venueID parse fail (Bad venueID given?)", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.setErMsgStk(true, "Could not find song", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // Set the song rating.
                r = db.MobileGetSongRating(mobileID, songID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (r.message.Trim().Length == 0)
                {
                    r.setErMsgRes(false, "-1", -1);
                    return r;
                }

                if (!int.TryParse(r.message.Trim(), out rating))
                {
                    r.setErMsgStk(true, "Could not parse song rating song", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                r.setErMsgRes(false, rating.ToString(), rating);
                return r;
            }
        }
Пример #14
0
        /// <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;
            }
        }