public override void FromXml(XElement artistXml)
{
// ReSharper disable PossibleNullReferenceException
string uriString;
if (artistXml.Descendants("image")
.FirstOrDefault(x => x.Attribute("size").Value == "medium") != null)
{
uriString = artistXml.Descendants("image")
.FirstOrDefault(x => x.Attribute("size").Value == "medium")
.Value;
}
else
{
uriString = artistXml.Descendants("image")
.FirstOrDefault()
.Value;
}
BitmapImage img = null;
if (!string.IsNullOrEmpty(uriString))
img = new BitmapImage(new Uri(uriString));
Name = artistXml.Element("name").Value;
MusicBrainzId = artistXml.Element("mbid").Value;
if (artistXml.Element("match") == null
|| string.IsNullOrEmpty(artistXml.Element("match").Value))
SimilarMatch = 0;
else
SimilarMatch = (int)Math.Round(Convert.ToDouble(artistXml.Element("match").Value), 0);
Url = new Uri(artistXml.Element("url").Value, UriKind.RelativeOrAbsolute);
if (img != null) PictureSmall = img;
// ReSharper restore PossibleNullReferenceException
// ReSharper disable PossibleNullReferenceException
uriString = artistXml.Descendants("image")
.FirstOrDefault(descendant => descendant.Attribute("size").Value == "large")
.Value;
img = null;
if (!string.IsNullOrEmpty(uriString))
img = new BitmapImage(new Uri(uriString));
if (img != null) Picture = img;
uriString = artistXml.Descendants("image")
.FirstOrDefault(descendant => descendant.Attribute("size").Value == "mega")
.Value;
img = null;
if (!string.IsNullOrEmpty(uriString))
img = new BitmapImage(new Uri(uriString));
if (img != null) PictureLarge = img;
Listeners = artistXml.Descendants("listeners").FirstOrDefault() == null
? 0
: Convert.ToInt32(artistXml.Descendants("listeners").FirstOrDefault().Value);
Streamable = artistXml.Element("streamable").Value != "0";
if (artistXml.Element("weight") != null
&& !string.IsNullOrEmpty(artistXml.Element("weight").Value))
{
Weight = Convert.ToDouble(artistXml.Element("weight").Value, new CultureInfo("en-US"));
}
// ReSharper restore PossibleNullReferenceException
}
}