Ejemplo n.º 1
0
        /// <summary>
        /// Get the DJ's queue from the server.
        /// </summary>
        /// <param name="queue">The out parameter that represents the queue.</param>
        /// <param name="DJKey">The DJKey assigned to the DJ.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJGetQueue(out List<queueSinger> queue, long DJKey)
        {
            queue = new List<queueSinger>();
            int DJID = -1, count = 0;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ is not logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    r.error = false;
                    r.message = "Empty Queue";
                    return r;
                }

                r = Common.DBToFullList(raw, out queue, DJID, db);
                if (r.error)
                    return r;
                r.result = count;
                return r;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a test Queue for the Rick account. Does not work with any other account.
        /// </summary>
        /// <param name="DJKey">The DJ Key assigned to the Rick account.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJTestQueueFill(long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                if (DJID != 5 && DJID != 4)
                {
                    r.error = true;
                    r.message = "You are not the rick or jakub account.";
                    return r;
                }

                // Make sure the DJ isn't logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Get the current song Requests
                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string newRequests = string.Empty;
                if (DJID == 5)
                    newRequests = "1~32066~44022`3~23565~23504`2003~32155~32158`2~41440~41438";
                else if (DJID == 4)
                    newRequests = "1~55474~56758`2~59321~42050`3~43357~47751";

                r = db.SetSongRequests(DJID, newRequests);
                if (r.error)
                    return r;
                Common.PushMessageToUsersOfDJ(DJID, "queue", db);
                return r;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Changes a user's song request.
        /// </summary>
        /// <param name="newSR">The new song request to user.</param>
        /// <param name="oldSR">The old song request to replace.</param>
        /// <param name="DJKey">The DJ's assigned key.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJChangeSongRequest(SongRequest newSR, SongRequest oldSR, long DJKey)
        {
            int DJID = -1;
            int songID = -1;
            bool songChangeMade = false;
            bool requireSendToAll = false;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                if (newSR.user.userID != oldSR.user.userID)
                {
                    r.error = true;
                    r.message = "User must be the same between song requets";
                    return r;
                }

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ isn't logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Check to see if song exists.
                r = db.SongExists(DJID, newSR.songID);
                if (r.error)
                    return r;

                // Make sure a songID was sent back.
                if (!int.TryParse(r.message.Trim(), out songID))
                {
                    r.error = true;
                    r.message = "Could not find new song.";
                    return r;
                }

                // Make sure the mobile user is valid.
                    r = db.MobileValidateID(oldSR.user.userID);
                    if (r.error)
                        return r;
                    // See if an ID was returned.
                    if (r.message.Trim() == String.Empty)
                    {
                        string s = r.message.Trim();
                        r.error = true;
                        r.message = "Client ID could not be validated.";
                        return r;
                    }

                // Get the current song Requests
                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string requests = r.message;
                string newRequests = string.Empty;

                // If there were no requests, simply add the single request.
                if (requests.Trim().Length == 0)
                {
                    r.error = true;
                    r.message = "There are no song requests";
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return r;

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == oldSR.user.userID)
                    {
                        // Loop through the songs to see if the user is already singing this song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            if (queue[i].songs[j].ID == newSR.songID)
                            {
                                r.error = true;
                                r.message = "User is already singing that song";
                                return r;
                            }
                            if (queue[i].songs[j].ID == oldSR.songID)
                            {
                                queue[i].songs[j].ID = newSR.songID;
                                songChangeMade = true;
                                if (j == 0)
                                    requireSendToAll = true;
                            }

                        }

                        if (songChangeMade)
                        {
                            Common.MinimalListToDB(queue, out newRequests);
                            r = db.SetSongRequests(DJID, newRequests);
                            if (r.error)
                                return r;
                            if (requireSendToAll)
                                Common.PushMessageToUsersOfDJ(DJID, "queue", db);
                            else
                                Common.PushMessageToMobile(oldSR.user.userID, "queue", db);
                            return r;
                        }

                        // We didn't find the old song.
                        r.error = true;
                        r.message = "Could not find the old song.";
                        return r;
                    }
                }

                // We didn't find the user.
                r.error = true;
                r.message = "Could not find the user.";
                return r;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Pop the top song off the queue and updates the queue.
        /// </summary>
        /// <param name="sr">A Song request that represents the top song off the queue. Must match what the server believes is the top of the queue. Used to make sure the queues are in sync.</param>
        /// <param name="DJKey">The DJKey given to the DJ.</param>
        /// <returns>The outcome of the operaton.</returns>
        public Response DJPopQueue(SongRequest sr, long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    r.error = true;
                    r.message = "Empty Queue";
                    return r;
                }

                List<queueSinger> queue;
                r = Common.DBToMinimalList(raw, out  queue);
                if (r.error)
                    return r;

                if (queue[0].user.userID != sr.user.userID || queue[0].songs[0].ID != sr.songID)
                {
                    r.error = true;
                    r.message = "Song Request to Pop did not match first song Request, is your queue out of date?";
                    return r;
                }

                int nextUserID = queue[0].user.userID;
                Common.PushMessageToMobile(nextUserID, "turn", db);

                queue[0].songs.RemoveAt(0);
                if (queue[0].songs.Count == 0)
                {
                    if (queue[0].user.userID < 0)
                    {
                        r = db.DJRemoveTempUser(queue[0].user.userID, DJID);
                        queue.RemoveAt(0);
                        if (r.error)
                            return r;
                    }
                    else
                        queue.RemoveAt(0);

                }
                else
                {
                    queueSinger temp = queue[0];
                    queue.RemoveAt(0);
                    queue.Add(temp);
                }

                if (queue.Count > 0)
                {
                    nextUserID = queue[0].user.userID;
                    Common.PushMessageToMobile(nextUserID, "next", db);
                }

                raw = string.Empty;
                r = Common.MinimalListToDB(queue, out raw);
                if (r.error)
                    return r;
                r = db.SetSongRequests(DJID, raw);
                if (r.error)
                    return r;

                if (sr.user.userID > 0)
                {
                    r = db.MobileAddSongHistory(sr.user.userID, DJID, sr.songID, DateTime.Now);
                    if (r.error)
                        Common.LogError(r.message, Environment.StackTrace, r, 1);
                }

                Common.PushMessageToUsersOfDJ(DJID, "queue", db);

                r = Common.RunAchievements(DJID, db);
                if (r.error)
                    return r;

                return r;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Remove a user from the queue. All of the user's song requests are removed.
        /// </summary>
        /// <param name="userID">The userID of the user</param>
        /// <param name="DJKey">The DJ's assigned key.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJRemoveUser(int userID, long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ isn't logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Get the current song Requests
                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string requests = r.message;
                string newRequests = string.Empty;

                // If there were no requests, simply add the single request.
                if (requests.Trim().Length == 0)
                {
                    r.error = true;
                    r.message = "The queue is empty";
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return r;

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == userID)
                    {
                        queue.RemoveAt(i);

                        if (userID < 0)
                        {
                            r = db.DJRemoveTempUser(userID, DJID);
                            if (r.error)
                                return r;
                        }

                        Common.MinimalListToDB(queue, out newRequests);
                        r = db.SetSongRequests(DJID, newRequests);
                        if (r.error)
                            return r;
                        Common.PushMessageToUsersOfDJ(DJID, "queue", db);
                        return r;
                    }
                }

                r.error = true;
                r.message = "Could not find client in the queue.";
                return r;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// View the queue of the DJ the client is associated with.
        /// </summary>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public List<queueSinger> MobileViewQueue(long userKey)
        {
            int venueID = -1;
            int mobileID = -1;
            List<queueSinger> queue = new List<queueSinger>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetGen<List<queueSinger>>(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<queueSinger>>(r, null, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsgStk(true, "Bad user status", Environment.StackTrace);
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);
                }

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);
                venueID = r.result;
                if (venueID == -1)
                {
                    r.setErMsg(true, Messages.MSG_NO_VENUE_ASSOCIATED);
                    Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);
                }

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsgStk(true, "Bad venue status for viewing queue.", Environment.StackTrace);
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);
                }

                r = db.GetSongRequests(venueID);
                if (r.error)
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    return queue;
                }

                r = DBToNearlyFullList(raw, out queue, venueID, mobileID, db);
                if (r.error)
                    return Common.LogErrorRetGen<List<queueSinger>>(r, null, Common.LogFile.Mobile);
                return queue;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the approximate wait time for a new user if they were to join the queue. If no error occures, result stored in result and message.
        /// </summary>
        /// <param name="DJKey">The DJ key assigned to the DJ.</param>
        /// <returns>The outcome of the opeartion.</returns>
        public Response DJNewUserWaitTime(long DJKey)
        {
            int DJID = -1;
            List<queueSinger> queue = new List<queueSinger>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ isn't logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                r = db.GetSongRequests(DJID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    r.error = false;
                    r.message = "Empty Queue";
                    r.result = 0;
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                r = Common.DBToFullList(raw, out queue, DJID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                int time = 0;
                foreach (queueSinger qs in queue)
                    time += qs.songs[0].duration + Common.TIME_BETWEEN_REQUESTS;

                r.error = false;
                r.message = time.ToString().Trim();
                r.result = time;
                return r;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// View the queue of the DJ the client is associated with.
        /// </summary>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public List<queueSinger> MobileViewQueue(long userKey)
        {
            int venueID = -1;
            int mobileID = -1;
            List<queueSinger> queue = new List<queueSinger>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (List<queueSinger>)Common.LogError(r.message, Environment.StackTrace, null, 0);

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

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return (List<queueSinger>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                venueID = r.result;

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db);
                if (r.error)
                    return queue;

                r = db.GetSongRequests(venueID);
                if (r.error)
                    return (List<queueSinger>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    return queue;
                }

                r = DBToNearlyFullList(raw, out queue, venueID, mobileID, db);
                if (r.error)
                    return (List<queueSinger>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                return queue;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get the estimated wait time until the user can sing.
        /// </summary>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileGetWaitTime(long userKey)
        {
            int venueID = -1;
            int mobileID = -1;
            List<queueSinger> queue = new List<queueSinger>();
            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 r;

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                venueID = r.result;

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db);
                if (r.error)
                    return r;

                r = db.GetSongRequests(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    r.error = false;
                    r.message = "Empty Queue";
                    r.result = 0;
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                r = DBToNearlyFullList(raw, out queue, venueID, mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                int time = 0;
                for (int i = 0; i < queue.Count; i++)
                {
                    if (queue[i].user.userID == mobileID)
                        break;
                    else
                        time += queue[i].songs[0].duration + Common.TIME_BETWEEN_REQUESTS;
                }

                r.error = false;
                r.message = time.ToString().Trim();
                r.result = time;
                return r;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create a song request.
        /// </summary>
        /// <param name="songID">The songID</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileSongRequest(int songID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            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 r;

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                venueID = r.result;

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db);
                if (r.error)
                    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;
                }

                // Get the current song Requests
                r = db.GetSongRequests(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                string requests = r.message;
                string newRequests = string.Empty;

                if (requests.Trim().Length == 0)
                {
                    requests = mobileID.ToString() + "~" + songID.ToString();
                    r = db.SetSongRequests(venueID, requests);
                    if (r.error)
                        return r;
                    r = Common.PushMessageToMobile(mobileID, "queue", db);
                    if (r.error)
                        Common.LogError(r.message, Environment.StackTrace, null, 0);
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == mobileID)
                    {
                        // Loop through the songs to see if the user is already singing this song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            if (queue[i].songs[j].ID == songID)
                            {
                                r.error = true;
                                r.message = "You are already in queue to sing that song";
                                return r;
                            }

                        }
                        // They dont' already have the song in the list, add them to the list
                        Song s = new Song();
                        s.ID = songID;
                        queue[i].songs.Add(s);
                        Common.MinimalListToDB(queue, out newRequests);
                        r = db.SetSongRequests(venueID, newRequests);
                        if(r.error)
                            return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                        Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                        return r;
                    }
                }

                queueSinger qs = new queueSinger();
                qs.songs = new List<Song>();

                User u = new User();
                u.userID = mobileID;
                qs.user = u;

                Song song = new Song();
                song.ID = songID;
                qs.songs.Add(song);

                queue.Add(qs);
                Common.MinimalListToDB(queue, out newRequests);
                r = db.SetSongRequests(venueID, newRequests);
                if(r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                return r;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Changes a user's song request to a new song.
        /// </summary>
        /// <param name="oldSongID">The old request.</param>
        /// <param name="newSongID">The new request.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileChangeSongRequest(int oldSongID, int newSongID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            bool songChangeMade = false;
            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 r;

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                venueID = r.result;

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db);
                if (r.error)
                    return r;

                // Check to see if song exists.
                r = db.SongExists(venueID, newSongID);
                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 new song";
                    return r;
                }

                // Get the current song Requests
                r = db.GetSongRequests(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                string requests = r.message;
                string newRequests = string.Empty;

                // If there are no song requests.
                if (requests.Trim().Length == 0)
                {
                    r.error = true;
                    r.message = "There are no song requests.";
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == mobileID)
                    {
                        // Loop through the songs to find the old song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            // If we find the new song, we don't want to allow duplicates
                            if (queue[i].songs[j].ID == newSongID)
                            {
                                r.error = true;
                                r.message = "You are already singing the new song";
                                return r;
                            }
                            // If we found the old song.
                            if (queue[i].songs[j].ID == oldSongID)
                            {
                                queue[i].songs[j].ID = newSongID;
                                songChangeMade = true;
                            }

                        }

                        if (songChangeMade)
                        {
                            Common.MinimalListToDB(queue, out newRequests);
                            r = db.SetSongRequests(venueID, newRequests);
                            if(r.error)
                                return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                            Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                            return r;
                        }
                        // If we couldn't find the old song, inform user.
                        r.error = true;
                        r.message = "Could not find the old song";
                        return r;
                    }
                }

                // If we couldn't find the user.
                r.error = true;
                r.message = "You have no song reqeusts.";
                return r;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Move a user's song to the front of his/her songs.
        /// </summary>
        /// <param name="songID">The ID of the song.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileMoveSongRequestToTop(int songID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            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;
                }

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                venueID = r.result;
                if (venueID == -1)
                {
                    r.setErMsg(true, Messages.MSG_NO_VENUE_ASSOCIATED);
                    return r;
                }

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_VENUE_NO_SESSION);
                    return r;
                }

                // 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.setErMsg(true, Messages.MSG_SONG_NOT_FOUND);
                    return r;
                }

                // Get the current song Requests
                r = db.GetSongRequests(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                string requests = r.message;
                string newRequests = string.Empty;

                // If there are no song requests.
                if (requests.Trim().Length == 0)
                {
                    r.setErMsg(true, Messages.MSG_NO_SONG_REQUESTS);
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == mobileID)
                    {
                        // Loop through the songs to find the song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            // Remove this song, and add them to the front of the queue.
                            if (queue[i].songs[j].ID == songID)
                            {
                                Song s = queue[i].songs[j];
                                queue[i].songs.RemoveAt(j);
                                queue[i].songs.Insert(0, s);
                                r = Common.MinimalListToDB(queue, out newRequests);
                                if(r.error)
                                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                                r = db.SetSongRequests(venueID, newRequests);
                                if (r.error)
                                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                                Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                                return r;
                            }
                        }
                    }
                }

                // If we couldn't find the user.
                r.setErMsg(true, Messages.MSG_SONG_NOT_FOUND);
                return r;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get the estimated wait time until the user can sing.
        /// </summary>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileGetWaitTime(long userKey)
        {
            int venueID = -1;
            int mobileID = -1;
            List<queueSinger> queue = new List<queueSinger>();
            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;
                }

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                venueID = r.result;
                if (venueID == -1)
                {
                    r.setErMsg(true, Messages.MSG_NO_VENUE_ASSOCIATED);
                    return r;
                }

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_VENUE_NO_SESSION);
                    return r;
                }

                r = db.GetSongRequests(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                string raw = r.message;
                if (raw.Trim() == "")
                {
                    r.setErMsgRes(false, "0", 0);
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                r = DBToNearlyFullList(raw, out queue, venueID, mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                int time = 0;
                for (int i = 0; i < queue.Count; i++)
                {
                    if (queue[i].user.userID == mobileID)
                        break;
                    else
                        time += queue[i].songs[0].duration + Common.TIME_BETWEEN_REQUESTS;
                }

                r.setErMsgRes(false, time.ToString(), time);
                return r;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Try to remove a users song requests from the venue. If they dont' have any, nothing happens.
        /// </summary>
        /// <param name="mobileID">The user's ID.</param>
        /// <param name="venueID">The venue ID</param>
        /// <param name="db">Database connectivity.</param>
        /// <returns>The outcome of the operation.</returns>
        private ExpResponse MobileTryRemoveAllSongRequests(int mobileID, DatabaseConnectivity db)
        {
            ExpResponse r = new ExpResponse();
            int venueID;
            // Get the venueID
            r = MobileGetVenue(mobileID, db);
            if (r.error)
                return r;
            venueID = r.result;
            if (venueID == -1)
                return r;

            bool validStatus;
            // Make sure the venue is accepting songs.
            r = VenueCheckStatus(venueID, "2", db, out validStatus);
            if (r.error)
                return r;
            if (!validStatus)
                return r;

            // Get the current song Requests
            r = db.GetSongRequests(venueID);
            if (r.error)
                return r;

            string requests = r.message;
            string newRequests = string.Empty;

            if (requests.Trim().Length == 0)
                return r;

            // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
            List<queueSinger> queue;
            r = Common.DBToMinimalList(requests, out queue);
            if (r.error)
                return r;

            // Search to see if the user is already in this list of singers.
            for (int i = 0; i < queue.Count; i++)
            {
                // If the user is found.
                if (queue[i].user.userID == mobileID)
                {
                    queue.RemoveAt(i);

                    Common.MinimalListToDB(queue, out newRequests);
                    r = db.SetSongRequests(venueID, newRequests);
                    if (r.error)
                        return r;

                    Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                    return r;

                }
            }
            return r;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Move a song in a user's song requets new a new position in his/her song requests.
        /// Does not move singers, moves a singer's songs.
        /// </summary>
        /// <param name="sr">The song request to move</param>
        /// <param name="newIndex">The new index to insert the song into.</param>
        /// <param name="DJKey">The unique key that describes the DJ.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response DJMoveSongRequest(SongRequest sr, int newIndex, long DJKey)
        {
            int DJID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ isn't logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Get the current song Requests
                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string requests = r.message;
                string newRequests = string.Empty;

                // If there were no requests, simply add the single request.
                if (requests.Trim().Length == 0)
                {
                    r.error = true;
                    r.message = "The queue is empty";
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return r;

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == sr.user.userID)
                    {
                        // Loop through the songs to see if the user is already singing this song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            // If we find the song.
                            if (queue[i].songs[j].ID == sr.songID)
                            {
                                // Make sure the indexes are in range.
                                if (newIndex < 0)
                                    newIndex = 0;
                                if (newIndex > queue[i].songs.Count - 1)
                                    newIndex = queue[i].songs.Count - 1;

                                // Get the song out, and insert it into the new index.
                                Song temp = queue[i].songs[j];
                                queue[i].songs.RemoveAt(j);
                                queue[i].songs.Insert(newIndex, temp);
                                Common.MinimalListToDB(queue, out newRequests);
                                r = db.SetSongRequests(DJID, newRequests);
                                if (r.error)
                                    return r;
                                if (j == 0 || newIndex == 0)
                                    Common.PushMessageToUsersOfDJ(DJID, "queue", db);
                                else
                                    Common.PushMessageToMobile(sr.user.userID, "queue", db);

                                return r;
                            }

                        }
                        // If we can't find the current song.
                        r.error = true;
                        r.message = "Could not find the song to move.";
                        return r;
                    }
                }

                r.error = true;
                r.message = "Could not find client in the queue.";
                return r;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Removes a song from a user's song requests.
        /// </summary>
        /// <param name="songID">The ID of the song.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileRemoveSongRequest(int songID, long userKey)
        {
            int venueID = -1;
            int mobileID;
            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 MobileIDx
                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;

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                venueID = r.result;

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db);
                if (r.error)
                    return r;

                // Get the current song Requests
                r = db.GetSongRequests(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                string requests = r.message;
                string newRequests = string.Empty;

                if (requests.Trim().Length == 0)
                {
                    r.error = true;
                    r.message = "There are no song requests to remove";
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // If the user is found.
                    if (queue[i].user.userID == mobileID)
                    {
                        // Loop through the songs to find the current song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            if (queue[i].songs[j].ID == songID)
                            {
                                queue[i].songs.RemoveAt(j);
                                if (queue[i].songs.Count == 0)
                                    queue.RemoveAt(i);
                                Common.MinimalListToDB(queue, out newRequests);
                                r = db.SetSongRequests(venueID, newRequests);
                                if(r.error)
                                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                                Common.PushMessageToUsersOfDJ(venueID, "queue", db);

                                return r;
                            }

                        }
                        // If we can't find the current song.
                        r.error = true;
                        r.message = "Could not find the song to remove";
                        return r;
                    }
                }

                r.error = true;
                r.message = "Could not find you in the queue";
                return r;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Add a song request to the queue. Automatically figures out of the user is already in the queue or not.
        /// If the song request userID is > 0, matches based on registered user id.
        /// If the song request userID is 0, matches based in registered user name.
        /// If the song request uesrID is less than 0, matches based on temporary user name.
        /// Automaticlaly creates the temporary user if needed.
        /// </summary>
        /// <param name="sr">The song request to add.</param>
        /// <param name="queueIndex">The position to add the user in, if they don't already have song requests in the queue.</param>
        /// <param name="DJKey">The DJ's assigned key.</param>
        /// <returns>The outcome of the operation. If the operation is sucessful, the client ID number is returned in result and message.</returns>
        public Response DJAddQueue(SongRequest sr, int queueIndex, long DJKey)
        {
            int DJID = -1;
            int songID = -1;
            int clientID = -1;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return r;

                // Convert the DJKey to a DJID
                r = DJKeyToID(DJKey, out DJID, db);
                if (r.error)
                    return r;

                // Make sure the DJ isn't logged out.
                r = DJValidateStatus(DJID, "2", db);
                if (r.error)
                    return r;

                // Check to see if song exists.
                r = db.SongExists(DJID, sr.songID);
                if (r.error)
                    return r;

                // Make sure the songExists method returned a song.
                if (!int.TryParse(r.message.Trim(), out songID))
                {
                    r.error = true;
                    r.message = "Could not find song";
                    return r;
                }

                if (sr.user.userID < -1)
                    sr.user.userID = -1;

                // when userID == -1, we are dealing with creating an anonmymous user.
                if (sr.user.userID == -1)
                {
                    // See if this username exists.
                    r = db.DJValidateTempUserName(sr.user.userName, DJID);
                    if (r.error)
                        return r;
                    // In this case, the username does not exist.
                    if (r.message.Trim().Length == 0)
                    {
                        // Add the tempUser.
                        r = db.DJAddTempUser(sr.user.userName, DJID);
                        if (r.error)
                            return r;
                        // Get the tempUser's ID from the DB.
                        r = db.DJValidateTempUserName(sr.user.userName, DJID);
                        if (r.error)
                            return r;
                        // Parse the ID.
                        if (!int.TryParse(r.message.Trim(), out clientID))
                        {
                            r.error = true;
                            r.message = "Unable to get the clientID of the new user.";
                            return r;
                        }
                    }
                    // In this case, the username already exists.
                    else
                    {
                        // Get the tempUser's ID from the DB.
                        r = db.DJValidateTempUserName(sr.user.userName, DJID);
                        if (r.error)
                            return r;
                        // Parse the ID.
                        if (!int.TryParse(r.message.Trim(), out clientID))
                        {
                            r.error = true;
                            r.message = "Unable to get the clientID of the temp user.";
                            return r;
                        }
                    }
                }
                // When userID == 0, we look the user up by username instead of userID.
                else if (sr.user.userID == 0)
                {
                    r = db.MobileValidateUsername(sr.user.userName);
                    if (r.error)
                        return r;
                    if (!int.TryParse(r.message.Trim(), out clientID))
                    {
                        r.error = true;
                        r.message = "Client name could not be validated.";
                        return r;
                    }
                }
                // If a userID is passed in.
                else
                {
                    r = db.MobileValidateID(sr.user.userID);
                    if (r.error)
                        return r;
                    // See if an ID was returned.
                    if (r.message.Trim() == String.Empty)
                    {
                        string s = r.message.Trim();
                        r.error = true;
                        r.message = "Client ID could not be validated.";
                        return r;
                    }
                    clientID = sr.user.userID;
                }

                // Get the current song Requests
                r = db.GetSongRequests(DJID);
                if (r.error)
                    return r;

                string requests = r.message;
                string newRequests = string.Empty;

                // If there were no requests, simply add the single request.
                if (requests.Trim().Length == 0)
                {
                    newRequests = clientID.ToString() + "~" + sr.songID.ToString();
                    //r = Common.PushMessageToMobile(sr.user.userID, "queue", db);
                    Common.PushMessageToUsersOfDJ(DJID, "queue", db);
                    r = db.SetSongRequests(DJID, newRequests);
                    return r;
                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return r;

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == clientID)
                    {
                        // Loop through the songs to see if the user is already singing this song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            if (queue[i].songs[j].ID == sr.songID)
                            {
                                r.error = true;
                                r.message = "User is already singing that song";
                                return r;
                            }

                        }
                        // They dont' already have the song in the list, add them to the list
                        Song s = new Song();
                        s.ID = sr.songID;
                        queue[i].songs.Add(s);
                        Common.MinimalListToDB(queue, out newRequests);
                        r = db.SetSongRequests(DJID, newRequests);
                        if (r.error)
                            return r;

                        Common.PushMessageToMobile(clientID, "queue", db);
                        //Common.PushMessageToUsersOfDJ(DJID, "queue", db);

                        r.message = clientID.ToString();
                        r.result = clientID;
                        return r;
                    }
                }

                // Now they are not in the queue, add them at queueIndex.
                queueSinger qs = new queueSinger();
                qs.songs = new List<Song>();

                qs.user = sr.user;
                qs.user.userID = clientID;

                Song song = new Song();
                song.ID = sr.songID;
                qs.songs.Add(song);

                if (queueIndex < 0)
                    queueIndex = 0;
                if (queueIndex > queue.Count)
                    queueIndex = queue.Count;
                queue.Insert(queueIndex, qs);
                Common.MinimalListToDB(queue, out newRequests);
                r = db.SetSongRequests(DJID, newRequests);
                if (r.error)
                    return r;

                Common.PushMessageToUsersOfDJ(DJID, "queue", db);

                r.message = clientID.ToString();
                r.result = clientID;
                return r;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Changes a user's song request to a new song.
        /// </summary>
        /// <param name="oldSongID">The old request.</param>
        /// <param name="newSongID">The new request.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileChangeSongRequest(int oldSongID, int newSongID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            bool songChangeMade = false;
            bool requireSendToAll = false;
            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;
                }

                // Get the venueID
                r = MobileGetVenue(mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                venueID = r.result;
                if (venueID == -1)
                {
                    r.setErMsg(true, Messages.MSG_NO_VENUE_ASSOCIATED);
                    return r;
                }

                // Make sure the venue is accepting songs.
                r = VenueCheckStatus(venueID, "2", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_VENUE_NO_SESSION);
                    return r;
                }

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

                // Get the current song Requests
                r = db.GetSongRequests(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                string requests = r.message;
                string newRequests = string.Empty;

                // If there are no song requests.
                if (requests.Trim().Length == 0)
                {
                    r.setErMsg(true, "There are no song requests.");
                    return r;

                }

                // Since there is a list of requests, call to parse the raw string data into an list of queuesingers.
                List<queueSinger> queue;
                r = Common.DBToMinimalList(requests, out queue);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Search to see if the user is already in this list of singers.
                for (int i = 0; i < queue.Count; i++)
                {
                    // We found the userID already in here.
                    if (queue[i].user.userID == mobileID)
                    {
                        // Loop through the songs to find the old song.
                        for (int j = 0; j < queue[i].songs.Count; j++)
                        {
                            // If we find the new song, we don't want to allow duplicates
                            if (queue[i].songs[j].ID == newSongID)
                            {
                                r.setErMsg(true, "You are already singing the new song");
                                return r;
                            }
                            // If we found the old song.
                            if (queue[i].songs[j].ID == oldSongID)
                            {
                                queue[i].songs[j].ID = newSongID;
                                songChangeMade = true;
                                if (j == 0)
                                    requireSendToAll = true;
                            }

                        }

                        if (songChangeMade)
                        {
                            r = Common.MinimalListToDB(queue, out newRequests);
                            if(r.error)
                                return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                            r = db.SetSongRequests(venueID, newRequests);
                            if(r.error)
                                return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                            if (requireSendToAll)
                                Common.PushMessageToUsersOfDJ(venueID, "queue", db);
                            else
                                Common.PushMessageToMobile(mobileID, "queue", db);

                            return r;
                        }
                        // If we couldn't find the old song, inform user.
                        r.setErMsg(true, Messages.MSG_SONG_NOT_FOUND);
                        return r;
                    }
                }

                // If we couldn't find the user.
                r.setErMsg(true, Messages.MSG_USER_NO_SONG_REQUESTS);
                return r;
            }
        }