Beispiel #1
0
        /// <summary>
        /// Allow a client to join a venue via QR code.
        /// </summary>
        /// <param name="QR">The QR code of the venue.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileJoinVenue(string QR, long userKey)
        {
            int mobileID = -1;
            int venueID = -1;
            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 venue of this qr string.
                r = db.GetVenueIDByQR(QR.Trim());
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Parse the venueID.
                if (!int.TryParse(r.message.Trim(), out venueID))
                {
                    r.error = true;
                    r.message = "Could not match QR code to a venue";
                    return r;
                }

                // Set the venue of the client
                r = db.MobileSetVenue(mobileID, venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                r = db.GetVenueName(venueID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                r.result = venueID;
                return r;
            }
        }
Beispiel #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;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Allow a client to join a venue via QR code.
        /// </summary>
        /// <param name="QR">The QR code of the venue.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileJoinVenue(string QR, long userKey)
        {
            int mobileID = -1;
            int venueID = -1;
            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 venue of this qr string.
                r = db.GetVenueIDByQR(QR.Trim());
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (r.message.Trim().Length == 0)
                {
                    r.setErMsg(true, Messages.ERR_QR_BAD);
                    return r;
                }

                // Parse the venueID.
                if (!int.TryParse(r.message.Trim(), out venueID))
                {
                    r.setErMsgStk(true, "QR code couldnot be parsed from db", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // 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 if the user is banned
                bool userBanned;
                r = db.MobileIsBanned(venueID, mobileID, out userBanned);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                if (userBanned)
                {
                    r.setErMsg(true, Messages.MSG_USER_BANNED);
                    return r;
                }

                // Set the venue of the client
                r = db.MobileSetVenue(mobileID, venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Run the achievements on this venue, upon error, simply log the error.
                r = Common.RunAchievements(venueID, db);
                if(r.error)
                    Common.LogErrorPassThru(r, Common.LogFile.Mobile);

                r = db.GetVenueName(venueID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                r.result = venueID;
                return r;
            }
        }
Beispiel #4
0
        /// <summary>
        /// View the song history of the client.
        /// </summary>
        /// <param name="start">The index of the first result.</param>
        /// <param name="count">The number of results to return.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public List<SongHistory> MobileViewSongHistory(int start, int count, long userKey)
        {
            int mobileID = -1;
            List<SongHistory> songHistory = new List<SongHistory>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0);

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

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

                r = db.MobileGetSongHistory(mobileID, start, count);
                if (r.error)
                    return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0);

                // Case of empty playlists.
                if (r.message.Trim().Length == 0)
                    return songHistory;

                //"ID", "VenueID", "MobileID", "SongID", "DateSung"
                try
                {
                    string[] songHistoryLines = r.message.Trim().Split('\n');
                    foreach (string songHistoryLine in songHistoryLines)
                    {
                        string[] songHistoryParts = Common.splitByDel(songHistoryLine);
                        SongHistory sh = new SongHistory();

                        int vid;
                        if (!int.TryParse(songHistoryParts[1], out vid))
                            return (List<SongHistory>)Common.LogError("MobileGetSongHistory venueID parse fail from MobileSongHistory.", Environment.StackTrace, null, 0);
                        sh.venue = new Venue();
                        sh.venue.venueID = vid;

                        r = db.GetVenueName(vid);
                        if (r.error)
                            return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                        sh.venue.venueName = r.message.Trim();

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

                        int songID;
                        if(!int.TryParse(songHistoryParts[3], out songID))
                            return (List<SongHistory>)Common.LogError("MobileGetSongHistory songID parse fail from MobileSongHistory.", Environment.StackTrace, null, 0);

                        Song song;
                        r = Common.GetSongInformation(songID, vid, mobileID,out song, db, false);
                        if(r.error)
                            return (List<SongHistory>)Common.LogError(r.message, Environment.StackTrace, null, 0);
                        sh.song = song;
                        sh.date = Convert.ToDateTime(songHistoryParts[4]);
                        songHistory.Add(sh);
                    }
                    return songHistory;
                }
                catch (Exception e)
                {
                    return (List<SongHistory>)Common.LogError(e.Message, e.StackTrace, null, 0);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// View the song history of the client.
        /// </summary>
        /// <param name="start">The index of the first result.</param>
        /// <param name="count">The number of results to return.</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public List<SongHistory> MobileViewSongHistory(int start, int count, long userKey)
        {
            int mobileID = -1;
            List<SongHistory> songHistory = new List<SongHistory>();
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);

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

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsgStk(true, "User: "******" has invalid status", Environment.StackTrace);
                    return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);
                }

                r = db.MobileGetSongHistory(mobileID, start, count, out songHistory);
                if (r.error)
                    return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);

                for (int i = 0; i < songHistory.Count; i++)
                {
                    r = db.GetVenueName(songHistory[i].venue.venueID);
                    if (r.error)
                        return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);
                    songHistory[i].venue.venueName = r.message.Trim();
                    r = db.GetVenueAddress(songHistory[i].venue.venueID);
                    if (r.error)
                        return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);
                    songHistory[i].venue.venueAddress = r.message.Trim();

                    Song song;
                    r = Common.GetSongInformation(songHistory[i].song.ID, songHistory[i].venue.venueID, mobileID, out song, db, false);
                    if (r.error)
                        return Common.LogErrorRetGen<List<SongHistory>>(r, null, Common.LogFile.Mobile);
                    songHistory[i].song = song;
                }

                return songHistory;
            }
        }