|
|
|
@ -1,203 +1,613 @@
|
|
|
|
|
using Model.Stub;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Model.Serialization;
|
|
|
|
|
|
|
|
|
|
public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private List<Artist> artists;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Artist> Artists
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return artists.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Album> albums;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Album> Albums
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return albums.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Playlist> playlists;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Playlist> Playlists
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return playlists.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<InfoTitle> infoTitles;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<InfoTitle> InfoTitles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return infoTitles.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<CustomTitle> customTitles;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<CustomTitle> CustomTitles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return customTitles.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LINQ_XML_Serialization()
|
|
|
|
|
{
|
|
|
|
|
playlists = new List<Playlist>();
|
|
|
|
|
artists = new List<Artist>();
|
|
|
|
|
albums = new List<Album>();
|
|
|
|
|
infoTitles = new List<InfoTitle>();
|
|
|
|
|
customTitles = new List<CustomTitle>();
|
|
|
|
|
LoadPlaylists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddAlbum(Album album)
|
|
|
|
|
{
|
|
|
|
|
albums.Add(album);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddArtist(Artist artist)
|
|
|
|
|
{
|
|
|
|
|
artists.Add(artist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddCustomTitle(CustomTitle title)
|
|
|
|
|
{
|
|
|
|
|
customTitles.Add(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddInfoTitle(InfoTitle title)
|
|
|
|
|
{
|
|
|
|
|
infoTitles.Add(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddPlaylist(Playlist playlist)
|
|
|
|
|
{
|
|
|
|
|
playlists.Add(playlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Album> GetAlbums()
|
|
|
|
|
{
|
|
|
|
|
return albums;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Artist> GetArtists()
|
|
|
|
|
{
|
|
|
|
|
return artists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<CustomTitle> GetCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
return customTitles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<InfoTitle> GetInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
return infoTitles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Playlist> GetPlaylists()
|
|
|
|
|
{
|
|
|
|
|
return playlists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAlbum(Album album)
|
|
|
|
|
{
|
|
|
|
|
albums.Remove(album);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveArtist(Artist artist)
|
|
|
|
|
{
|
|
|
|
|
artists.Remove(artist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveCustomTitle(CustomTitle title)
|
|
|
|
|
{
|
|
|
|
|
customTitles.Remove(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveInfoTitle(InfoTitle title)
|
|
|
|
|
{
|
|
|
|
|
infoTitles.Remove(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemovePlaylist(Playlist playlist)
|
|
|
|
|
{
|
|
|
|
|
playlists.Remove(playlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadPlaylists()
|
|
|
|
|
{
|
|
|
|
|
XDocument PlaylistsFichier = XDocument.Load("playlists.xml");
|
|
|
|
|
|
|
|
|
|
playlists = PlaylistsFichier.Descendants("playlist")
|
|
|
|
|
.Select(eltPlaylist => new Playlist(
|
|
|
|
|
eltPlaylist.Attribute("Name")!.Value,
|
|
|
|
|
eltPlaylist.Element("Description")!.Value,
|
|
|
|
|
eltPlaylist.Element("ImageURL")!.Value
|
|
|
|
|
)).ToList();
|
|
|
|
|
foreach(Playlist playlist in playlists)
|
|
|
|
|
{
|
|
|
|
|
var custom = PlaylistsFichier.Descendants("playlist")
|
|
|
|
|
.Single(ct => ct.Attribute("Name")?.Value == playlist.Name)
|
|
|
|
|
.Element("Customs");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SavePlaylists()
|
|
|
|
|
{
|
|
|
|
|
XDocument PlaylistsFichier = new XDocument();
|
|
|
|
|
|
|
|
|
|
var playlist = playlists.Select(playlist => new XElement("playlist",
|
|
|
|
|
new XAttribute("Name", playlist.Name),
|
|
|
|
|
new XElement("Description", playlist.Description),
|
|
|
|
|
new XElement("ImageURL", playlist.ImageURL)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
|
|
|
|
using(TextWriter tw = File.CreateText("playlists.xml"))
|
|
|
|
|
{
|
|
|
|
|
using(XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
PlaylistsFichier.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using Model.Stub;
|
|
|
|
|
using System.Diagnostics.Metrics;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using static System.Reflection.Metadata.BlobBuilder;
|
|
|
|
|
using System.Reflection.Metadata;
|
|
|
|
|
|
|
|
|
|
namespace Model.Serialization;
|
|
|
|
|
|
|
|
|
|
public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
{
|
|
|
|
|
private static string XMLPATH = @"D:\Data\";
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEPLAYLISTS = "playlists.xml";
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEALBUMS = "albums.xml";
|
|
|
|
|
|
|
|
|
|
private static string XMLFILECUSTOMS = "customs.xml";
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEINFOS = "infos.xml";
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEARTISTS = "artists.xml";
|
|
|
|
|
|
|
|
|
|
private List<Artist> artists;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Artist> Artists
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return artists.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Album> albums;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Album> Albums
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return albums.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Playlist> playlists;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Playlist> Playlists
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return playlists.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<InfoTitle> infoTitles;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<InfoTitle> InfoTitles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return infoTitles.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<CustomTitle> customTitles;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<CustomTitle> CustomTitles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return customTitles.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LINQ_XML_Serialization()
|
|
|
|
|
{
|
|
|
|
|
playlists = new List<Playlist>();
|
|
|
|
|
artists = new List<Artist>();
|
|
|
|
|
albums = new List<Album>();
|
|
|
|
|
infoTitles = new List<InfoTitle>();
|
|
|
|
|
customTitles = new List<CustomTitle>();
|
|
|
|
|
LoadSerialization();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddAlbum(Album album)
|
|
|
|
|
{
|
|
|
|
|
albums.Add(album);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddArtist(Artist artist)
|
|
|
|
|
{
|
|
|
|
|
artists.Add(artist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddCustomTitle(CustomTitle title)
|
|
|
|
|
{
|
|
|
|
|
customTitles.Add(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddInfoTitle(InfoTitle title)
|
|
|
|
|
{
|
|
|
|
|
infoTitles.Add(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddPlaylist(Playlist playlist)
|
|
|
|
|
{
|
|
|
|
|
playlists.Add(playlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Album> GetAlbums()
|
|
|
|
|
{
|
|
|
|
|
return albums;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Artist> GetArtists()
|
|
|
|
|
{
|
|
|
|
|
return artists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<CustomTitle> GetCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
return customTitles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<InfoTitle> GetInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
return infoTitles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Playlist> GetPlaylists()
|
|
|
|
|
{
|
|
|
|
|
return playlists;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAlbum(Album album)
|
|
|
|
|
{
|
|
|
|
|
albums.Remove(album);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveArtist(Artist artist)
|
|
|
|
|
{
|
|
|
|
|
artists.Remove(artist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveCustomTitle(CustomTitle title)
|
|
|
|
|
{
|
|
|
|
|
customTitles.Remove(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveInfoTitle(InfoTitle title)
|
|
|
|
|
{
|
|
|
|
|
infoTitles.Remove(title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemovePlaylist(Playlist playlist)
|
|
|
|
|
{
|
|
|
|
|
playlists.Remove(playlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadSerialization()
|
|
|
|
|
{
|
|
|
|
|
LoadArtists();
|
|
|
|
|
LoadCustomTitles();
|
|
|
|
|
LoadInfoTitles();
|
|
|
|
|
LoadPlaylists();
|
|
|
|
|
LoadAlbums();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveSerialization()
|
|
|
|
|
{
|
|
|
|
|
SaveArtists();
|
|
|
|
|
SaveCustomTitles();
|
|
|
|
|
SaveInfoTitles();
|
|
|
|
|
SavePlaylists();
|
|
|
|
|
SaveAlbums();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadPlaylists()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEPLAYLISTS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument PlaylistFile = new XDocument();
|
|
|
|
|
Playlist p1 = new Playlist();
|
|
|
|
|
playlists.Add(p1);
|
|
|
|
|
|
|
|
|
|
var playlist = playlists.Select(p => new XElement("Playlist",
|
|
|
|
|
new XAttribute("Name", p.Name),
|
|
|
|
|
new XElement("Description", p.Description),
|
|
|
|
|
new XElement("ImageURL", p.ImageURL),
|
|
|
|
|
new XElement("Titles", p.Morceaux.Count() > 0 ? p.Morceaux.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "")
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
PlaylistFile.Add(new XElement("Playlists", playlist));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEPLAYLISTS)))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
PlaylistFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument PlaylistsFichier = XDocument.Load(Path.Combine(XMLPATH, XMLFILEPLAYLISTS));
|
|
|
|
|
|
|
|
|
|
playlists = PlaylistsFichier.Descendants("Playlist")
|
|
|
|
|
.Select(eltPlaylist => new Playlist(
|
|
|
|
|
eltPlaylist.Attribute("Name")!.Value,
|
|
|
|
|
eltPlaylist.Element("Description")!.Value,
|
|
|
|
|
eltPlaylist.Element("ImageURL")!.Value
|
|
|
|
|
)).ToList();
|
|
|
|
|
foreach (Playlist playlist in playlists)
|
|
|
|
|
{
|
|
|
|
|
var custom = PlaylistsFichier.Descendants("Playlist")
|
|
|
|
|
.Single(ct => ct.Attribute("Name")?.Value == playlist.Name)
|
|
|
|
|
.Element("Titles")!.ToString();
|
|
|
|
|
if (custom == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CustomTitle? customTitle = GetCustomTitleByUrl(custom);
|
|
|
|
|
|
|
|
|
|
if (customTitle == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playlist.AddTitle(customTitle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SavePlaylists()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument PlaylistsFichier = new XDocument();
|
|
|
|
|
|
|
|
|
|
var playlist = playlists.Select(playlist => new XElement("Playlist",
|
|
|
|
|
new XAttribute("Name", playlist.Name),
|
|
|
|
|
new XElement("Description", playlist.Description),
|
|
|
|
|
new XElement("ImageURL", playlist.ImageURL),
|
|
|
|
|
new XElement("Titles", playlist.Morceaux.Count() > 0 ? playlist.Morceaux.Select(p => p.ImageURL).Aggregate((playlistUrl, nextPlaylist) => playlistUrl + " " + nextPlaylist) : "")
|
|
|
|
|
));
|
|
|
|
|
PlaylistsFichier.Add(new XElement("Playlists", playlist));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
|
|
|
|
using(TextWriter tw = File.CreateText(XMLFILEPLAYLISTS))
|
|
|
|
|
{
|
|
|
|
|
using(XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
PlaylistsFichier.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadArtists()
|
|
|
|
|
{
|
|
|
|
|
XDocument ArtistsFile = XDocument.Load("artists.xml");
|
|
|
|
|
artists = ArtistsFile.Descendants("artist")
|
|
|
|
|
.Select(eltArtist => new Artist(
|
|
|
|
|
eltArtist.Attribute("Name")!.Value
|
|
|
|
|
)).ToList();
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEARTISTS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument ArtistFile = new XDocument();
|
|
|
|
|
Artist a1 = new Artist("a1");
|
|
|
|
|
Artist a2 = new Artist("a2");
|
|
|
|
|
|
|
|
|
|
artists.Add(a1);
|
|
|
|
|
artists.Add(a2);
|
|
|
|
|
|
|
|
|
|
var artist = artists.Select(artist => new XElement("Artist",
|
|
|
|
|
new XAttribute("Name", artist.Name)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
ArtistFile.Add(new XElement("Artists", artist));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEARTISTS)))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
ArtistFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XDocument ArtistsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILEARTISTS));
|
|
|
|
|
artists = ArtistsFile.Descendants("Artist")
|
|
|
|
|
.Select(eltArtist => new Artist(
|
|
|
|
|
eltArtist.Attribute("Name")!.Value
|
|
|
|
|
)).ToList();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveArtists()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument ArtistsFile = new XDocument();
|
|
|
|
|
var artist = artists.Select(artist => new XElement("artist",
|
|
|
|
|
var artist = artists.Select(artist => new XElement("Artist",
|
|
|
|
|
new XAttribute("Name", artist.Name)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArtistsFile.Add(new XElement("Artists", artist));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEARTISTS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
ArtistsFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILECUSTOMS)))
|
|
|
|
|
{
|
|
|
|
|
using (Stream s = File.Create(Path.Combine(XMLPATH, XMLFILECUSTOMS)))
|
|
|
|
|
{
|
|
|
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(CustomTitle));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
xmlSerializer.Serialize(XmlWriter.Create(s, settings), new CustomTitle("test1","url1.png","info1","path1"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument CustomsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILECUSTOMS));
|
|
|
|
|
|
|
|
|
|
customTitles = CustomsFile.Descendants("CustomTitle")
|
|
|
|
|
.Select(eltPlaylist => new CustomTitle(
|
|
|
|
|
eltPlaylist.Attribute("Name")!.Value,
|
|
|
|
|
eltPlaylist.Element("ImageURL")!.Value,
|
|
|
|
|
eltPlaylist.Element("Information")!.Value,
|
|
|
|
|
eltPlaylist.Element("Path")!.Value
|
|
|
|
|
)).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument CustomsFile = new XDocument();
|
|
|
|
|
|
|
|
|
|
var customs = customTitles.Select(custom => new XElement("CustomTitle",
|
|
|
|
|
new XAttribute("Name", custom.Name),
|
|
|
|
|
new XElement("ImageURL", custom.ImageURL),
|
|
|
|
|
new XElement("Information", custom.Information),
|
|
|
|
|
new XElement("Path", custom.Path)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
CustomsFile.Add(new XElement("Customs", customs));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILECUSTOMS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
CustomsFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadAlbums()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEALBUMS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument AlbumFile = new XDocument();
|
|
|
|
|
Album a1 = new Album();
|
|
|
|
|
albums.Add(a1);
|
|
|
|
|
|
|
|
|
|
var album = albums.Select(p => new XElement("Album",
|
|
|
|
|
new XAttribute("Name", p.Name),
|
|
|
|
|
new XElement("ImageURL", p.ImageURL),
|
|
|
|
|
new XElement("Artist", p.Titles.Count() > 0 ? p.Titles.Select(a => a.Name).Aggregate((artistName, nextArtist) => artistName + " " + nextArtist) : ""),
|
|
|
|
|
new XElement("Description", p.Description),
|
|
|
|
|
new XElement("Information", p.Information),
|
|
|
|
|
new XElement("Titles", p.Titles.Count() > 0 ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "")
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
AlbumFile.Add(new XElement("Albums", album));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEALBUMS)))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
AlbumFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument AlbumsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILEALBUMS));
|
|
|
|
|
|
|
|
|
|
albums = AlbumsFile.Descendants("Album")
|
|
|
|
|
.Select(eltPlaylist => new Album(
|
|
|
|
|
eltPlaylist.Attribute("Name")!.Value,
|
|
|
|
|
eltPlaylist.Element("ImageURL")!.Value,
|
|
|
|
|
GetArtistByName(eltPlaylist.Element("Artist")!.Value) != null ? GetArtistByName(eltPlaylist.Element("Artist")!.Value) : new Artist("Unknown"),
|
|
|
|
|
eltPlaylist.Element("Description")!.Value,
|
|
|
|
|
eltPlaylist.Element("Information")!.Value
|
|
|
|
|
)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (Album a in albums)
|
|
|
|
|
{
|
|
|
|
|
var title = AlbumsFile.Descendants("Album")
|
|
|
|
|
.Single(ct => ct.Attribute("Name")?.Value == a.Name)
|
|
|
|
|
.Element("Titles")!.ToString();
|
|
|
|
|
if (title == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InfoTitle? infoTitle = GetInfoTitleByUrl(title);
|
|
|
|
|
|
|
|
|
|
if (infoTitle == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a.AddTitle(infoTitle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveAlbums()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument AlbumsFile = new XDocument();
|
|
|
|
|
|
|
|
|
|
var album = albums.Select(a => new XElement("Album",
|
|
|
|
|
new XAttribute("Name", a.Name),
|
|
|
|
|
new XElement("ImageURL", a.ImageURL),
|
|
|
|
|
new XElement("Artist", a.Artist.Name),
|
|
|
|
|
new XElement("Description", a.Description),
|
|
|
|
|
new XElement("Information", a.Information),
|
|
|
|
|
new XElement("Titles", a.Titles.Count() > 0 ? a.Titles.Select(p => p.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "")
|
|
|
|
|
));
|
|
|
|
|
AlbumsFile.Add(new XElement("Albums", album));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEALBUMS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
AlbumsFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEINFOS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument InfoFile = new XDocument();
|
|
|
|
|
InfoTitle it1 = new InfoTitle();
|
|
|
|
|
infoTitles.Add(it1);
|
|
|
|
|
|
|
|
|
|
var infoTitle = infoTitles.Select(p => new XElement("InfoTitle",
|
|
|
|
|
new XAttribute("Name", p.Name),
|
|
|
|
|
new XElement("ImageURL", p.ImageURL),
|
|
|
|
|
new XElement("Information", p.Information),
|
|
|
|
|
new XElement("Feats", p.Feat.Count() > 0 ? p.Feat.Select(a => a.Name).Aggregate((artistName, nextArtist) => artistName + " " + nextArtist) : ""),
|
|
|
|
|
new XElement("Description", p.Description),
|
|
|
|
|
new XElement("Genre", p.Genre)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
InfoFile.Add(new XElement("InfoTitles", infoTitle));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEINFOS)))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
InfoFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument InfosFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILEINFOS));
|
|
|
|
|
|
|
|
|
|
infoTitles = InfosFile.Descendants("InfoTitle")
|
|
|
|
|
.Select(eltPlaylist => new InfoTitle(
|
|
|
|
|
eltPlaylist.Attribute("Name")!.Value,
|
|
|
|
|
eltPlaylist.Element("ImageURL")!.Value,
|
|
|
|
|
eltPlaylist.Element("Information")!.Value,
|
|
|
|
|
GetArtistByName(eltPlaylist.Element("Feats")!.Value),
|
|
|
|
|
eltPlaylist.Element("Description")!.Value,
|
|
|
|
|
GetGenreByName(eltPlaylist.Element("Genre")!.Value)
|
|
|
|
|
)).ToList();
|
|
|
|
|
foreach (InfoTitle it in infoTitles)
|
|
|
|
|
{
|
|
|
|
|
var feat = InfosFile.Descendants("InfoTitle")
|
|
|
|
|
.Single(infot => infot.Attribute("Name")?.Value == it.Name)
|
|
|
|
|
.Element("Feats")!.ToString();
|
|
|
|
|
if (feat == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Artist? Feat = GetArtistByName(feat);
|
|
|
|
|
|
|
|
|
|
if (Feat == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it.AddFeat(Feat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument InfosFile = new XDocument();
|
|
|
|
|
|
|
|
|
|
var info = infoTitles.Select(it => new XElement("InfoTitle",
|
|
|
|
|
new XAttribute("Name", it.Name),
|
|
|
|
|
new XElement("ImageURL", it.ImageURL),
|
|
|
|
|
new XElement("Information", it.Information),
|
|
|
|
|
new XElement("Genre", it.Genre.ToString()),
|
|
|
|
|
new XElement("Description", it.Description),
|
|
|
|
|
new XElement("Feats", it.Feat.Count() > 0 ? it.Feat.Select(p => p.Name).Aggregate((featName, nextFeat) => featName + " " + nextFeat) : "")
|
|
|
|
|
));
|
|
|
|
|
InfosFile.Add(new XElement("InfoTitles", info));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEINFOS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
InfosFile.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Genre GetGenreByName(string genre)
|
|
|
|
|
{
|
|
|
|
|
if (genre == "HIP_HOP") return Genre.HIP_HOP;
|
|
|
|
|
if (genre == "POP") return Genre.POP;
|
|
|
|
|
if (genre == "ROCK") return Genre.ROCK;
|
|
|
|
|
if (genre == "ELECTRO") return Genre.ELECTRO;
|
|
|
|
|
if (genre == "CLASSIQUE") return Genre.CLASSIQUE;
|
|
|
|
|
if (genre == "JAZZ") return Genre.JAZZ;
|
|
|
|
|
if (genre == "VARIETE_FRANCAISE") return Genre.VARIETE_FRANCAISE;
|
|
|
|
|
if (genre == "VARIETE_INTERNATIONALE") return Genre.VARIETE_INTERNATIONALE;
|
|
|
|
|
if (genre == "REGGAE") return Genre.REGGAE;
|
|
|
|
|
if (genre == "RAP") return Genre.RAP;
|
|
|
|
|
if (genre == "RNB") return Genre.RNB;
|
|
|
|
|
if (genre == "DISCO") return Genre.DISCO;
|
|
|
|
|
if (genre == "BLUES") return Genre.BLUES;
|
|
|
|
|
if (genre == "COUNTRY") return Genre.COUNTRY;
|
|
|
|
|
if (genre == "FUNK") return Genre.FUNK;
|
|
|
|
|
if (genre == "GOSPEL") return Genre.GOSPEL;
|
|
|
|
|
if (genre == "METAL") return Genre.METAL;
|
|
|
|
|
else return Genre.K_POP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InfoTitle? GetInfoTitleByUrl(string infoUrl)
|
|
|
|
|
{
|
|
|
|
|
foreach(InfoTitle it in infoTitles)
|
|
|
|
|
{
|
|
|
|
|
if (it.Name == infoUrl)
|
|
|
|
|
{
|
|
|
|
|
return it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Artist? GetArtistByName(string artist)
|
|
|
|
|
{
|
|
|
|
|
foreach(Artist a in artists)
|
|
|
|
|
{
|
|
|
|
|
if (a.Name == artist)
|
|
|
|
|
{
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Album? GetAlbumByUrl(string album)
|
|
|
|
|
{
|
|
|
|
|
foreach(Album a in albums)
|
|
|
|
|
{
|
|
|
|
|
if (a.ImageURL == album)
|
|
|
|
|
{
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CustomTitle? GetCustomTitleByUrl(string custom)
|
|
|
|
|
{
|
|
|
|
|
foreach(CustomTitle customTitle in customTitles)
|
|
|
|
|
{
|
|
|
|
|
if(customTitle.Name == custom)
|
|
|
|
|
{
|
|
|
|
|
return customTitle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|