Example #1
0
        internal static List<Playlist> parseToList(GrooveSharp grooveSharp, string jsonData)
        {
            List<Playlist> _playlist = new List<Playlist>();
            var _data = Snippet.ToXElementCollection(jsonData);

            _data.Where(e => e.Name == "playlists").Select(e => e).ToList().ForEach(e =>
                {
                    User _user = new User();

                    try
                    {
                        _user.ID = Convert.ToInt32(e.Elements().Where(i => i.Name == "UserID").First().Value);
                        _user.FirstName = e.Elements().Where(i => i.Name == "FName").First().Value;
                        _user.LastName = e.Elements().Where(i => i.Name == "LName").First().Value;
                    }
                    catch { }

                    DateTime _dateTime = DateTime.Now;

                    try
                    {
                        _dateTime = DateTime.Parse(e.Elements().Where(i => i.Name == "TSAdded").First().Value);
                    }
                    catch { }

                    Playlist _p = new Playlist()
                    {
                        ID = Convert.ToInt32(e.Elements().Where(i => i.Name == "PlaylistID").First().Value),
                        Name = e.Elements().Where(i => i.Name == "PlaylistName").First().Value,
                        Added = _dateTime,
                        User = _user,
                        grooveSharp = grooveSharp
                    };

                    _playlist.Add(_p);
                });

            return _playlist;
        }
Example #2
0
        internal static User Parse(GrooveSharp grooveSharp, string jsonData)
        {
            var _el = Snippet.ToXElementCollection(jsonData);

            string _email = (_el.Where(e => e.Name == "Email").FirstOrDefault() == null) ?
                "" : _el.Where(e => e.Name == "Email").FirstOrDefault().Value;

            User _user = new User()
            {
                ID = Convert.ToInt32(_el.Where(e => e.Name == "UserID").First().Value),
                LastName = _el.Where(e => e.Name == "LName").First().Value,
                FirstName = _el.Where(e => e.Name == "FName").First().Value,
                IsPlus = Convert.ToBoolean(_el.Where(e => e.Name == "IsPlus").First().Value),
                IsPremium = Convert.ToBoolean(_el.Where(e => e.Name == "IsPremium").First().Value),
                IsAnywhere = Convert.ToBoolean(_el.Where(e => e.Name == "IsAnywhere").First().Value),
                Email = _email
            };

            _user.grooveSharp = grooveSharp;

            return _user;
        }
        public bool Login(string username, string token)
        {
            try
            {
                User _response = this.login(username, token);

                if (_response.Email != null)
                {
                    if (_response.ID == 0)
                        return false;
                }

                user = _response;

                return _response.Email != null;
            }
            catch(GrooveException)
            {
                throw;
            }
        }
        /// <summary>
        /// Initialize the session to access the web service.
        /// </summary>
        /// <returns>Returns the string representation of the session key.</returns>
        public string InitializeSession()
        {
            if (string.IsNullOrEmpty(APIData.SessionData))
            {
                string _response = this.startSession();
                APIData.SessionData = Snippet.ToXElementCollection(_response).Where(e => e.Name == "sessionID").First().Value;
            }

            SessionKey = APIData.SessionData;

            GrooveCountry = this.getCountry();
            User _currentUser = this.getUserInfo();

            if (_currentUser.ID == 0)
                user = null;
            else
                user = _currentUser;

            return APIData.SessionData;
        }