using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.ComponentModel.DataAnnotations;

namespace MainTestApplication
{
    public class Song
    {
        [Display(Name = "Name")]
        public string Name { get; set; }

        [Display(Name = "Album")]
        public string Album { get; set; }

        [Display(Name = "Artist")]
        public string Artist { get; set; }

        [Display(Name = "Duration")]
        public long Duration { get; set; }  // in milliseconds

        [Display(Name = "Size")]
        public long Size { get; set; }      // in bytes

        [Display(Name = "Rating")]
        public int Rating { get; set; }     // from 0 to 5
    }

    public class MediaLibrary
    {
        public static List<Song> Load()
        {
            var asm = Assembly.GetExecutingAssembly();
            foreach (var res in asm.GetManifestResourceNames())
            {
                if (res.EndsWith("songs.xml"))
                {
                    using (var stream = asm.GetManifestResourceStream(res))
                    {
                        var xmls = new XmlSerializer(typeof(List<Song>));
                        return (List<Song>)xmls.Deserialize(stream);
                    }
                }
            }
            throw new Exception("Can't find 'songs.xml' embedded resource.");
        }
    }
}
