|
|
|
@ -13,17 +13,17 @@ namespace Model.Serialization;
|
|
|
|
|
|
|
|
|
|
public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
{
|
|
|
|
|
private static string XMLPATH = @"Data\";
|
|
|
|
|
private static string XMLPATH = Path.Combine(Environment.CurrentDirectory, "Data");
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEPLAYLISTS = "playlists.xml";
|
|
|
|
|
private static string XMLFILEPLAYLISTS = Path.Combine(XMLPATH, "playlists.xml");
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEALBUMS = "albums.xml";
|
|
|
|
|
private static string XMLFILEALBUMS = Path.Combine(XMLPATH, "albums.xml");
|
|
|
|
|
|
|
|
|
|
private static string XMLFILECUSTOMS = "customs.xml";
|
|
|
|
|
private static string XMLFILECUSTOMS = Path.Combine(XMLPATH, "customs.xml");
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEINFOS = "infos.xml";
|
|
|
|
|
private static string XMLFILEINFOS = Path.Combine(XMLPATH, "infos.xml");
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEARTISTS = "artists.xml";
|
|
|
|
|
private static string XMLFILEARTISTS = Path.Combine(XMLPATH, "artists.xml");
|
|
|
|
|
|
|
|
|
|
private List<Artist> artists;
|
|
|
|
|
|
|
|
|
@ -185,11 +185,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadPlaylists()
|
|
|
|
|
{
|
|
|
|
|
if(!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEPLAYLISTS)))
|
|
|
|
|
if (!File.Exists(XMLFILEPLAYLISTS))
|
|
|
|
|
{
|
|
|
|
|
XDocument PlaylistFile = new XDocument();
|
|
|
|
|
Playlist p1 = new Playlist();
|
|
|
|
@ -206,7 +202,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEPLAYLISTS)))
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEPLAYLISTS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
@ -214,7 +210,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument PlaylistsFichier = XDocument.Load(Path.Combine(XMLPATH, XMLFILEPLAYLISTS));
|
|
|
|
|
XDocument PlaylistsFichier = XDocument.Load(XMLFILEPLAYLISTS);
|
|
|
|
|
|
|
|
|
|
playlists = PlaylistsFichier.Descendants("Playlist")
|
|
|
|
|
.Select(eltPlaylist => new Playlist(
|
|
|
|
@ -266,14 +262,10 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void LoadArtists()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEARTISTS)))
|
|
|
|
|
if (!File.Exists(XMLFILEARTISTS))
|
|
|
|
|
{
|
|
|
|
|
XDocument ArtistFile = new XDocument();
|
|
|
|
|
Artist a1 = new Artist("a1");
|
|
|
|
@ -290,7 +282,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEARTISTS)))
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEARTISTS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
@ -299,7 +291,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XDocument ArtistsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILEARTISTS));
|
|
|
|
|
XDocument ArtistsFile = XDocument.Load(XMLFILEARTISTS);
|
|
|
|
|
artists = ArtistsFile.Descendants("Artist")
|
|
|
|
|
.Select(eltArtist => new Artist(
|
|
|
|
|
eltArtist.Attribute("Name")!.Value
|
|
|
|
@ -331,11 +323,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILECUSTOMS)))
|
|
|
|
|
if (!File.Exists(XMLFILECUSTOMS))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
XDocument CustomsFile2 = new XDocument();
|
|
|
|
@ -356,14 +344,14 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILECUSTOMS)))
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILECUSTOMS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
|
|
|
|
|
CustomsFile2.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument CustomsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILECUSTOMS));
|
|
|
|
|
XDocument CustomsFile = XDocument.Load(XMLFILECUSTOMS);
|
|
|
|
|
|
|
|
|
|
customTitles = CustomsFile.Descendants("CustomTitle")
|
|
|
|
|
.Select(eltPlaylist => new CustomTitle(
|
|
|
|
@ -401,11 +389,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadAlbums()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEALBUMS)))
|
|
|
|
|
if (!File.Exists(XMLFILEALBUMS))
|
|
|
|
|
{
|
|
|
|
|
XDocument AlbumFile = new XDocument();
|
|
|
|
|
Album a1 = new Album();
|
|
|
|
@ -424,7 +408,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEALBUMS)))
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEALBUMS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
@ -432,7 +416,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument AlbumsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILEALBUMS));
|
|
|
|
|
XDocument AlbumsFile = XDocument.Load(XMLFILEALBUMS);
|
|
|
|
|
|
|
|
|
|
albums = AlbumsFile.Descendants("Album")
|
|
|
|
|
.Select(eltPlaylist => new Album(
|
|
|
|
@ -492,11 +476,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEINFOS)))
|
|
|
|
|
if (!File.Exists(XMLFILEINFOS))
|
|
|
|
|
{
|
|
|
|
|
XDocument InfoFile = new XDocument();
|
|
|
|
|
InfoTitle it1 = new InfoTitle();
|
|
|
|
@ -515,7 +495,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(XMLPATH + XMLFILEINFOS)))
|
|
|
|
|
using (TextWriter tw = File.CreateText(XMLFILEINFOS))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
@ -523,7 +503,7 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument InfosFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILEINFOS));
|
|
|
|
|
XDocument InfosFile = XDocument.Load(XMLFILEINFOS);
|
|
|
|
|
|
|
|
|
|
infoTitles = InfosFile.Descendants("InfoTitle")
|
|
|
|
|
.Select(eltPlaylist => new InfoTitle(
|
|
|
|
@ -901,4 +881,124 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
infoTitles.Remove(infoTitle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsPlaylist(Playlist playlist)
|
|
|
|
|
{
|
|
|
|
|
foreach(Playlist p in playlists)
|
|
|
|
|
{
|
|
|
|
|
if (p == playlist)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsPlaylistByUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
foreach(Playlist p in playlists)
|
|
|
|
|
{
|
|
|
|
|
if (p.ImageURL == url)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsAlbum(Album album)
|
|
|
|
|
{
|
|
|
|
|
foreach(Album a in albums)
|
|
|
|
|
{
|
|
|
|
|
if(a == album)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsAlbumByUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
foreach(Album a in albums)
|
|
|
|
|
{
|
|
|
|
|
if (a.ImageURL == url)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsArtist(Artist artist)
|
|
|
|
|
{
|
|
|
|
|
foreach (Artist a in artists)
|
|
|
|
|
{
|
|
|
|
|
if (a == artist)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsArtistByName(string name)
|
|
|
|
|
{
|
|
|
|
|
foreach(Artist a in artists)
|
|
|
|
|
{
|
|
|
|
|
if(a.Name == name)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsCustomTitle(CustomTitle title)
|
|
|
|
|
{
|
|
|
|
|
foreach(CustomTitle ct in customTitles)
|
|
|
|
|
{
|
|
|
|
|
if(title == ct)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsCustomTitleByUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
foreach(CustomTitle ct in customTitles)
|
|
|
|
|
{
|
|
|
|
|
if(ct.ImageURL == url)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsInfoTitle(InfoTitle title)
|
|
|
|
|
{
|
|
|
|
|
foreach(InfoTitle it in infoTitles)
|
|
|
|
|
{
|
|
|
|
|
if(it == title)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExistsInfoTitleByUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
foreach(InfoTitle it in infoTitles)
|
|
|
|
|
{
|
|
|
|
|
if(it.ImageURL == url)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|