Пример #1
0
        public static TrackListItem Create(JsonElement element)
        {
            var item = new TrackListItem();

            foreach (var property in element.EnumerateObject())
            {
                switch (property.Name)
                {
                case "title":
                    item.Title = property.Value.GetString();
                    break;

                case "type_":
                    item.Type = property.Value.GetString();
                    break;

                case "position":
                    item.Position = int.Parse(property.Value.GetString());
                    break;

                case "duration":
                    item.Duration = TimeSpan.Parse(property.Value.GetString());
                    break;

                case "extraartists":
                    item.ExtraArtists = new List <ArtistRef>();
                    foreach (var extraArtist in property.Value.EnumerateArray())
                    {
                        item.ExtraArtists.Add(ArtistRef.Create(extraArtist));
                    }
                    break;

                default:
                    throw new Exception(string.Format("Unrecognised parameter when creating the Discogs TrackListItem Object. Parameter is: {0}", property.Name));
                }
            }

            return(item);
        }
Пример #2
0
        public static ArtistRef Create(JsonElement element)
        {
            ArtistRef img = new ArtistRef();

            foreach (var property in element.EnumerateObject())
            {
                switch (property.Name)
                {
                case "join":
                    img.JoinWith = property.Value.GetString();
                    break;

                case "name":
                    img.Name = property.Value.GetString();
                    break;

                case "id":
                    img.Id = property.Value.GetInt32();
                    break;

                case "anv":
                    img.NameVariation = property.Value.GetString();
                    break;

                case "role":
                    img.Role = property.Value.GetString();
                    break;

                case "resource_url":
                    img.ResourceURI = property.Value.GetString();
                    break;

                default:
                    throw new Exception(string.Format("Unrecognised parameter when creating the Discogs ArtistRef Object. Parameter is: {0}", property.Name));
                }
            }
            return(img);
        }
Пример #3
0
        public static Master Create(JsonElement element)
        {
            var master = new Master();
            foreach (var property in element.EnumerateObject())
            {
                switch (property.Name)
                {
                    case "styles":
                        master.Styles = new List<string>();
                        foreach (var style in property.Value.EnumerateArray())
                        {
                            master.Styles.Add(style.GetString());
                        }
                        break;
                    case "genres":
                        master.Genres = new List<string>();
                        foreach (var genre in property.Value.EnumerateArray())
                        {
                            master.Genres.Add(genre.GetString());
                        }
                        break;
                    case "videos":
                        master.Videos = new List<VideoRef>();
                        foreach (var genre in property.Value.EnumerateArray())
                        {
                            master.Videos.Add(VideoRef.Create(genre));
                        }
                        break;
                    case "title":
                        master.Title = property.Value.GetString();
                        break;
                    case "main_release":
                        master.ReleaseId = property.Value.GetInt32();
                        break;
                    case "main_release_url":
                        master.ReleaseURI = property.Value.GetString();
                        break;
                    case "uri":
                        master.WebURL = property.Value.GetString();
                        break;
                    case "artists":
                        master.Artists = new List<ArtistRef>();
                        foreach (var artist in property.Value.EnumerateArray())
                        {
                            master.Artists.Add(ArtistRef.Create(artist));
                        }
                        break;
                    case "versions_url":
                        master.VersionsURI = property.Value.GetString();
                        break;
                    case "year":
                        master.Year = property.Value.GetInt32();
                        break;
                    case "images":
                        master.Images = new List<Image>();
                        foreach (var img in property.Value.EnumerateArray())
                        {
                            master.Images.Add(Image.Create(img));
                        }
                        break;
                    case "resource_url":
                        master.ResourceURI = property.Value.GetString();
                        break;
                    case "tracklist":
                        master.Tracklist = new List<TrackListItem>();
                        foreach (var track in property.Value.EnumerateArray())
                        {
                            master.Tracklist.Add(TrackListItem.Create(track));
                        }
                        break;
                    case "id":
                        master.Id = property.Value.GetInt32();
                        break;
                    case "num_for_sale":
                        master.NumberForSale = property.Value.GetInt32();
                        break;
                    case "lowest_price":
                        master.LowestPrice = property.Value.GetDouble();
                        break;
                    case "data_quality":
                        master.DataQulity = property.Value.GetString();
                        break;
                    default:
                        throw new ArgumentException("Unrecognised parameter when creating the Discogs Master Object.", property.Name);
                }
            }

            return master;
        }