|
|
|
@ -13,7 +13,7 @@ namespace Model.Serialization;
|
|
|
|
|
|
|
|
|
|
public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
{
|
|
|
|
|
private static string XMLPATH = @"D:\Data\";
|
|
|
|
|
private static string XMLPATH = @"Data\";
|
|
|
|
|
|
|
|
|
|
private static string XMLFILEPLAYLISTS = "playlists.xml";
|
|
|
|
|
|
|
|
|
@ -82,6 +82,11 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
albums = new List<Album>();
|
|
|
|
|
infoTitles = new List<InfoTitle>();
|
|
|
|
|
customTitles = new List<CustomTitle>();
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
LoadSerialization();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -180,6 +185,10 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadPlaylists()
|
|
|
|
|
{
|
|
|
|
|
if(!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEPLAYLISTS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument PlaylistFile = new XDocument();
|
|
|
|
@ -236,7 +245,6 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void SavePlaylists()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument PlaylistsFichier = new XDocument();
|
|
|
|
|
|
|
|
|
|
var playlist = playlists.Select(playlist => new XElement("Playlist",
|
|
|
|
@ -261,6 +269,10 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadArtists()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEARTISTS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument ArtistFile = new XDocument();
|
|
|
|
@ -297,7 +309,6 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void SaveArtists()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument ArtistsFile = new XDocument();
|
|
|
|
|
var artist = artists.Select(artist => new XElement("Artist",
|
|
|
|
|
new XAttribute("Name", artist.Name)
|
|
|
|
@ -320,14 +331,36 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILECUSTOMS)))
|
|
|
|
|
{
|
|
|
|
|
using (Stream s = File.Create(Path.Combine(XMLPATH, XMLFILECUSTOMS)))
|
|
|
|
|
|
|
|
|
|
XDocument CustomsFile2 = new XDocument();
|
|
|
|
|
CustomTitle ct1 = new CustomTitle("ct1", "url1.png", "info1", "path1");
|
|
|
|
|
CustomTitle ct2 = new CustomTitle("ct2", "url2.png", "info2", "path2");
|
|
|
|
|
|
|
|
|
|
customTitles.Add(ct1);
|
|
|
|
|
customTitles.Add(ct2);
|
|
|
|
|
|
|
|
|
|
var custom = customTitles.Select(c => new XElement("CustomTitle",
|
|
|
|
|
new XAttribute("Name", c.Name),
|
|
|
|
|
new XElement("ImageURL", c.ImageURL),
|
|
|
|
|
new XElement("Information", c.Information),
|
|
|
|
|
new XElement("Path",c.Path)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
CustomsFile2.Add(new XElement("Customs", custom));
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
using (TextWriter tw = File.CreateText(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"));
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
|
|
|
|
|
CustomsFile2.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
XDocument CustomsFile = XDocument.Load(Path.Combine(XMLPATH, XMLFILECUSTOMS));
|
|
|
|
@ -343,7 +376,6 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void SaveCustomTitles()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument CustomsFile = new XDocument();
|
|
|
|
|
|
|
|
|
|
var customs = customTitles.Select(custom => new XElement("CustomTitle",
|
|
|
|
@ -369,6 +401,10 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadAlbums()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEALBUMS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument AlbumFile = new XDocument();
|
|
|
|
@ -430,7 +466,6 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void SaveAlbums()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument AlbumsFile = new XDocument();
|
|
|
|
|
|
|
|
|
|
var album = albums.Select(a => new XElement("Album",
|
|
|
|
@ -457,6 +492,10 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void LoadInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(XMLPATH))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(XMLPATH);
|
|
|
|
|
}
|
|
|
|
|
if (!File.Exists(Path.Combine(XMLPATH + XMLFILEINFOS)))
|
|
|
|
|
{
|
|
|
|
|
XDocument InfoFile = new XDocument();
|
|
|
|
@ -518,7 +557,6 @@ public class LINQ_XML_Serialization : IDataManager
|
|
|
|
|
|
|
|
|
|
public void SaveInfoTitles()
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(XMLPATH);
|
|
|
|
|
XDocument InfosFile = new XDocument();
|
|
|
|
|
|
|
|
|
|
var info = infoTitles.Select(it => new XElement("InfoTitle",
|
|
|
|
|