@ -1,6 +1,7 @@
using System.Xml ;
using System.Xml.Linq ;
using System.Collections.ObjectModel ;
using Model.Stub ;
namespace Model.Serialization ;
@ -73,9 +74,17 @@ public class LinqXmlSerialization : IDataManager
playlists = new ObservableCollection < Playlist > ( ) ;
artists = new List < Artist > ( ) ;
Artist ImagineDragons = new Artist ( "Imagine Dragons" ) ;
Artist artist = new Artist ( "artist" ) ;
InfoTitle nom = new InfoTitle ( "nom" , "none.png" , "infos" , artist , "desc" , Genre . RAP ) ;
InfoTitle unknown = new InfoTitle ( ) ;
infoTitles = new ObservableCollection < InfoTitle > ( )
{
nom ,
unknown
} ;
albums = new ObservableCollection < Album > ( )
{
new Album ( "Adios Bahamas" , "album1.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Adios Bahamas" , "album1.jpg" , artist , "Description d'Adios Bahamas" , "Informations sur Adios Bahamas ") ,
new Album ( "Album2" , "album2.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Album3" , "album3.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Album4" , "album4.jpg" , new Artist ( ) , "" , "" ) ,
@ -83,14 +92,16 @@ public class LinqXmlSerialization : IDataManager
new Album ( "Album6" , "album6.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Album7" , "album7.png" , new Artist ( ) , "" , "" ) ,
new Album ( "Album8" , "album8.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Night Visions" , "album9.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Smoke & Mirrors" , "album10.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Evolve" , "album11.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Origins" , "album12.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Mercury Act 1" , "album13.jpg" , new Artist ( ) , "" , "" ) ,
new Album ( "Mercury Act 2" , "album14.jpg" , new Artist ( ) , "" , "" )
new Album ( "Night Visions" , "album9.jpg" , ImagineDragons , "" , "" ) ,
new Album ( "Smoke & Mirrors" , "album10.jpg" , ImagineDragons , "" , "" ) ,
new Album ( "Evolve" , "album11.jpg" , ImagineDragons , "" , "" ) ,
new Album ( "Origins" , "album12.jpg" , ImagineDragons , "" , "" ) ,
new Album ( "Mercury Act 1" , "album13.jpg" , ImagineDragons , "" , "" ) ,
new Album ( "Mercury Act 2" , "album14.jpg" , ImagineDragons , "" , "" )
} ;
infoTitles = new ObservableCollection < InfoTitle > ( ) ;
Album ? AdiosBahamas = GetAlbumByName ( "Adios Bahamas" ) ;
AdiosBahamas ? . AddTitle ( nom ) ;
AdiosBahamas ? . AddTitle ( unknown ) ;
customTitles = new ObservableCollection < CustomTitle > ( ) ;
if ( ! Directory . Exists ( XMLPATH ) )
{
@ -98,6 +109,7 @@ public class LinqXmlSerialization : IDataManager
}
Directory . SetCurrentDirectory ( XMLPATH ) ;
SaveAlbums ( ) ;
SaveInfoTitles ( ) ;
LoadSerialization ( ) ;
}
@ -128,7 +140,7 @@ public class LinqXmlSerialization : IDataManager
public ObservableCollection < Album > GetAlbums ( )
{
return A lbums;
return a lbums;
}
public List < Artist > GetArtists ( )
@ -138,17 +150,17 @@ public class LinqXmlSerialization : IDataManager
public ObservableCollection < CustomTitle > GetCustomTitles ( )
{
return C ustomTitles;
return c ustomTitles;
}
public ObservableCollection < InfoTitle > GetInfoTitles ( )
{
return I nfoTitles;
return i nfoTitles;
}
public ObservableCollection < Playlist > GetPlaylists ( )
{
return P laylists;
return p laylists;
}
public void RemoveAlbum ( Album album )
@ -206,7 +218,7 @@ public class LinqXmlSerialization : IDataManager
new XAttribute ( "Name" , p . Name ) ,
new XElement ( "Description" , p . Description ) ,
new XElement ( "ImageURL" , p . ImageURL ) ,
new XElement ( "Titles" , p . Titles . Any ( ) ? p . Titles . Select ( a = > a . ImageURL) . Aggregate ( ( albumUrl , nextAlbum ) = > albumUrl + " " + nextAlbum ) : "" )
new XElement ( "Titles" , p . Titles . Any ( ) ? p . Titles . Select ( a = > a . Name) . Aggregate ( ( playlistName , nextPlaylist ) = > playlistName + " " + nextPlaylist ) : "" )
) ) ;
PlaylistFile . Add ( new XElement ( "Playlists" , playlist ) ) ;
@ -233,22 +245,30 @@ public class LinqXmlSerialization : IDataManager
foreach ( Playlist playlist in playlists )
{
var custom = PlaylistsFichier . Descendants ( "Playlist" )
var allCustoms = PlaylistsFichier . Descendants ( "Playlist" )
. Single ( ct = > ct . Attribute ( "Name" ) ? . Value = = playlist . Name )
. Element ( "Titles" ) ! . ToString ( ) ;
if ( custom = = null )
. Element ( "Titles" ) ! . Value ;
if ( allCustoms = = null )
{
continue ;
}
CustomTitle ? customTitle = GetCustomTitleByUrl ( custom ) ;
char [ ] separator = new char [ ] { ' ' } ;
string [ ] customArray = allCustoms . Split ( separator , StringSplitOptions . RemoveEmptyEntries ) ;
List < string > customsList = customArray . ToList ( ) ;
if ( customTitle = = null )
foreach( var custom in customsList )
{
continue ;
}
CustomTitle ? customTitle = GetCustomTitleByName ( custom ) ;
if ( customTitle = = null )
{
continue ;
}
playlist . AddTitle ( customTitle ) ;
playlist . AddTitle ( customTitle ) ;
}
}
}
@ -260,7 +280,7 @@ public class LinqXmlSerialization : IDataManager
new XAttribute ( "Name" , playlist . Name ) ,
new XElement ( "Description" , playlist . Description ) ,
new XElement ( "ImageURL" , playlist . ImageURL ) ,
new XElement ( "Titles" , playlist . Titles . Any ( ) ? playlist . Titles . Select ( p = > p . ImageURL) . Aggregate ( ( playlistUrl , nextPlaylist ) = > playlistUrl + " " + nextPlaylist ) : "" )
new XElement ( "Titles" , playlist . Titles . Any ( ) ? playlist . Titles . Select ( p = > p . Name) . Aggregate ( ( playlistName , nextPlaylist ) = > playlistName + " " + nextPlaylist ) : "" )
) ) ;
PlaylistsFichier . Add ( new XElement ( "Playlists" , playlist ) ) ;
@ -278,7 +298,7 @@ public class LinqXmlSerialization : IDataManager
public void LoadArtists ( )
{
if ( ! File . Exists ( XMLFILEARTISTS ) )
/ * if ( ! File . Exists ( XMLFILEARTISTS ) )
{
XDocument ArtistFile = new XDocument ( ) ;
Artist a1 = new Artist ( "a1" ) ;
@ -308,13 +328,14 @@ public class LinqXmlSerialization : IDataManager
artists = ArtistsFile . Descendants ( "Artist" )
. Select ( eltArtist = > new Artist (
eltArtist . Attribute ( "Name" ) ! . Value
) ) . ToList ( ) ;
) ) . ToList ( ) ; * /
artists . Add ( new Artist ( "Imagine Dragons" ) ) ;
}
public void SaveArtists ( )
{
XDocument ArtistsFile = new XDocument ( ) ;
/ * XDocument ArtistsFile = new XDocument ( ) ;
var artist = artists . Select ( artist = > new XElement ( "Artist" ,
new XAttribute ( "Name" , artist . Name )
) ) ;
@ -330,8 +351,7 @@ public class LinqXmlSerialization : IDataManager
{
ArtistsFile . Save ( writer ) ;
}
}
} * /
}
public void LoadCustomTitles ( )
@ -401,7 +421,7 @@ public class LinqXmlSerialization : IDataManager
public void LoadAlbums ( )
{
if ( ! File . Exists ( XMLFILEALBUMS ) )
/ * if ( ! File . Exists ( XMLFILEALBUMS ) )
{
XDocument AlbumFile = new XDocument ( ) ;
Album a1 = new Album ( ) ;
@ -413,7 +433,7 @@ public class LinqXmlSerialization : IDataManager
new XElement ( "Artist" , p . Titles . Any ( ) ? 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 . Any ( ) ? p . Titles . Select ( a = > a . ImageURL) . Aggregate ( ( albumUrl , nextAlbum ) = > albumUrl + " " + nextAlbum ) : "" )
new XElement ( "Titles" , p . Titles . Any ( ) ? p . Titles . Select ( a = > a . Name) . Aggregate ( ( albumName , nextAlbum ) = > albumName + " " + nextAlbum ) : "" )
) ) ;
AlbumFile . Add ( new XElement ( "Albums" , album ) ) ;
@ -443,28 +463,35 @@ public class LinqXmlSerialization : IDataManager
foreach ( Album a in albums )
{
var title = AlbumsFile . Descendants ( "Album" )
var allTitles = AlbumsFile . Descendants ( "Album" )
. Single ( ct = > ct . Attribute ( "Name" ) ? . Value = = a . Name )
. Element ( "Titles" ) ! . ToString( ) ;
if ( title = = null )
. Element ( "Titles" ) ! . Value ;
if ( allTitles = = null )
{
continue ;
}
InfoTitle ? infoTitle = GetInfoTitleByName ( title ) ;
char [ ] separator = new char [ ] { ' ' } ;
string [ ] titleArray = allTitles . Split ( separator , StringSplitOptions . RemoveEmptyEntries ) ;
List < string > titlesList = titleArray . ToList ( ) ;
if ( infoTitle = = null )
foreach ( var title in titlesList )
{
continue ;
}
InfoTitle ? infoTitle = GetInfoTitleByName ( title ) ;
a . AddTitle ( infoTitle ) ;
}
if ( infoTitle = = null )
{
continue ;
}
a . AddTitle ( infoTitle ) ;
}
} * /
}
public void SaveAlbums ( )
{
XDocument AlbumsFile = new XDocument ( ) ;
/ * XDocument AlbumsFile = new XDocument ( ) ;
var album = albums . Select ( a = > new XElement ( "Album" ,
new XAttribute ( "Name" , a . Name ) ,
@ -472,7 +499,7 @@ public class LinqXmlSerialization : IDataManager
new XElement ( "Artist" , a . Artist . Name ) ,
new XElement ( "Description" , a . Description ) ,
new XElement ( "Information" , a . Information ) ,
new XElement ( "Titles" , a . Titles . Any ( ) ? a . Titles . Select ( p = > p . ImageURL) . Aggregate ( ( albumUrl , nextAlbum ) = > albumUrl + " " + nextAlbum ) : "" )
new XElement ( "Titles" , a . Titles . Any ( ) ? a . Titles . Select ( p = > p . Name) . Aggregate ( ( albumName , nextAlbum ) = > albumName + " " + nextAlbum ) : "" )
) ) ;
AlbumsFile . Add ( new XElement ( "Albums" , album ) ) ;
@ -485,12 +512,12 @@ public class LinqXmlSerialization : IDataManager
{
AlbumsFile . Save ( writer ) ;
}
}
} * /
}
public void LoadInfoTitles ( )
{
if ( ! File . Exists ( XMLFILEINFOS ) )
/ * if ( ! File . Exists ( XMLFILEINFOS ) )
{
XDocument InfoFile = new XDocument ( ) ;
InfoTitle it1 = new InfoTitle ( ) ;
@ -548,12 +575,94 @@ public class LinqXmlSerialization : IDataManager
}
it . AddFeat ( Feat ) ;
} * /
AddInfoTitle ( new InfoTitle ( "Bones" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Symphony" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Sharks" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "I don't like myself" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Blur" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Higher ground" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Crushed" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Take it easy" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Waves" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "I'm happy" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Ferris wheel" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Peace of mind" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Sirens" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Tied" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Younger" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "Continual" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
AddInfoTitle ( new InfoTitle ( "They don't know you like I do" , "none.png" , "infos" , GetArtistByName ( "Imagine Dragons" ) ? ? new Artist ( "Imagine Dragons" ) , "desc" , Genre . POP ) ) ;
foreach ( var infoTitle in InfoTitles )
{
switch ( infoTitle . Name )
{
case "Bones" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Symphony" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Sharks" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "I don't like myself" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Blur" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Higher ground" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Crushed" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Take it easy" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Waves" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "I'm Happy" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Ferris wheel" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Peace of mind" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Sirens" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Tied" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Younger" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "Continual" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
case "They don't know you like I do" :
GetAlbumByName ( "Mercury Act 2" ) ! . AddTitle ( infoTitle ) ;
break ;
default :
break ;
}
}
}
public void SaveInfoTitles ( )
{
XDocument InfosFile = new XDocument ( ) ;
/ * XDocument InfosFile = new XDocument ( ) ;
var info = infoTitles . Select ( it = > new XElement ( "InfoTitle" ,
new XAttribute ( "Name" , it . Name ) ,
@ -574,7 +683,7 @@ public class LinqXmlSerialization : IDataManager
{
InfosFile . Save ( writer ) ;
}
}
} * /
}
public static Genre GetGenreByName ( string genre )
{
@ -634,7 +743,7 @@ public class LinqXmlSerialization : IDataManager
return null ;
}
public CustomTitle ? GetCustomTitleBy Url ( string custom )
public CustomTitle ? GetCustomTitleBy Name ( string custom )
{
foreach ( CustomTitle customTitle in customTitles )
{
@ -706,9 +815,9 @@ public class LinqXmlSerialization : IDataManager
title . Path = path ;
}
public void UpdateCustomTitleBy Url( string url , string name , string newUrl , string info , string path )
public void UpdateCustomTitleBy Name( string name , string newUrl , string info , string path )
{
CustomTitle ? title = GetCustomTitleBy Url( url ) ;
CustomTitle ? title = GetCustomTitleBy Name( name ) ;
if ( title ! = null )
{
title . Name = name ;
@ -982,11 +1091,11 @@ public class LinqXmlSerialization : IDataManager
return false ;
}
public bool ExistsCustomTitleBy Url( string url )
public bool ExistsCustomTitleBy Name( string name )
{
foreach ( CustomTitle ct in customTitles )
{
if ( ct . ImageURL = = url )
if ( ct . Name = = name )
{
return true ;
}