Ejemplo n.º 1
0
        /// <summary>
        /// Debug method to insert batch song history into the database. Allows for somewhat realistic song histories to
        /// be created easily. Will take in a list of bands, and find numberPerBand random songs per band and add them to
        /// the song history of the user with the given mobileID.
        /// </summary>
        /// <param name="DJKey">The Venue's unique key.</param>
        /// <param name="bands">A list of bands.</param>
        /// <param name="numberPerBand">The number of songs to add per band.</param>
        /// <param name="mobileID">The user to add these songs to.</param>
        /// <returns>The outcome of the operation.</returns>
        public Response InsertFauxSongHistory(long DJKey, List<string> bands, int numberPerBand, int mobileID)
        {
            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;

                string extraMessage = string.Empty;
                foreach (string band in bands)
                {
                    List<int> songIDs = new List<int>();
                    r = db.GetRandomSongsForArtist(band, DJID, numberPerBand, out songIDs);
                    if (r.error)
                        extraMessage += "Error looking for : " + band + "\n" + r.message;

                    for (int i = 0; i < songIDs.Count; i++)
                    {
                        r = db.MobileAddSongHistory(mobileID, DJID, songIDs[i], DateTime.Now);
                        if (r.error)
                            return r;
                    }
                    r.message = extraMessage;
                }
                return r;
            }
        }
Ejemplo n.º 2
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;
            }
        }