@ -11,19 +11,14 @@ public class LinqXmlSerialization : IDataManager
private static string XMLFILEPLAYLISTS = Path . Combine ( XMLPATH , "playlists.xml" ) ;
private static string XMLFILEALBUMS = Path . Combine ( XMLPATH , "albums.xml" ) ;
private static string XMLFILECUSTOMS = Path . Combine ( XMLPATH , "customs.xml" ) ;
private static string XMLFILEINFOS = Path . Combine ( XMLPATH , "infos.xml" ) ;
private static string XMLFILEARTISTS = Path . Combine ( XMLPATH , "artists.xml" ) ;
private Stub Manager stubManager ;
private StubInfoTitle stubInfoTitle = new ( ) ;
public Stub Manager StubManager
public Stub InfoTitle StubInfoTitle
{
get = > stub Manager ;
get = > stub InfoTitle ;
}
private List < Artist > artists ;
@ -79,16 +74,16 @@ public class LinqXmlSerialization : IDataManager
public LinqXmlSerialization ( )
{
playlists = new ObservableCollection < Playlist > ( ) ;
stubManager = new StubManager ( ) ;
artists = StubManager . GetArtists ( ) ;
infoTitles = StubManager . GetInfoTitles ( ) ;
albums = StubManager . GetAlbums ( ) ;
artists = new List < Artist > ( ) ;
infoTitles = new ObservableCollection < InfoTitle > ( ) ;
albums = new ObservableCollection < Album > ( ) ;
customTitles = new ObservableCollection < CustomTitle > ( ) ;
if ( ! Directory . Exists ( XMLPATH ) )
{
Directory . CreateDirectory ( XMLPATH ) ;
}
Directory . SetCurrentDirectory ( XMLPATH ) ;
LoadSerialization ( ) ;
}
public void AddAlbum ( Album album )
@ -169,10 +164,10 @@ public class LinqXmlSerialization : IDataManager
public void LoadSerialization ( )
{
LoadArtists ( ) ;
Load CustomTitle s( ) ;
Load Album s( ) ;
LoadInfoTitles ( ) ;
LoadCustomTitles ( ) ;
LoadPlaylists ( ) ;
LoadAlbums ( ) ;
}
public void SaveSerialization ( )
@ -189,8 +184,6 @@ public class LinqXmlSerialization : IDataManager
if ( ! File . Exists ( 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 ) ,
@ -238,7 +231,7 @@ public class LinqXmlSerialization : IDataManager
foreach ( var custom in customsList )
{
CustomTitle ? customTitle = GetCustomTitleBy Url ( custom ) ;
CustomTitle ? customTitle = GetCustomTitleBy Path ( custom ) ;
if ( customTitle = = null )
{
@ -258,7 +251,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 . Name ) . Aggregate ( ( playlistName , nextPlaylist ) = > playlistName + " " + nextPlaylist ) : "" )
new XElement ( "Titles" , playlist . Titles . Any ( ) ? playlist . Titles . Select ( p = > p . Path ) . Aggregate ( ( playlistName , nextPlaylist ) = > playlistName + " " + nextPlaylist ) : "" )
) ) ;
PlaylistsFichier . Add ( new XElement ( "Playlists" , playlist ) ) ;
@ -276,60 +269,12 @@ public class LinqXmlSerialization : IDataManager
public void LoadArtists ( )
{
/ * if ( ! File . Exists ( 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 ( XMLFILEARTISTS ) )
{
using ( XmlWriter writer = XmlWriter . Create ( tw , settings ) )
{
ArtistFile . Save ( writer ) ;
}
}
}
XDocument ArtistsFile = XDocument . Load ( XMLFILEARTISTS ) ;
artists = ArtistsFile . Descendants ( "Artist" )
. Select ( eltArtist = > new Artist (
eltArtist . Attribute ( "Name" ) ! . Value
) ) . ToList ( ) ; * /
artists . Add ( new Artist ( "Imagine Dragons" ) ) ;
artists = StubInfoTitle . StubAlbum . StubArtist . GetArtists ( ) ;
}
public void SaveArtists ( )
{
/ * XDocument ArtistsFile = new XDocument ( ) ;
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 ) ;
}
} * /
// Don't do anything because it's static data
}
public void LoadCustomTitles ( )
@ -338,9 +283,6 @@ public class LinqXmlSerialization : IDataManager
{
XDocument CustomsFile2 = new XDocument ( ) ;
CustomTitle ct1 = new CustomTitle ( "ct1" , "url1.png" , "info1" , "path1" ) ;
customTitles . Add ( ct1 ) ;
var custom = customTitles . Select ( c = > new XElement ( "CustomTitle" ,
new XAttribute ( "Name" , c . Name ) ,
@ -399,270 +341,28 @@ public class LinqXmlSerialization : IDataManager
public void LoadAlbums ( )
{
/ * if ( ! File . Exists ( 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 . 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 . Name ) . Aggregate ( ( albumName , nextAlbum ) = > albumName + " " + nextAlbum ) : "" )
) ) ;
AlbumFile . 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 ) )
{
AlbumFile . Save ( writer ) ;
}
}
}
XDocument AlbumsFile = XDocument . Load ( XMLFILEALBUMS ) ;
var albums2 = AlbumsFile . Descendants ( "Album" )
. Select ( eltPlaylist = > new Album (
eltPlaylist . Attribute ( "Name" ) ! . Value ,
eltPlaylist . Element ( "ImageURL" ) ! . Value ,
GetArtistByName ( eltPlaylist . Element ( "Artist" ) ! . Value ) ? ? new Artist ( ) ,
eltPlaylist . Element ( "Description" ) ! . Value ,
eltPlaylist . Element ( "Information" ) ! . Value
) ) . ToList ( ) ;
albums = new ObservableCollection < Album > ( albums2 ) ;
foreach ( Album a in albums )
{
var allTitles = AlbumsFile . Descendants ( "Album" )
. Single ( ct = > ct . Attribute ( "Name" ) ? . Value = = a . Name )
. Element ( "Titles" ) ! . Value ;
if ( allTitles = = null )
{
continue ;
}
char [ ] separator = new char [ ] { ' ' } ;
string [ ] titleArray = allTitles . Split ( separator , StringSplitOptions . RemoveEmptyEntries ) ;
List < string > titlesList = titleArray . ToList ( ) ;
foreach ( var title in titlesList )
{
InfoTitle ? infoTitle = GetInfoTitleByName ( title ) ;
if ( infoTitle = = null )
{
continue ;
}
a . AddTitle ( infoTitle ) ;
}
} * /
albums = StubInfoTitle . StubAlbum . GetAlbums ( ) ;
}
public void SaveAlbums ( )
{
/ * 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 . Any ( ) ? a . Titles . Select ( p = > p . Name ) . Aggregate ( ( albumName , nextAlbum ) = > albumName + " " + 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 ) ;
}
} * /
// Don't do anything because it's static data
}
public void LoadInfoTitles ( )
{
/ * if ( ! File . Exists ( 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 . Any ( ) ? 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 ( XMLFILEINFOS ) )
{
using ( XmlWriter writer = XmlWriter . Create ( tw , settings ) )
{
InfoFile . Save ( writer ) ;
}
}
}
XDocument InfosFile = XDocument . Load ( XMLFILEINFOS ) ;
var infoTitles2 = InfosFile . Descendants ( "InfoTitle" )
. Select ( eltPlaylist = > new InfoTitle (
eltPlaylist . Attribute ( "Name" ) ! . Value ,
eltPlaylist . Element ( "ImageURL" ) ! . Value ,
eltPlaylist . Element ( "Information" ) ! . Value ,
GetArtistByName ( eltPlaylist . Element ( "Feats" ) ! . Value ) ? ? new Artist ( ) ,
eltPlaylist . Element ( "Description" ) ! . Value ,
GetGenreByName ( eltPlaylist . Element ( "Genre" ) ! . Value )
) ) . ToList ( ) ;
infoTitles = new ObservableCollection < InfoTitle > ( infoTitles2 ) ;
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 ) ;
} * /
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 ) ) ;
infoTitles = StubInfoTitle . GetInfoTitles ( ) ;
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 ;
}
GetAlbumById ( infoTitle . AlbumID ) ? . AddTitle ( infoTitle ) ;
}
}
public void SaveInfoTitles ( )
{
/ * 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 . Any ( ) ? 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 ) ;
}
} * /
// Don't do anything because it's static data
}
public static Genre GetGenreByName ( string genre )
{
if ( genre = = "HIP_HOP" ) return Genre . HIP_HOP ;
@ -721,11 +421,20 @@ public class LinqXmlSerialization : IDataManager
return null ;
}
public CustomTitle ? GetCustomTitleByUrl ( string custom )
public Album ? GetAlbumById ( long id )
{
foreach ( Album a in albums )
{
if ( a . ID = = id ) return a ;
}
return null ;
}
public CustomTitle ? GetCustomTitleByPath ( string custom )
{
foreach ( CustomTitle customTitle in customTitles )
{
if ( customTitle . ImageURL = = custom )
if ( customTitle . Path = = custom )
{
return customTitle ;
}
@ -793,15 +502,15 @@ public class LinqXmlSerialization : IDataManager
title . Path = path ;
}
public void UpdateCustomTitleBy Url( string url , string name , string newUrl , string info , string p ath)
public void UpdateCustomTitleBy Path( string path , string name , string newUrl , string info , string newP ath)
{
CustomTitle ? title = GetCustomTitleBy Url( url ) ;
CustomTitle ? title = GetCustomTitleBy Path( path ) ;
if ( title ! = null )
{
title . Name = name ;
title . ImageURL = newUrl ;
title . Information = info ;
title . Path = p ath;
title . Path = newP ath;
}
}
@ -810,7 +519,6 @@ public class LinqXmlSerialization : IDataManager
title . Name = name ;
title . ImageURL = url ;
title . Information = info ;
title . Artist = artist ;
title . Description = description ;
title . Genre = genre ;
}
@ -823,39 +531,6 @@ public class LinqXmlSerialization : IDataManager
title . Name = name ;
title . ImageURL = newUrl ;
title . Information = info ;
title . Artist = artist ;
title . Description = description ;
title . Genre = genre ;
}
}
public void UpdateInfoTitleByArtistName ( InfoTitle title , string name , string url , string info , string artist , string description , Genre genre )
{
title . Name = name ;
title . ImageURL = url ;
title . Information = info ;
Artist ? artist2 = GetArtistByName ( artist ) ;
if ( artist2 ! = null )
{
title . Artist = artist2 ;
}
title . Description = description ;
title . Genre = genre ;
}
public void UpdateInfoTitleByNameByArtistName ( string name , string newUrl , string info , string artist , string description , Genre genre )
{
InfoTitle ? title = GetInfoTitleByName ( name ) ;
if ( title ! = null )
{
title . Name = name ;
title . ImageURL = newUrl ;
title . Information = info ;
Artist ? artist2 = GetArtistByName ( artist ) ;
if ( artist2 ! = null )
{
title . Artist = artist2 ;
}
title . Description = description ;
title . Genre = genre ;
}