Exemplo n.º 1
0
        internal static IEnumerable<Album> getListOfAlbums(GrooveSharp grooveSharp, string json)
        {
            List<Album> _retVal = new List<Album>();
            var _data = Snippet.ToXElementCollection(json);

            _data.Where(e => e.Name == "albums").Select(e => e).ToList().ForEach(e =>
                {
                    Artist _artist = new Artist()
                    {
                        ID = Convert.ToInt32(e.Elements().Where(i => i.Name == "ArtistID").First().Value),
                        Name = e.Elements().Where(i => i.Name == "ArtistName").First().Value
                    };

                    Album _album = new Album()
                    {
                        ID = Convert.ToInt32(e.Elements().Where(i => i.Name == "AlbumID").First().Value),
                        Name = e.Elements().Where(i => i.Name == "AlbumName").First().Value,
                        CoverArtFileName = e.Elements().Where(i => i.Name == "CoverArtFilename").First().Value,
                        IsVerified = Convert.ToBoolean(e.Elements().Where(i => i.Name == "IsVerified").First().Value),
                        Artist = _artist,
                        grooveSharp = grooveSharp
                    };

                    _retVal.Add(_album);
                });

            return _retVal;
        }
Exemplo n.º 2
0
        internal static IEnumerable<Song> parseToList(GrooveSharp grooveSharp, string json)
        {
            List<Song> _retVal = new List<Song>();
            var _el = Snippet.ToXElementCollection(json);

            _el.Where(e => e.Name == "songs").ToList().ForEach(e =>
            {
                var _inner = e.Elements();
                Artist _artist = new Artist()
                {
                    ID = Convert.ToInt32(_inner.Where(i => i.Name == "ArtistID").First().Value),
                    Name = _inner.Where(i => i.Name == "ArtistName").First().Value
                };

                Album _album = new Album()
                {
                    ID = Convert.ToInt32(_inner.Where(i => i.Name == "AlbumID").First().Value),
                    Name = _inner.Where(i => i.Name == "AlbumName").First().Value,
                    CoverArtFileName = _inner.Where(i => i.Name == "CoverArtFilename").First().Value,
                    Artist = _artist
                };

                var _ver = _inner.Where(i => i.Name == "IsVerified").First().Value;
                var _lowB = _inner.Where(i => i.Name == "IsLowBitrateAvailable").First().Value;

                if (_ver == "1")
                    _ver = "True";
                else if (_ver == "0")
                    _ver = "False";

                if (_lowB == "1")
                    _lowB = "True";
                else if (_lowB == "0")
                    _lowB = "False";

                bool _isVerified = Convert.ToBoolean(_ver);
                bool _isLowBitRate = Convert.ToBoolean(_lowB);

                Song _song = new Song()
                {
                    Album = _album,
                    ID = Convert.ToInt32(_inner.Where(i => i.Name == "SongID").First().Value),
                    Title = _inner.Where(i => i.Name == "SongName").First().Value,
                    Artist = _artist,
                    Popularity = Convert.ToInt64(_inner.Where(i => i.Name == "Popularity").First().Value),
                    IsLowBitrateAvailable = _isLowBitRate,
                    IsVerified = _isVerified,
                    Flags = Convert.ToInt32(_inner.Where(i => i.Name == "Flags").First().Value)
                };

                _song.grooveSharp = grooveSharp;

                _retVal.Add(_song);
            });

            return _retVal.AsEnumerable();
        }