Example #1
0
        protected void Clear()
        {
            if (PreviousSongs == null) PreviousSongs = new List<PandoraSong>();
            if (AvailableStations == null) AvailableStations = new List<PandoraStation>();

            _currentStation = null;
            CurrentSong = null;
            PreviousSongs.Clear();
            AvailableStations.Clear();
            SkipHistory = null;
            User = null;
            playlist.Clear();
        }
Example #2
0
        /// <summary>
        /// Try to execute the supplied logic, if we get an authentication error, relogin and try again.
        /// </summary>
        /// <param name="logic"></param>
        protected void VerifyAndExecute(ExecuteDelegate logic)
        {
            try { logic(); }
            catch (PandoraException ex) {
                // if there was an error and it was NOT an expired session, just toss it up to the client
                if (ex.ErrorCode != ErrorCodeEnum.AUTH_INVALID_TOKEN && ex.ErrorCode != ErrorCodeEnum.INSUFFICIENT_CONNECTIVITY)
                    throw;

                // this is an AUTH_INVALID_TOKEN error meaning our login expired, try logging in again
                Session = pandora.PartnerLogin(Proxy);
                User = pandora.UserLogin(Session, User.Name, User.Password, Proxy);

                playlist.Clear();
                if (Session == null || User == null) throw new PandoraException("Username and/or password are no longer valid!");

                // and again, try the desired action
                logic();
            }
        }
Example #3
0
        /// <summary>
        /// Logs into Pandora with the given credentials.
        /// </summary>
        /// <returns>true if the user was successfully logged in.</returns>
        public bool Login(string username, string password)
        {
            Clear();

            Session = pandora.PartnerLogin(Proxy);
            User = pandora.UserLogin(Session, username, password, Proxy);
            if (User != null && User.CanListen) {
                SkipHistory = new SkipHistory(User);

                AvailableStations = pandora.GetStations(Session, Proxy);
                pandora.GetGenreStations(Session, Proxy);

                // try to grab the first station in the list that is not the quickmix station
                foreach (PandoraStation currStation in AvailableStations)
                    if (!currStation.IsQuickMix) {
                        CurrentStation = currStation;
                        break;
                    }

                return true;
            }

            Clear();
            return false;
        }