コード例 #1
0
ファイル: DataReader3.cs プロジェクト: MediaPortal/MPTagThat
        public Artist ReadArtist(JObject source)
        {
            Artist artist = new Artist();
            foreach (var item in source)
            {
                var v = item.Value;

                switch (item.Key)
                {
                    case "id":
                        artist.Id = v.Value<int>();
                        break;
                    case "name":
                        artist.Name = v.Value<string>();
                        break;
                    case "profile":
                        artist.Profile = v.Value<string>();
                        break;
                    case "realname":
                        artist.RealName = v.Value<string>();
                        break;
                    case "releases_url":
                        break;
                    case "urls":
                        artist.Urls = v.ValueAsStringArray();
                        break;
                    case "images":
                        artist.Images = this.ReadImages(v.Value<JArray>());
                        break;
                    case "aliases":
                        artist.Aliases = v.Value<JArray>().Cast<JObject>().Select(t => this.ReadArtistAlias(t)).ToArray();
                        break;
                    case "members":
                        artist.Members = v.Value<JArray>().Cast<JObject>().Select(t => this.ReadMembers(t)).ToArray();
                        break;
                    case "uri":
                        break;
                    case "resource_url":
                        break;
                    case "data_quality":
                        artist.DataQuality = DataReader.ParseDataQuality(v.Value<string>());
                        break;
                    case "namevariations":
                        artist.NameVariations = v.ValueAsStringArray();
                        break;
                    default:
                        this.ThrowIfStrict("Unknown key: " + item.Key);
                        break;
                }
            }

            return artist;
        }
コード例 #2
0
ファイル: DataReader.cs プロジェクト: MediaPortal/MPTagThat
        public static Artist ReadArtist(XElement artist)
        {
            artist.AssertName("artist");
            artist.AssertNoAttributes();

            Artist result = new Artist();
            foreach (XElement e in artist.Elements())
            {
                if (e.Name == "images")
                {
                    result.Images = e.Elements().Select(image => ReadImage(image)).ToArray();
                }
                else if (e.Name == "name")
                {
                    e.AssertOnlyText();
                    result.Name = e.Value;
                }
                else if (e.Name == "realname")
                {
                    e.AssertOnlyText();
                    result.RealName = e.Value;
                }
                else if (e.Name == "namevariations")
                {
                    result.NameVariations = e.Elements().AssertNames("name").AssertOnlyText().Select(nameVariation => nameVariation.Value).ToArray();
                }
                else if (e.Name == "aliases")
                {
                    result.Aliases = e.Elements().AssertNames("name").AssertOnlyText().Select(alias => new ArtistAlias() { Name = alias.Value }).ToArray();
                }
                else if (e.Name == "members")
                {
                    result.Members = e.Elements().AssertNames("name").AssertOnlyText().Select(member => new Members() { Name = member.Value }).ToArray();
                }
                else if (e.Name == "profile")
                {
                    e.AssertOnlyText();
                    result.Profile = e.Value.TrimAndNormalizeLineEndings();
                }
                else if (e.Name == "urls")
                {
                    result.Urls = e.Elements().AssertNames("url").AssertOnlyText().Select(url => url.Value).ToArray();
                }
                else if (e.Name == "groups")
                {
                    result.Groups = e.Elements().AssertNames("name").AssertOnlyText().Select(group => group.Value).ToArray();
                }
                else if (e.Name == "releases")
                {
                    result.Releases = e.Elements().Select(release => ReadArtistRelease(release)).ToArray();
                }
                else
                {
                    throw new Exception("Unknown artist element: " + e.Name);
                }
            }
            return result;
        }
コード例 #3
0
        public Artist ReadArtist(JObject source)
        {
            Artist artist = new Artist();

            foreach (var item in source)
            {
                var v = item.Value;

                switch (item.Key)
                {
                case "id":
                    artist.Id = v.Value <int>();
                    break;

                case "name":
                    artist.Name = v.Value <string>();
                    break;

                case "profile":
                    artist.Profile = v.Value <string>();
                    break;

                case "realname":
                    artist.RealName = v.Value <string>();
                    break;

                case "releases_url":
                    break;

                case "urls":
                    artist.Urls = v.ValueAsStringArray();
                    break;

                case "images":
                    artist.Images = this.ReadImages(v.Value <JArray>());
                    break;

                case "aliases":
                    artist.Aliases = v.Value <JArray>().Cast <JObject>().Select(t => this.ReadArtistAlias(t)).ToArray();
                    break;

                case "members":
                    artist.Members = v.Value <JArray>().Cast <JObject>().Select(t => this.ReadMembers(t)).ToArray();
                    break;

                case "uri":
                    break;

                case "resource_url":
                    break;

                case "data_quality":
                    artist.DataQuality = DataReader.ParseDataQuality(v.Value <string>());
                    break;

                case "namevariations":
                    artist.NameVariations = v.ValueAsStringArray();
                    break;

                default:
                    this.ThrowIfStrict("Unknown key: " + item.Key);
                    break;
                }
            }

            return(artist);
        }
コード例 #4
0
ファイル: DataReader2.cs プロジェクト: MediaPortal/MPTagThat
        public Artist ReadArtist()
        {
            this.XmlReader.AssertElementStart("artist");

            Artist artist = new Artist();

            while (true)
            {
                this.XmlReader.AssertRead();

                if (this.XmlReader.IsElementEnd("artist"))
                {
                    break;
                }

                if (this.XmlReader.IsElementStart("images"))
                {
                    artist.Images = this.ReadImages();
                }
                else if (this.XmlReader.IsElementStart("id"))
                {
                    this.XmlReader.AssertNonEmptyElement();
                    this.XmlReader.AssertRead();
                    artist.Id = int.Parse(this.XmlReader.ReadContentAsString());
                }
                else if (this.XmlReader.IsElementStart("name"))
                {
                    if (!this.XmlReader.IsEmptyElement)
                    {
                        this.XmlReader.AssertRead();
                        artist.Name = this.XmlReader.ReadContentAsString();
                    }
                }
                else if (this.XmlReader.IsElementStart("realname"))
                {
                    this.XmlReader.AssertNonEmptyElement();
                    this.XmlReader.AssertRead();
                    artist.RealName = this.XmlReader.ReadContentAsString();
                }
                else if (this.XmlReader.IsElementStart("realname"))
                {
                    this.XmlReader.AssertNonEmptyElement();
                    this.XmlReader.AssertRead();
                    artist.RealName = this.XmlReader.ReadContentAsString();
                }
                else if (this.XmlReader.IsElementStart("profile"))
                {
                    this.XmlReader.AssertNonEmptyElement();
                    this.XmlReader.AssertRead();
                    artist.Profile = this.XmlReader.ReadContentAsString().Trim();
                }
                else if (this.XmlReader.IsElementStart("data_quality"))
                {
                    this.XmlReader.AssertNonEmptyElement();
                    this.XmlReader.AssertRead();
                    artist.DataQuality = DataReader.ParseDataQuality(this.XmlReader.ReadContentAsString());
                }
                else if (this.XmlReader.IsElementStart("urls"))
                {
                    artist.Urls = this.ReadUrls();
                }
                else if (this.XmlReader.IsElementStart("namevariations"))
                {
                    artist.NameVariations = this.ReadNameVariations();
                }
                else if (this.XmlReader.IsElementStart("aliases"))
                {
                    artist.Aliases = this.ReadAliases();
                }
                else if (this.XmlReader.IsElementStart("groups"))
                {
                    artist.Groups = this.ReadGroups();
                }
                //else if (this.XmlReader.IsElementStart("members"))
                //{
                //    artist.Members = this.ReadMembers();
                //}
                else
                {
                    this.ThrowInvalidFormatException();
                }
            }

            return artist;
        }
コード例 #5
0
 public ArtistAggregate(Artist artist)
 {
     this.artist = artist;
 }