示例#1
0
        /// <summary>
        /// Attempts to find and download the album's publication date, description, number of tracks and cover image.
        /// </summary>
        public Album FindAlbum(String albumTitle, String artistName)
        {
            XmlDocument document;

            try
            {
                document = GetResponseXml(String.Format("{0}/album/info.xml?album={1}&artist={2}", baseUrl, albumTitle, artistName));
            }
            catch { throw new NoMatchFound(String.Format("Nessun match trovato per '{0}' di '{1}'.", albumTitle, artistName)); }

            XmlElement root = document.DocumentElement;

            XmlNode node = root.SelectSingleNode("/album/releasedate");

            DateTime publicationDate = DateTime.Parse(node.InnerText.Trim(), System.Globalization.CultureInfo.GetCultureInfo("en"));

            String description  = root.GetValue <String>("/album/wiki/content");
            Int32  tracksNumber = root.SelectSingleNode("/album/tracks").ChildNodes.Count;

            Album result = database.Album.FindByName(albumTitle);

            result.TrackNumber     = (Byte)tracksNumber;
            result.Notes           = description;
            result.PublicationDate = publicationDate;

            Byte[] coverImage = this.DownloadBinaryImage(root, "/album/image");

            if (coverImage != null)
            {
                Cover cover = Cover.CreateCover(database.Covers.GetNextID(), result.ID);
                cover.Front = coverImage;
                database.AddToCovers(cover);
            }

            //database.SaveChanges();
            return(result);
        }