From 4a47cba23381a504a476ea41719464aa9eb21ef1 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE Date: Sat, 29 Apr 2023 12:06:12 +0200 Subject: [PATCH 01/45] Add Stub and starting Model --- Sources/Linaris/FooterPage.xaml.cs | 2 +- Sources/Model/Album.cs | 90 +++++++++++++++++++++++++----- Sources/Model/Artiste.cs | 40 +++++++------ Sources/Model/CustomTitle.cs | 24 ++++++++ Sources/Model/Genre.cs | 6 ++ Sources/Model/IDataManager.cs | 6 ++ Sources/Model/InfoTitle.cs | 46 +++++++++++++++ Sources/Model/Manager.cs | 51 +++++++++++++++++ Sources/Model/Model.csproj | 9 --- Sources/Model/Morceau.cs | 38 ------------- Sources/Model/Playlist.cs | 75 ++++++++++++++++++------- Sources/Model/Stub/Stub.cs | 49 ++++++++++++++++ Sources/Model/Title.cs | 58 +++++++++++++++++++ 13 files changed, 394 insertions(+), 100 deletions(-) create mode 100644 Sources/Model/CustomTitle.cs create mode 100644 Sources/Model/Genre.cs create mode 100644 Sources/Model/IDataManager.cs create mode 100644 Sources/Model/InfoTitle.cs create mode 100644 Sources/Model/Manager.cs delete mode 100644 Sources/Model/Model.csproj delete mode 100644 Sources/Model/Morceau.cs create mode 100644 Sources/Model/Stub/Stub.cs create mode 100644 Sources/Model/Title.cs diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index 64b0c9f..adaa690 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -19,7 +19,7 @@ public partial class FooterPage : ContentView // (s,a) = convention, s = sender, a = arguments, si appli fermée, on free tout outputDevice.PlaybackStopped += PlaybackStoppedHandler; - morceauEnCours = "U:\\Utils\\Musics\\peaches.mp3"; + morceauEnCours = "D:\\Musique\\Création\\winter.mp3"; audioFile = new AudioFileReader(morceauEnCours); outputDevice.Init(audioFile); } diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 1eafa3e..7dab8f9 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -1,32 +1,92 @@ namespace Model { - public class Album + public class Album { - public string Nom { get; set; } + public string Name + { + get => name; - public string File_Name { get; set; } + set + { + if (value != null && value.Length < 75) + { + name = value; + } + } + } - public Artiste Artiste { get; set; } + private string name; - public string Description { get; set; } + public string Description + { + get => description; + + set + { + if (value != null && value.Length < 500) + { + description = value; + } + } + } - public string Informations { get; set; } + private string description; - public IEnumerable Morceaux { get; set; } + public IEnumerable Titles { get; set; } - public Album(string nom, string file_Name, Artiste artiste, string description, string informations) + public string ImageURL { - Nom = nom; - File_Name = file_Name; - Artiste = artiste; + get => imageURL; + + set + { + if (value != null && value.Contains('.')) + { + imageURL = value; + } + } + } + + private string imageURL; + + public Artiste Artist { get; set; } + + public string Information + { + get => information; + + set + { + if (value != null && value.Length < 500) + { + information = value; + } + } + } + + private string information; + + public Album(string name, string file_Name, Artiste artist, string description, string information) + { + Name = name; + ImageURL = file_Name; + Artist = artist; Description = description; - Informations = informations; - Morceaux = new List<Morceau>(); + Information = information; + Titles = new List<Title>(); + } + + public void AddTitle(Title title) + { + Titles.Prepend(title); } - public void addMorceau(Morceau morceau) + public void RemoveTitle(Title title) { - Morceaux.Prepend(morceau); + foreach(var item in Titles) + { + Titles = Titles.Where(item => item != title).ToList(); + } } } diff --git a/Sources/Model/Artiste.cs b/Sources/Model/Artiste.cs index fa84929..bcab081 100644 --- a/Sources/Model/Artiste.cs +++ b/Sources/Model/Artiste.cs @@ -1,26 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace Model; -namespace Model +public class Artiste { - public class Artiste + public string Name { - public string Nom { get; set; } + get => name; - public IEnumerable<Album> Albums { get; set; } - - public Artiste(string nom) + set { - Nom = nom; - Albums = new List<Album>(); + if (value != null && value.Length < 75) + { + name = value; + } } + } - public void addAlbum(Album album) - { - Albums.Prepend(album); - } + private string name = "Unknown"; + + public IEnumerable<Album> Albums { get; set; } + + public Artiste(string name) + { + Name = name; + Albums = new List<Album>(); + } + + public void AddAlbum(Album album) + { + Albums.Prepend(album); } } diff --git a/Sources/Model/CustomTitle.cs b/Sources/Model/CustomTitle.cs new file mode 100644 index 0000000..9b41237 --- /dev/null +++ b/Sources/Model/CustomTitle.cs @@ -0,0 +1,24 @@ +namespace Model; + +public class CustomTitle : Title { + + public string Path + { + get => path; + + set + { + if (value != null && value.Length < 500) + { + path = value; + } + } + } + + private string path; + + public CustomTitle(string name, string imageURL, string information, string path) : base(name, imageURL, information) + { + Path = path; + } +} diff --git a/Sources/Model/Genre.cs b/Sources/Model/Genre.cs new file mode 100644 index 0000000..4298509 --- /dev/null +++ b/Sources/Model/Genre.cs @@ -0,0 +1,6 @@ +namespace Model; + +public enum Genre +{ + HIP_HOP, POP, ROCK, ELECTRO, CLASSIQUE, JAZZ, VARIETE_FRANCAISE, VARIETE_INTERNATIONALE, REGGAE, RAP, RNB, DISCO, BLUES, COUNTRY, FUNK, GOSPEL, METAL, K_POP +} diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs new file mode 100644 index 0000000..4799ef5 --- /dev/null +++ b/Sources/Model/IDataManager.cs @@ -0,0 +1,6 @@ +namespace Model; + +public interface IDataManager +{ + //méthodes style IEnumerable<Groupe> RecupGFroupe(); +} \ No newline at end of file diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs new file mode 100644 index 0000000..bb9eb4d --- /dev/null +++ b/Sources/Model/InfoTitle.cs @@ -0,0 +1,46 @@ +namespace Model; + +public class InfoTitle : Title +{ + public Artiste Artiste { get; set; } + + public string Description + { + get => description; + + set + { + if (value != null && value.Length < 500) + { + description = value; + } + } + } + + private string description; + + public IEnumerable<Artiste> Feat { get; set; } + + public Genre Genre { get; set; } + + public InfoTitle(string name, string imageURL, string information, Artiste artist, string description, Genre genre) : base(name,imageURL,information) + { + Artiste = artist; + Description = description; + Genre = genre; + Feat = new List<Artiste>(); + } + + public void AddFeat(Artiste artist) + { + Feat.Prepend(artist); + } + public void RemoveFeat(Artiste artiste) + { + foreach (var item in Feat) + { + Feat = Feat.Where(item => item != artiste).ToList(); + } + } + +} diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs new file mode 100644 index 0000000..9de8d13 --- /dev/null +++ b/Sources/Model/Manager.cs @@ -0,0 +1,51 @@ +namespace Model.Stub; + +public class Manager +{ + public IDataManager DataManager { get; set; } + + public IEnumerable<Album> Albums; + + public IEnumerable<Title> Titles; + + public IEnumerable<Playlist> Playlists; + + public Manager() + { + DataManager = new Stub(); + // Albums = DataManager.GetAlbum(); + Albums = new List<Album>(); + Titles = new List<Title>(); + Playlists = new List<Playlist>(); + } + + public void AddAlbum(Album album) + { + Albums.Prepend(album); + } + + public void AddTitle(Title title) + { + Titles.Prepend(title); + } + public void AddPlaylist(Playlist playlist) + { + Playlists.Prepend(playlist); + } + + public void RemoveAlbum(Album album) + { + Albums.ToList().Remove(album); + } + + public void RemoveTitle(Title title) + { + Titles.ToList().Remove(title); + } + + public void RemovePlaylist(Playlist playlist) + { + Playlists.ToList().Remove(playlist); + } + +} diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj deleted file mode 100644 index 4658cbf..0000000 --- a/Sources/Model/Model.csproj +++ /dev/null @@ -1,9 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net7.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - </PropertyGroup> - -</Project> diff --git a/Sources/Model/Morceau.cs b/Sources/Model/Morceau.cs deleted file mode 100644 index 670d754..0000000 --- a/Sources/Model/Morceau.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model -{ - public class Morceau - { - public string Nom { get; set; } - - public string File_Name { get; set; } - - public string Artiste { get; set; } - - public string Description { get; set; } - - public string Informations { get; set; } - - public IEnumerable<Artiste> feat { get; set; } - - public Morceau(string nom, string file_Name, string artiste, string description, string informations) - { - Nom = nom; - File_Name = file_Name; - Artiste = artiste; - Description = description; - Informations = informations; - feat = new List<Artiste>(); - } - - public void addFeat(Artiste artiste) - { - feat.Prepend(artiste); - } - } -} diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 797c593..97d3e43 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -1,35 +1,70 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace Model; -namespace Model +public class Playlist { - public class Playlist + public string Name { - public string Nom { get; set; } + get => name; - public string Description { get; set; } - - public IEnumerable<Morceau> Morceaux { get; set; } - - public Playlist(string nom, string description) + set { - Nom = nom; - Description = description; - Morceaux = new List<Morceau>(); + if (value != null && value.Length < 75) + { + name = value; + } } + } + + private string name; + + public string Description + { + get => description; - public void addMorceau(Morceau morceau) + set { - Morceaux.Prepend(morceau); + if (value != null && value.Length < 500) + { + description = value; + } } + } + + private string description; + + public IEnumerable<Title> Morceaux { get; set; } + + public string ImageURL + { + get => imageURL; - public void removeMorceau(Morceau morceau) + set { - Morceaux.ToList().Remove(morceau); + if (value != null && value.Contains('.')) + { + imageURL = value; + } } + } + + private string imageURL; + + public Playlist(string nom, string description, string imageURL) + { + Name = nom; + Description = description; + Morceaux = new List<Title>(); + this.imageURL = imageURL; + } + public void AddTitle(Title morceau) + { + Morceaux.Prepend(morceau); } + + public void RemoveTitle(Title morceau) + { + Morceaux.ToList().Remove(morceau); + } + } diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/Stub.cs new file mode 100644 index 0000000..9a60c86 --- /dev/null +++ b/Sources/Model/Stub/Stub.cs @@ -0,0 +1,49 @@ +namespace Model.Stub; + +public class Stub : IDataManager +{ + + public IEnumerable<Artiste> Artistes; + + public IEnumerable<Album> Albums; + + public IEnumerable<Playlist> Playlists; + + public IEnumerable<Title> Titles; + + public Stub() + { + Artistes = new List<Artiste>(); + Albums = new List<Album>(); + Playlists = new List<Playlist>(); + Titles = new List<Title>(); + + Artiste Artiste1 = new Artiste("Critien"); + Artiste Artiste2 = new Artiste("Gouriet"); + Artiste Artiste3 = new Artiste("Poulifer"); + Artiste Artiste4 = new Artiste("Credian"); + + Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); + Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); + + Artiste1.AddAlbum(Album1); + Artiste1.AddAlbum(new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2")); + Artiste2.AddAlbum(new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3")); + Artiste2.AddAlbum(Album4); + + Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); + Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); + Playlist Playlist3 = new Playlist("Playlist3", "desc3", "url3.png"); + Playlist Playlist4 = new Playlist("Playlist4", "desc4", "url4.png"); + + Playlist1.AddTitle(new CustomTitle("custom1", "url1.png", "info1", "chemin1")); + Playlist1.AddTitle(new CustomTitle("custom2", "url2.png", "info2", "chemin2")); + Playlist1.AddTitle(new CustomTitle("custom3", "url3.png", "info3", "chemin3")); + Playlist2.AddTitle(new CustomTitle("custom4", "url4.png", "info4", "chemin4")); + + Album1.AddTitle(new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP)); + Album1.AddTitle(new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL)); + Album1.AddTitle(new InfoTitle("info3", "url3.png", "info3", Artiste4, "desc3", Genre.BLUES)); + Album4.AddTitle(new InfoTitle("info4", "url4.png", "info4", Artiste3, "desc4", Genre.DISCO)); + } +} diff --git a/Sources/Model/Title.cs b/Sources/Model/Title.cs new file mode 100644 index 0000000..1d985e8 --- /dev/null +++ b/Sources/Model/Title.cs @@ -0,0 +1,58 @@ +namespace Model +{ + public class Title + { + public string Name + { + get => name; + + set + { + if (value != null && value.Length < 75) + { + name = value; + } + } + } + + private string name; + + public string ImageURL + { + get => imageURL; + + set + { + if (value != null && value.Contains('.')) + { + imageURL = value; + } + } + } + + private string imageURL; + + public string Information + { + get => information; + + set + { + if (value != null && value.Length < 500) + { + information = value; + } + } + } + + private string information; + + public Title(string nom, string file_Name, string informations) + { + Name = nom; + ImageURL = file_Name; + Information = informations; + } + + } +} From e4a0c77f0c12bf6b73a1e2d5177e6656ff29d692 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Wed, 3 May 2023 12:58:48 +0200 Subject: [PATCH 02/45] Fix Connsole error and missing model.csproj --- Sources/{Connsole => Console}/Console.csproj | 0 Sources/{Connsole => Console}/Program.cs | 0 Sources/Linaris.sln | 2 +- Sources/Model/Model.csproj | 9 +++++++++ 4 files changed, 10 insertions(+), 1 deletion(-) rename Sources/{Connsole => Console}/Console.csproj (100%) rename Sources/{Connsole => Console}/Program.cs (100%) create mode 100644 Sources/Model/Model.csproj diff --git a/Sources/Connsole/Console.csproj b/Sources/Console/Console.csproj similarity index 100% rename from Sources/Connsole/Console.csproj rename to Sources/Console/Console.csproj diff --git a/Sources/Connsole/Program.cs b/Sources/Console/Program.cs similarity index 100% rename from Sources/Connsole/Program.cs rename to Sources/Console/Program.cs diff --git a/Sources/Linaris.sln b/Sources/Linaris.sln index 413e4e5..6f91fb4 100644 --- a/Sources/Linaris.sln +++ b/Sources/Linaris.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 17.0.31611.283 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Linaris", "Linaris\Linaris.csproj", "{9E6281F7-95F6-472C-B268-894CE377C8A9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Connsole\Console.csproj", "{BB50C1E3-5A9A-40AF-8CD7-55B41064290B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console\Console.csproj", "{BB50C1E3-5A9A-40AF-8CD7-55B41064290B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{AA1DB94B-8273-437F-A07A-BB1F5F0D278D}" EndProject diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj new file mode 100644 index 0000000..4658cbf --- /dev/null +++ b/Sources/Model/Model.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net7.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> From 9d207ce7828f75e3009f1dd6ce7d62d9896535ea Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Wed, 3 May 2023 15:37:19 +0200 Subject: [PATCH 03/45] Enchance Model and Stub --- Sources/Console/Program.cs | 33 ++++--- Sources/Linaris/FooterPage.xaml.cs | 2 +- Sources/Linaris/Linaris.csproj | 3 +- Sources/Model/Album.cs | 29 +++--- Sources/Model/Artist.cs | 39 ++++++++ Sources/Model/CustomTitle.cs | 2 +- Sources/Model/IDataManager.cs | 25 ++++- Sources/Model/InfoTitle.cs | 25 +++-- Sources/Model/Manager.cs | 44 +++++++-- Sources/Model/Playlist.cs | 116 ++++++++++++++++++++++-- Sources/Model/Stub/Stub.cs | 141 ++++++++++++++++++++++++----- Sources/Model/Title.cs | 6 +- 12 files changed, 386 insertions(+), 79 deletions(-) create mode 100644 Sources/Model/Artist.cs diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index fb87e4e..5a4730d 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -1,24 +1,35 @@ using Model; +using Model.Stub; +Manager Manager = new Manager(); -// See https://aka.ms/new-console-template for more information +foreach(Album Album in Manager.GetAlbums()) +{ + Console.WriteLine(Album.Name); +} -/*Album a = new Album("Adios Bahamas", "album1.jpg", "Népal"); -Album a1 = new Album("Fenêtre sur Rue", "album3.jpg", "HugoTSR"); -Album a2 = new Album("Dans la Légende", "album8.jpg", "PNL"); +Console.WriteLine("---------------"); -List<Album> lst = new List<Album> { a1, a2, a }; +Manager.AddAlbum(new Album("coucou", "path.png", new Artist("lorenzo"), "descLolo", "infoLolo")); -foreach (Album album in lst) +foreach (Album Album in Manager.GetAlbums()) { - Console.WriteLine($"Nom de l'album : " + album.Nom); + Console.WriteLine(Album.Name); +} + +Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); + +Playlist p1 = Manager.Playlists.First(); + +Console.WriteLine(p1.GetCurrentTitle()); + +p1.NextTitle(); - Console.WriteLine($"Nom du fichier : " + album.File_Name); +Console.WriteLine(p1.GetCurrentTitle()); - Console.WriteLine($"Artiste : " + album.Artiste); +p1.PreviousTitle(); - Console.WriteLine($"-------------------------"); -}*/ +Console.WriteLine(p1.GetCurrentTitle()); diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index adaa690..fdf1855 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -19,7 +19,7 @@ public partial class FooterPage : ContentView // (s,a) = convention, s = sender, a = arguments, si appli fermée, on free tout outputDevice.PlaybackStopped += PlaybackStoppedHandler; - morceauEnCours = "D:\\Musique\\Création\\winter.mp3"; + morceauEnCours = "peaches.mp3"; audioFile = new AudioFileReader(morceauEnCours); outputDevice.Init(audioFile); } diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj index bbcc06b..b1d6590 100644 --- a/Sources/Linaris/Linaris.csproj +++ b/Sources/Linaris/Linaris.csproj @@ -45,7 +45,8 @@ <MauiFont Include="Resources\Fonts\*" /> <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> - <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> + <MauiAsset Include="Resources\Raw\*" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> + </ItemGroup> <ItemGroup> diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 7dab8f9..4ef7959 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -15,7 +15,7 @@ } } - private string name; + private string name ="Unknown"; public string Description { @@ -30,9 +30,17 @@ } } - private string description; + private string description =""; - public IEnumerable<Title> Titles { get; set; } + private List<Title> titles = new List<Title>(); + + public IEnumerable<Title> Titles + { + get + { + return Titles; + } + } public string ImageURL { @@ -47,9 +55,9 @@ } } - private string imageURL; + private string imageURL = "none.png"; - public Artiste Artist { get; set; } + public Artist Artist { get; set; } public string Information { @@ -64,28 +72,27 @@ } } - private string information; + private string information = ""; - public Album(string name, string file_Name, Artiste artist, string description, string information) + public Album(string name, string file_Name, Artist artist, string description, string information) { Name = name; ImageURL = file_Name; Artist = artist; Description = description; Information = information; - Titles = new List<Title>(); } public void AddTitle(Title title) { - Titles.Prepend(title); + titles.Add(title); } public void RemoveTitle(Title title) { - foreach(var item in Titles) + foreach(var item in titles) { - Titles = Titles.Where(item => item != title).ToList(); + titles = titles.Where(item => item != title).ToList(); } } diff --git a/Sources/Model/Artist.cs b/Sources/Model/Artist.cs new file mode 100644 index 0000000..c638dfd --- /dev/null +++ b/Sources/Model/Artist.cs @@ -0,0 +1,39 @@ +namespace Model; + +public class Artist +{ + public string Name + { + get => name; + + set + { + if (value != null && value.Length < 75) + { + name = value; + } + } + } + + private string name = "Unknown"; + + private List<Album> albums = new List<Album>(); + + public IEnumerable<Album> Albums + { + get + { + return albums; + } + } + + public Artist(string name) + { + Name = name; + } + + public void AddAlbum(Album album) + { + albums.Add(album); + } +} diff --git a/Sources/Model/CustomTitle.cs b/Sources/Model/CustomTitle.cs index 9b41237..4f9958f 100644 --- a/Sources/Model/CustomTitle.cs +++ b/Sources/Model/CustomTitle.cs @@ -15,7 +15,7 @@ public class CustomTitle : Title { } } - private string path; + private string path = "none.mp3"; public CustomTitle(string name, string imageURL, string information, string path) : base(name, imageURL, information) { diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 4799ef5..c21b2c5 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -2,5 +2,28 @@ public interface IDataManager { - //méthodes style IEnumerable<Groupe> RecupGFroupe(); + IEnumerable<Title> GetTitles(); + + IEnumerable<Album> GetAlbums(); + + IEnumerable<Artist> GetArtists(); + + IEnumerable<Playlist> GetPlaylists(); + + public void AddAlbum(Album album); + + public void AddArtist(Artist artist); + + public void AddPlaylist(Playlist playlist); + + public void AddTitle(Title title); + + public void RemoveAlbum(Album album); + + public void RemoveArtist(Artist artist); + + public void RemovePlaylist(Playlist playlist); + + public void RemoveTitle(Title title); + } \ No newline at end of file diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index bb9eb4d..8df3a81 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -2,7 +2,7 @@ public class InfoTitle : Title { - public Artiste Artiste { get; set; } + public Artist Artiste { get; set; } public string Description { @@ -17,29 +17,36 @@ public class InfoTitle : Title } } - private string description; + private string description =""; - public IEnumerable<Artiste> Feat { get; set; } + private List<Artist> feat = new List<Artist>(); + + public IEnumerable<Artist> Feat + { + get + { + return feat; + } + } public Genre Genre { get; set; } - public InfoTitle(string name, string imageURL, string information, Artiste artist, string description, Genre genre) : base(name,imageURL,information) + public InfoTitle(string name, string imageURL, string information, Artist artist, string description, Genre genre) : base(name,imageURL,information) { Artiste = artist; Description = description; Genre = genre; - Feat = new List<Artiste>(); } - public void AddFeat(Artiste artist) + public void AddFeat(Artist artist) { - Feat.Prepend(artist); + feat.Add(artist); } - public void RemoveFeat(Artiste artiste) + public void RemoveFeat(Artist artiste) { foreach (var item in Feat) { - Feat = Feat.Where(item => item != artiste).ToList(); + feat = Feat.Where(item => item != artiste).ToList(); } } diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 9de8d13..ae75df9 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -10,42 +10,66 @@ public class Manager public IEnumerable<Playlist> Playlists; + public IEnumerable<Artist> Artists; + public Manager() { DataManager = new Stub(); - // Albums = DataManager.GetAlbum(); - Albums = new List<Album>(); - Titles = new List<Title>(); - Playlists = new List<Playlist>(); + + Albums = DataManager.GetAlbums(); + Titles = DataManager.GetTitles(); + Playlists = DataManager.GetPlaylists(); + Artists = DataManager.GetArtists(); } public void AddAlbum(Album album) { - Albums.Prepend(album); + DataManager.AddAlbum(album); + Albums = DataManager.GetAlbums(); } public void AddTitle(Title title) { - Titles.Prepend(title); + DataManager.AddTitle(title); + Titles = DataManager.GetTitles(); } public void AddPlaylist(Playlist playlist) { - Playlists.Prepend(playlist); + DataManager.AddPlaylist(playlist); + Playlists = DataManager.GetPlaylists(); } public void RemoveAlbum(Album album) { - Albums.ToList().Remove(album); + DataManager.RemoveAlbum(album); + Albums = DataManager.GetAlbums(); } public void RemoveTitle(Title title) { - Titles.ToList().Remove(title); + DataManager.RemoveTitle(title); + Titles = DataManager.GetTitles(); } public void RemovePlaylist(Playlist playlist) { - Playlists.ToList().Remove(playlist); + DataManager.RemovePlaylist(playlist); + Playlists = DataManager.GetPlaylists(); + } + + public IEnumerable<Album> GetAlbums() + { + return DataManager.GetAlbums(); + } + + public IEnumerable<Title> GetTitles() + { + return DataManager.GetTitles(); + } + + public IEnumerable<Artist> GetArtists() + { + return DataManager.GetArtists(); } } diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 97d3e43..29f798b 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -15,7 +15,7 @@ public class Playlist } } - private string name; + private string name ="Unknown"; public string Description { @@ -30,9 +30,16 @@ public class Playlist } } - private string description; + private string description = ""; - public IEnumerable<Title> Morceaux { get; set; } + private List<Title> morceaux = new List<Title>(); + + public IEnumerable<Title> Morceaux { + get + { + return morceaux; + } + } public string ImageURL { @@ -47,24 +54,119 @@ public class Playlist } } - private string imageURL; + private string imageURL = "none.png"; + + public int Index + { + get => index; + + set + { + if (value < morceaux.Count()) + { + index = value; + } + else if(Loop) + { + index = 0; + } + else + { + return; + } + } + } + + private int index = 0; + + public bool Shuffle = false; + + public bool Loop = false; + + public bool LoopTitle = false; + + Random Aleatoire = new Random(); + + private List<int> played = new List<int>(); + + public IEnumerable<int> Played + { + get + { + return played; + } + } public Playlist(string nom, string description, string imageURL) { Name = nom; Description = description; - Morceaux = new List<Title>(); this.imageURL = imageURL; } public void AddTitle(Title morceau) { - Morceaux.Prepend(morceau); + morceaux.Add(morceau); } public void RemoveTitle(Title morceau) { - Morceaux.ToList().Remove(morceau); + morceaux.Remove(morceau); + } + + public void NextTitle() + { + if (LoopTitle) + { + return; + } + + if (!Shuffle) + { + Index++; + played.Add(Index); + } + else + { + Index = Aleatoire.Next(morceaux.Count() - 1); + played.Add(Index); + } + } + + public void PreviousTitle() + { + if (LoopTitle) + { + return; + } + + if(!Shuffle) + { + Index--; + played.RemoveAt(0); + } + else + { + if (played.Count() == 0) + { + return; + } + Index = played[0]; + played.RemoveAt(0); + } + } + + public Title? GetCurrentTitle() + { + if (Index < morceaux.Count() - 1) + { + return morceaux[Index]; + } + else + { + return null; + } + } } diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/Stub.cs index 9a60c86..2b4b96b 100644 --- a/Sources/Model/Stub/Stub.cs +++ b/Sources/Model/Stub/Stub.cs @@ -3,7 +3,7 @@ public class Stub : IDataManager { - public IEnumerable<Artiste> Artistes; + public IEnumerable<Artist> Artists; public IEnumerable<Album> Albums; @@ -13,37 +13,130 @@ public class Stub : IDataManager public Stub() { - Artistes = new List<Artiste>(); - Albums = new List<Album>(); - Playlists = new List<Playlist>(); - Titles = new List<Title>(); - - Artiste Artiste1 = new Artiste("Critien"); - Artiste Artiste2 = new Artiste("Gouriet"); - Artiste Artiste3 = new Artiste("Poulifer"); - Artiste Artiste4 = new Artiste("Credian"); + Artist Artiste1 = new Artist("Critien"); + Artist Artiste2 = new Artist("Gouriet"); + Artist Artiste3 = new Artist("Poulifer"); + Artist Artiste4 = new Artist("Credian"); Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); + Album Album2 = new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2"); + Album Album3 = new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3"); Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); Artiste1.AddAlbum(Album1); - Artiste1.AddAlbum(new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2")); - Artiste2.AddAlbum(new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3")); + Artiste1.AddAlbum(Album2); + Artiste2.AddAlbum(Album3); Artiste2.AddAlbum(Album4); Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); - Playlist Playlist3 = new Playlist("Playlist3", "desc3", "url3.png"); - Playlist Playlist4 = new Playlist("Playlist4", "desc4", "url4.png"); - - Playlist1.AddTitle(new CustomTitle("custom1", "url1.png", "info1", "chemin1")); - Playlist1.AddTitle(new CustomTitle("custom2", "url2.png", "info2", "chemin2")); - Playlist1.AddTitle(new CustomTitle("custom3", "url3.png", "info3", "chemin3")); - Playlist2.AddTitle(new CustomTitle("custom4", "url4.png", "info4", "chemin4")); - - Album1.AddTitle(new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP)); - Album1.AddTitle(new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL)); - Album1.AddTitle(new InfoTitle("info3", "url3.png", "info3", Artiste4, "desc3", Genre.BLUES)); - Album4.AddTitle(new InfoTitle("info4", "url4.png", "info4", Artiste3, "desc4", Genre.DISCO)); + + CustomTitle Custom1 = new CustomTitle("custom1", "url1.png", "info1", "chemin1"); + CustomTitle Custom2 = new CustomTitle("custom2", "url2.png", "info2", "chemin2"); + CustomTitle Custom3 = new CustomTitle("custom3", "url3.png", "info3", "chemin3"); + + Playlist1.AddTitle(Custom1); + Playlist1.AddTitle(Custom2); + Playlist2.AddTitle(Custom2); + Playlist2.AddTitle(Custom3); + + InfoTitle Info1 = new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP); + InfoTitle Info2 = new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL); + + Album1.AddTitle(Info1); + Album1.AddTitle(Info2); + Album2.AddTitle(Info2); + + Artists = new List<Artist>() + { + Artiste1, + Artiste2, + Artiste3, + Artiste4 + }; + + Albums = new List<Album>() + { + Album1, + Album2, + Album3, + Album4 + }; + + Playlists = new List<Playlist>() + { + Playlist1, + Playlist2 + }; + + Titles = new List<Title>() + { + Custom1, + Custom2, + Custom3, + Info1, + Info2 + }; + } + + public IEnumerable<Album> GetAlbums() + { + return Albums; + } + + public IEnumerable<Artist> GetArtists() + { + return Artists; + } + + public IEnumerable<Playlist> GetPlaylists() + { + return Playlists; + } + + public IEnumerable<Title> GetTitles() + { + return Titles; + } + + public void AddAlbum(Album album) + { + Albums = Albums.Prepend(album); } + + public void AddTitle(Title title) + { + Titles = Titles.Prepend(title); + } + public void AddPlaylist(Playlist playlist) + { + Playlists = Playlists.Prepend(playlist); + } + + public void AddArtist(Artist artist) + { + Artists = Artists.Prepend(artist); + } + + + + public void RemoveAlbum(Album album) + { + Albums.ToList().Remove(album); + } + + public void RemoveTitle(Title title) + { + Titles.ToList().Remove(title); + } + + public void RemovePlaylist(Playlist playlist) + { + Playlists.ToList().Remove(playlist); + } + + public void RemoveArtist(Artist artist) + { + Artists.ToList().Remove(artist); + } } diff --git a/Sources/Model/Title.cs b/Sources/Model/Title.cs index 1d985e8..0410f66 100644 --- a/Sources/Model/Title.cs +++ b/Sources/Model/Title.cs @@ -15,7 +15,7 @@ } } - private string name; + private string name = "Unknown"; public string ImageURL { @@ -30,7 +30,7 @@ } } - private string imageURL; + private string imageURL = "none.png"; public string Information { @@ -45,7 +45,7 @@ } } - private string information; + private string information =""; public Title(string nom, string file_Name, string informations) { From e8176659d159cfd2d8b42cf86120714e1f06e686 Mon Sep 17 00:00:00 2001 From: Louis LABORIE <laborie.louis@gmail.com> Date: Wed, 3 May 2023 16:08:35 +0200 Subject: [PATCH 04/45] 3/05 Commit Tests Unitaires Attributes --- Sources/Linaris.sln | 10 ++++++-- Sources/Linaris/FooterPage.xaml.cs | 4 +-- Sources/TestUnitaires/TU_Album.cs | 28 ++++++++++++++++++++ Sources/TestUnitaires/TU_Artiste.cs | 20 +++++++++++++++ Sources/TestUnitaires/TU_CustomTitle.cs | 30 ++++++++++++++++++++++ Sources/TestUnitaires/TU_Playlist.cs | 26 +++++++++++++++++++ Sources/TestUnitaires/TU_Title.cs | 26 +++++++++++++++++++ Sources/TestUnitaires/TestUnitaires.csproj | 28 ++++++++++++++++++++ Sources/TestUnitaires/Usings.cs | 1 + 9 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 Sources/TestUnitaires/TU_Album.cs create mode 100644 Sources/TestUnitaires/TU_Artiste.cs create mode 100644 Sources/TestUnitaires/TU_CustomTitle.cs create mode 100644 Sources/TestUnitaires/TU_Playlist.cs create mode 100644 Sources/TestUnitaires/TU_Title.cs create mode 100644 Sources/TestUnitaires/TestUnitaires.csproj create mode 100644 Sources/TestUnitaires/Usings.cs diff --git a/Sources/Linaris.sln b/Sources/Linaris.sln index 6f91fb4..e01685e 100644 --- a/Sources/Linaris.sln +++ b/Sources/Linaris.sln @@ -5,9 +5,11 @@ VisualStudioVersion = 17.0.31611.283 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Linaris", "Linaris\Linaris.csproj", "{9E6281F7-95F6-472C-B268-894CE377C8A9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console\Console.csproj", "{BB50C1E3-5A9A-40AF-8CD7-55B41064290B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "Console\Console.csproj", "{BB50C1E3-5A9A-40AF-8CD7-55B41064290B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{AA1DB94B-8273-437F-A07A-BB1F5F0D278D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{AA1DB94B-8273-437F-A07A-BB1F5F0D278D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaires", "TestUnitaires\TestUnitaires.csproj", "{8B0671CF-1302-4244-8837-916E632007E2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,6 +31,10 @@ Global {AA1DB94B-8273-437F-A07A-BB1F5F0D278D}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA1DB94B-8273-437F-A07A-BB1F5F0D278D}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA1DB94B-8273-437F-A07A-BB1F5F0D278D}.Release|Any CPU.Build.0 = Release|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B0671CF-1302-4244-8837-916E632007E2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index adaa690..a36c9e9 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -19,9 +19,9 @@ public partial class FooterPage : ContentView // (s,a) = convention, s = sender, a = arguments, si appli fermée, on free tout outputDevice.PlaybackStopped += PlaybackStoppedHandler; - morceauEnCours = "D:\\Musique\\Création\\winter.mp3"; + /*morceauEnCours = "Resources/Musics/peaches.mp3"; audioFile = new AudioFileReader(morceauEnCours); - outputDevice.Init(audioFile); + outputDevice.Init(audioFile);*/ } public void PlayButton_Clicked(object sender, EventArgs e) diff --git a/Sources/TestUnitaires/TU_Album.cs b/Sources/TestUnitaires/TU_Album.cs new file mode 100644 index 0000000..13861be --- /dev/null +++ b/Sources/TestUnitaires/TU_Album.cs @@ -0,0 +1,28 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + public class TU_Album + { + [Theory] + [InlineData("Fenêtre sur Rue","album2.jpg","Un banger","Sortie : 2012")] + [InlineData("Adios Bahamas", "album. jpg", "Un banger", "Sortie : 2012")] + [InlineData(null, "album2.jpg", "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende", null, "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende","album1.jpg", null, "Sortie : 2012")] + [InlineData("Dans La Légende", "album1.jpg", "Un banger", null)] + [InlineData("Dans La Légende", "album1jpg", "Un banger", "Sortie : 2012")] + public void TU_Attributes(string nameAlbum, string url, string desc, string info) + { + Assert.True(nameAlbum != null && nameAlbum.Length < 75); + Assert.True(url != null && url.Contains('.')); + Assert.False(url.Contains(' ')); + Assert.True(desc != null && desc.Length < 500); + Assert.True(info != null && info.Length < 500); + + } + + } +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Artiste.cs b/Sources/TestUnitaires/TU_Artiste.cs new file mode 100644 index 0000000..cb12bbd --- /dev/null +++ b/Sources/TestUnitaires/TU_Artiste.cs @@ -0,0 +1,20 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_Artist + { + [Theory] + [InlineData("Hugo TSR")] + [InlineData(null)] + [InlineData("Hugo TSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")] + public void TU_Attributes(string name) + { + Assert.True(name != null && name.Length < 75); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_CustomTitle.cs b/Sources/TestUnitaires/TU_CustomTitle.cs new file mode 100644 index 0000000..03c096c --- /dev/null +++ b/Sources/TestUnitaires/TU_CustomTitle.cs @@ -0,0 +1,30 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_CustomTitle + { + [Theory] + [InlineData("Trajectoire","morceau1.png","Sortie : 2020", "Musique/test.mp3")] + [InlineData(null, "morceau1.png", "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", null, "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1.png", null, "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020", "Musique/test.mp3")] + [InlineData("Trajectoire", "morceau1.png", "Sortie : 2020", null)] + public void TU_Attributes(string name, string url, string info, string path) + { + CustomTitle ct = new CustomTitle(name, url, info, path); + Assert.True(ct.Name != null && ct.Name.Length < 75); + Assert.True(ct.ImageURL != null && ct.ImageURL.Contains('.')); + Assert.False(ct.ImageURL.Contains(' ')); + Assert.True(ct.Information != null && ct.Information.Length < 500); + Assert.True(ct.Path != null && ct.Path.Contains('.')); + Assert.False(ct.Path.Contains(' ')); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Playlist.cs b/Sources/TestUnitaires/TU_Playlist.cs new file mode 100644 index 0000000..f1ca0d0 --- /dev/null +++ b/Sources/TestUnitaires/TU_Playlist.cs @@ -0,0 +1,26 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_Playlist + { + [Theory] + [InlineData("Sons Soirées","red-sky.png","Contient les sons que je mets quand je suis en soirée.")] + [InlineData(null, "red-sky.png", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", null, "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky.png", null)] + [InlineData("Sons Soirées", "redskypng", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky .png", "Contient les sons que je mets quand je suis en soirée.")] + public void TU_Attributes(string name, string url, string desc) + { + Assert.True(name != null && name.Length < 75); + Assert.True(url != null && url.Contains('.')); + Assert.False(url.Contains(' ')); + Assert.True(desc != null && desc.Length < 500); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Title.cs b/Sources/TestUnitaires/TU_Title.cs new file mode 100644 index 0000000..d5162c3 --- /dev/null +++ b/Sources/TestUnitaires/TU_Title.cs @@ -0,0 +1,26 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_Title + { + [Theory] + [InlineData("Trajectoire","morceau1.png","Sortie : 2020")] + [InlineData(null, "morceau1.png", "Sortie : 2020")] + [InlineData("Trajectoire", null, "Sortie : 2020")] + [InlineData("Trajectoire", "morceau1.png", null)] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020")] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020")] + public void TU_Attributes(string name, string url, string info) + { + Assert.True(name != null && name.Length < 75); + Assert.True(url != null && url.Contains('.')); + Assert.False(url.Contains(' ')); + Assert.True(info != null && info.Length < 500); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TestUnitaires.csproj b/Sources/TestUnitaires/TestUnitaires.csproj new file mode 100644 index 0000000..dedc487 --- /dev/null +++ b/Sources/TestUnitaires/TestUnitaires.csproj @@ -0,0 +1,28 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>net7.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + + <IsPackable>false</IsPackable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> + <PackageReference Include="xunit" Version="2.4.2" /> + <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + <PackageReference Include="coverlet.collector" Version="3.1.2"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\Model\Model.csproj" /> + </ItemGroup> + +</Project> diff --git a/Sources/TestUnitaires/Usings.cs b/Sources/TestUnitaires/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Sources/TestUnitaires/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file From 0ff97dbf1aa48b35bd35f2fb1f5fbc3002c2c476 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Wed, 3 May 2023 18:33:10 +0200 Subject: [PATCH 05/45] Finish Stub --- Sources/Console/Program.cs | 92 ++++++++++++- Sources/Model/IDataManager.cs | 8 +- Sources/Model/Manager.cs | 164 +++++++++++++---------- Sources/Model/Playlist.cs | 10 +- Sources/Model/Stub/Stub.cs | 236 +++++++++++++++++++--------------- 5 files changed, 330 insertions(+), 180 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 5a4730d..dec48a1 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -21,15 +21,101 @@ Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); Playlist p1 = Manager.Playlists.First(); -Console.WriteLine(p1.GetCurrentTitle()); +Title? current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); -Console.WriteLine(p1.GetCurrentTitle()); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +p1.Loop = true; +p1.AddTitle(new CustomTitle("Nouveau", "img.png", "infos", "path.mp3")); +p1.Shuffle = true; +Console.WriteLine("--------------------"); + +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +Console.WriteLine("--------------------"); + +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); -Console.WriteLine(p1.GetCurrentTitle()); +Console.WriteLine("--------------------"); + +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +// Quand aléatoire et que retour arrière puis retour avant, musique aléatoire et non celle de base + +Console.WriteLine("--------------------"); + +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); +p1.PreviousTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index c21b2c5..34fbb0f 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -2,13 +2,13 @@ public interface IDataManager { - IEnumerable<Title> GetTitles(); + List<Title> GetTitles(); - IEnumerable<Album> GetAlbums(); + List<Album> GetAlbums(); - IEnumerable<Artist> GetArtists(); + List<Artist> GetArtists(); - IEnumerable<Playlist> GetPlaylists(); + List<Playlist> GetPlaylists(); public void AddAlbum(Album album); diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index ae75df9..e6f11e9 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -1,75 +1,107 @@ -namespace Model.Stub; - -public class Manager -{ - public IDataManager DataManager { get; set; } - - public IEnumerable<Album> Albums; - - public IEnumerable<Title> Titles; - - public IEnumerable<Playlist> Playlists; - - public IEnumerable<Artist> Artists; - - public Manager() - { - DataManager = new Stub(); - - Albums = DataManager.GetAlbums(); - Titles = DataManager.GetTitles(); - Playlists = DataManager.GetPlaylists(); - Artists = DataManager.GetArtists(); - } - - public void AddAlbum(Album album) - { - DataManager.AddAlbum(album); - Albums = DataManager.GetAlbums(); - } - - public void AddTitle(Title title) - { - DataManager.AddTitle(title); - Titles = DataManager.GetTitles(); - } - public void AddPlaylist(Playlist playlist) - { - DataManager.AddPlaylist(playlist); - Playlists = DataManager.GetPlaylists(); - } - - public void RemoveAlbum(Album album) - { - DataManager.RemoveAlbum(album); - Albums = DataManager.GetAlbums(); - } - - public void RemoveTitle(Title title) - { - DataManager.RemoveTitle(title); - Titles = DataManager.GetTitles(); - } - - public void RemovePlaylist(Playlist playlist) - { - DataManager.RemovePlaylist(playlist); - Playlists = DataManager.GetPlaylists(); - } - +namespace Model.Stub; + +public class Manager +{ + public IDataManager DataManager { get; set; } + + private List<Album> albums = new List<Album>(); + + public IEnumerable<Album> Albums + { + get + { + return albums; + } + } + + private List<Title> titles = new List<Title>(); + + public IEnumerable<Title> Titles + { + get + { + return titles; + } + } + + private List<Playlist> playlists = new List<Playlist>(); + + public IEnumerable<Playlist> Playlists + { + get + { + return playlists; + } + } + + private List<Artist> artists = new List<Artist>(); + + public IEnumerable<Artist> Artists + { + get + { + return artists; + } + } + + public Manager() + { + DataManager = new Stub(); + + albums = DataManager.GetAlbums(); + titles = DataManager.GetTitles(); + playlists = DataManager.GetPlaylists(); + artists = DataManager.GetArtists(); + } + + public void AddAlbum(Album album) + { + DataManager.AddAlbum(album); + albums = DataManager.GetAlbums(); + } + + public void AddTitle(Title title) + { + DataManager.AddTitle(title); + titles = DataManager.GetTitles(); + } + public void AddPlaylist(Playlist playlist) + { + DataManager.AddPlaylist(playlist); + playlists = DataManager.GetPlaylists(); + } + + public void RemoveAlbum(Album album) + { + DataManager.RemoveAlbum(album); + albums = DataManager.GetAlbums(); + } + + public void RemoveTitle(Title title) + { + DataManager.RemoveTitle(title); + titles = DataManager.GetTitles(); + } + + public void RemovePlaylist(Playlist playlist) + { + DataManager.RemovePlaylist(playlist); + playlists = DataManager.GetPlaylists(); + } + public IEnumerable<Album> GetAlbums() { return DataManager.GetAlbums(); - } - + } + public IEnumerable<Title> GetTitles() { return DataManager.GetTitles(); - } - + } + public IEnumerable<Artist> GetArtists() { return DataManager.GetArtists(); - } - -} + } + +} diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 29f798b..53265b7 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -128,7 +128,7 @@ public class Playlist } else { - Index = Aleatoire.Next(morceaux.Count() - 1); + Index = Aleatoire.Next(morceaux.Count()); played.Add(Index); } } @@ -143,7 +143,7 @@ public class Playlist if(!Shuffle) { Index--; - played.RemoveAt(0); + played.RemoveAt(played.Count - 1); } else { @@ -151,14 +151,14 @@ public class Playlist { return; } - Index = played[0]; - played.RemoveAt(0); + Index = played[played.Count - 1]; + played.RemoveAt(played.Count - 1); } } public Title? GetCurrentTitle() { - if (Index < morceaux.Count() - 1) + if (Index < morceaux.Count()) { return morceaux[Index]; } diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/Stub.cs index 2b4b96b..672bdd4 100644 --- a/Sources/Model/Stub/Stub.cs +++ b/Sources/Model/Stub/Stub.cs @@ -1,142 +1,174 @@ -namespace Model.Stub; - -public class Stub : IDataManager -{ - - public IEnumerable<Artist> Artists; - - public IEnumerable<Album> Albums; - - public IEnumerable<Playlist> Playlists; - - public IEnumerable<Title> Titles; - - public Stub() - { - Artist Artiste1 = new Artist("Critien"); - Artist Artiste2 = new Artist("Gouriet"); - Artist Artiste3 = new Artist("Poulifer"); - Artist Artiste4 = new Artist("Credian"); - - Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); - Album Album2 = new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2"); - Album Album3 = new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3"); - Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); - - Artiste1.AddAlbum(Album1); - Artiste1.AddAlbum(Album2); - Artiste2.AddAlbum(Album3); - Artiste2.AddAlbum(Album4); - - Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); - Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); - - CustomTitle Custom1 = new CustomTitle("custom1", "url1.png", "info1", "chemin1"); - CustomTitle Custom2 = new CustomTitle("custom2", "url2.png", "info2", "chemin2"); - CustomTitle Custom3 = new CustomTitle("custom3", "url3.png", "info3", "chemin3"); - - Playlist1.AddTitle(Custom1); - Playlist1.AddTitle(Custom2); - Playlist2.AddTitle(Custom2); - Playlist2.AddTitle(Custom3); - - InfoTitle Info1 = new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP); - InfoTitle Info2 = new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL); - - Album1.AddTitle(Info1); - Album1.AddTitle(Info2); - Album2.AddTitle(Info2); - - Artists = new List<Artist>() +namespace Model.Stub; + +public class Stub : IDataManager +{ + + private List<Artist> artists = new List<Artist>(); + + public IEnumerable<Artist> Artists + { + get + { + return artists; + } + } + + private List<Album> albums = new List<Album>(); + + public IEnumerable<Album> Albums + { + get + { + return albums; + } + } + + private List<Playlist> playlists = new List<Playlist>(); + + public IEnumerable<Playlist> Playlists + { + get + { + return playlists; + } + } + + private List<Title> titles = new List<Title>(); + + public IEnumerable<Title> Titles + { + get + { + return titles; + } + } + + public Stub() + { + Artist Artiste1 = new Artist("Critien"); + Artist Artiste2 = new Artist("Gouriet"); + Artist Artiste3 = new Artist("Poulifer"); + Artist Artiste4 = new Artist("Credian"); + + Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); + Album Album2 = new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2"); + Album Album3 = new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3"); + Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); + + Artiste1.AddAlbum(Album1); + Artiste1.AddAlbum(Album2); + Artiste2.AddAlbum(Album3); + Artiste2.AddAlbum(Album4); + + Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); + Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); + + CustomTitle Custom1 = new CustomTitle("MaMusique", "url1.png", "info1", "chemin1"); + CustomTitle Custom2 = new CustomTitle("MusiqueGeniale", "url2.png", "info2", "chemin2"); + CustomTitle Custom3 = new CustomTitle("custom3", "url3.png", "info3", "chemin3"); + + Playlist1.AddTitle(Custom1); + Playlist1.AddTitle(Custom2); + Playlist2.AddTitle(Custom2); + Playlist2.AddTitle(Custom3); + + InfoTitle Info1 = new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP); + InfoTitle Info2 = new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL); + + Album1.AddTitle(Info1); + Album1.AddTitle(Info2); + Album2.AddTitle(Info2); + + artists = new List<Artist>() { Artiste1, Artiste2, Artiste3, Artiste4 - }; - - Albums = new List<Album>() + }; + + albums = new List<Album>() { Album1, Album2, Album3, Album4 - }; - - Playlists = new List<Playlist>() + }; + + playlists = new List<Playlist>() { Playlist1, Playlist2 - }; - - Titles = new List<Title>() + }; + + titles = new List<Title>() { Custom1, Custom2, Custom3, Info1, Info2 - }; + }; + } + + public List<Album> GetAlbums() + { + return albums; + } + + public List<Artist> GetArtists() + { + return artists; } - public IEnumerable<Album> GetAlbums() + public List<Playlist> GetPlaylists() { - return Albums; + return playlists; } - public IEnumerable<Artist> GetArtists() + public List<Title> GetTitles() { - return Artists; + return titles; } - public IEnumerable<Playlist> GetPlaylists() + public void AddAlbum(Album album) { - return Playlists; + albums.Add(album); } - public IEnumerable<Title> GetTitles() + public void AddTitle(Title title) { - return Titles; + titles.Add(title); + } + public void AddPlaylist(Playlist playlist) + { + playlists.Add(playlist); } - public void AddAlbum(Album album) - { - Albums = Albums.Prepend(album); - } - - public void AddTitle(Title title) - { - Titles = Titles.Prepend(title); - } - public void AddPlaylist(Playlist playlist) - { - Playlists = Playlists.Prepend(playlist); - } - public void AddArtist(Artist artist) { - Artists = Artists.Prepend(artist); - } - - - - public void RemoveAlbum(Album album) - { - Albums.ToList().Remove(album); - } - - public void RemoveTitle(Title title) - { - Titles.ToList().Remove(title); - } - - public void RemovePlaylist(Playlist playlist) - { - Playlists.ToList().Remove(playlist); + artists.Add(artist); + } + + + + public void RemoveAlbum(Album album) + { + albums.Remove(album); + } + + public void RemoveTitle(Title title) + { + titles.Remove(title); + } + + public void RemovePlaylist(Playlist playlist) + { + playlists.Remove(playlist); } public void RemoveArtist(Artist artist) { - Artists.ToList().Remove(artist); + artists.Remove(artist); } -} +} From d19d4c7d25f28856d42c5b7c05a46f5302209700 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Wed, 3 May 2023 18:42:58 +0200 Subject: [PATCH 06/45] Enhance Stub by creating stub classes --- Sources/Model/Album.cs | 2 +- Sources/Model/Artist.cs | 2 +- Sources/Model/Artiste.cs | 32 ------------------- Sources/Model/InfoTitle.cs | 2 +- Sources/Model/Manager.cs | 10 +++--- Sources/Model/Playlist.cs | 4 +-- Sources/Model/Stub/StubAlbum.cs | 6 ++++ Sources/Model/Stub/StubArtist.cs | 6 ++++ Sources/Model/Stub/StubCustomTitle.cs | 6 ++++ Sources/Model/Stub/StubInfoTitle.cs | 6 ++++ .../Model/Stub/{Stub.cs => StubManager.cs} | 12 +++---- Sources/Model/Stub/StubPlaylist.cs | 6 ++++ Sources/Model/Stub/StubTitle.cs | 6 ++++ 13 files changed, 52 insertions(+), 48 deletions(-) delete mode 100644 Sources/Model/Artiste.cs create mode 100644 Sources/Model/Stub/StubAlbum.cs create mode 100644 Sources/Model/Stub/StubArtist.cs create mode 100644 Sources/Model/Stub/StubCustomTitle.cs create mode 100644 Sources/Model/Stub/StubInfoTitle.cs rename Sources/Model/Stub/{Stub.cs => StubManager.cs} (90%) create mode 100644 Sources/Model/Stub/StubPlaylist.cs create mode 100644 Sources/Model/Stub/StubTitle.cs diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 4ef7959..a2beba3 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -38,7 +38,7 @@ { get { - return Titles; + return titles.ToList(); } } diff --git a/Sources/Model/Artist.cs b/Sources/Model/Artist.cs index c638dfd..a5b8e48 100644 --- a/Sources/Model/Artist.cs +++ b/Sources/Model/Artist.cs @@ -23,7 +23,7 @@ public class Artist { get { - return albums; + return albums.ToList(); } } diff --git a/Sources/Model/Artiste.cs b/Sources/Model/Artiste.cs deleted file mode 100644 index bcab081..0000000 --- a/Sources/Model/Artiste.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Model; - -public class Artiste -{ - public string Name - { - get => name; - - set - { - if (value != null && value.Length < 75) - { - name = value; - } - } - } - - private string name = "Unknown"; - - public IEnumerable<Album> Albums { get; set; } - - public Artiste(string name) - { - Name = name; - Albums = new List<Album>(); - } - - public void AddAlbum(Album album) - { - Albums.Prepend(album); - } -} diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index 8df3a81..2c6b46a 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -25,7 +25,7 @@ public class InfoTitle : Title { get { - return feat; + return feat.ToList(); } } diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index e6f11e9..02bb855 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -10,7 +10,7 @@ public class Manager { get { - return albums; + return albums.ToList(); } } @@ -20,7 +20,7 @@ public class Manager { get { - return titles; + return titles.ToList(); } } @@ -30,7 +30,7 @@ public class Manager { get { - return playlists; + return playlists.ToList(); } } @@ -40,13 +40,13 @@ public class Manager { get { - return artists; + return artists.ToList(); } } public Manager() { - DataManager = new Stub(); + DataManager = new StubManager(); albums = DataManager.GetAlbums(); titles = DataManager.GetTitles(); diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 53265b7..3d30732 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -37,7 +37,7 @@ public class Playlist public IEnumerable<Title> Morceaux { get { - return morceaux; + return morceaux.ToList(); } } @@ -93,7 +93,7 @@ public class Playlist { get { - return played; + return played.ToList(); } } diff --git a/Sources/Model/Stub/StubAlbum.cs b/Sources/Model/Stub/StubAlbum.cs new file mode 100644 index 0000000..396733b --- /dev/null +++ b/Sources/Model/Stub/StubAlbum.cs @@ -0,0 +1,6 @@ +namespace Model.Stub; + +public class StubAlbum +{ + +} diff --git a/Sources/Model/Stub/StubArtist.cs b/Sources/Model/Stub/StubArtist.cs new file mode 100644 index 0000000..ef769b1 --- /dev/null +++ b/Sources/Model/Stub/StubArtist.cs @@ -0,0 +1,6 @@ +namespace Model.Stub; + +public class StubArtist +{ + +} diff --git a/Sources/Model/Stub/StubCustomTitle.cs b/Sources/Model/Stub/StubCustomTitle.cs new file mode 100644 index 0000000..b49a895 --- /dev/null +++ b/Sources/Model/Stub/StubCustomTitle.cs @@ -0,0 +1,6 @@ +namespace Model.Stub; + +public class StubCustomTitle +{ + +} diff --git a/Sources/Model/Stub/StubInfoTitle.cs b/Sources/Model/Stub/StubInfoTitle.cs new file mode 100644 index 0000000..8dbade2 --- /dev/null +++ b/Sources/Model/Stub/StubInfoTitle.cs @@ -0,0 +1,6 @@ +namespace Model.Stub; + +public class StubInfoTitle +{ + +} diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/StubManager.cs similarity index 90% rename from Sources/Model/Stub/Stub.cs rename to Sources/Model/Stub/StubManager.cs index 672bdd4..4642fcd 100644 --- a/Sources/Model/Stub/Stub.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -1,6 +1,6 @@ namespace Model.Stub; -public class Stub : IDataManager +public class StubManager : IDataManager { private List<Artist> artists = new List<Artist>(); @@ -9,7 +9,7 @@ public class Stub : IDataManager { get { - return artists; + return artists.ToList(); } } @@ -19,7 +19,7 @@ public class Stub : IDataManager { get { - return albums; + return albums.ToList(); } } @@ -29,7 +29,7 @@ public class Stub : IDataManager { get { - return playlists; + return playlists.ToList(); } } @@ -39,11 +39,11 @@ public class Stub : IDataManager { get { - return titles; + return titles.ToList(); } } - public Stub() + public StubManager() { Artist Artiste1 = new Artist("Critien"); Artist Artiste2 = new Artist("Gouriet"); diff --git a/Sources/Model/Stub/StubPlaylist.cs b/Sources/Model/Stub/StubPlaylist.cs new file mode 100644 index 0000000..b07415c --- /dev/null +++ b/Sources/Model/Stub/StubPlaylist.cs @@ -0,0 +1,6 @@ +namespace Model.Stub; + +public class StubPlaylist +{ + +} diff --git a/Sources/Model/Stub/StubTitle.cs b/Sources/Model/Stub/StubTitle.cs new file mode 100644 index 0000000..f403fe9 --- /dev/null +++ b/Sources/Model/Stub/StubTitle.cs @@ -0,0 +1,6 @@ +namespace Model.Stub; + +public class StubTitle +{ + +} From 097fb5c257a09c374ac1c878be8952e82f559c3c Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Wed, 3 May 2023 19:40:32 +0200 Subject: [PATCH 07/45] Enhance UT --- Sources/Console/Program.cs | 2 +- Sources/Linaris/FooterPage.xaml.cs | 2 +- Sources/Model/Album.cs | 11 ++++++++++- Sources/TestUnitaires/TU_Album.cs | 16 ++++++++-------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index fb87e4e..4c93076 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -1,6 +1,6 @@ using Model; - +Console.WriteLine("---"); // See https://aka.ms/new-console-template for more information /*Album a = new Album("Adios Bahamas", "album1.jpg", "Népal"); diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index a36c9e9..8176381 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -9,7 +9,7 @@ public partial class FooterPage : ContentView System.Timers.Timer timer; bool changementManuel = true; bool closing = false; - string morceauEnCours; + // string morceauEnCours; public FooterPage() { diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 7dab8f9..32a57eb 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -40,7 +40,16 @@ set { - if (value != null && value.Contains('.')) + if (value == null || !value.Contains('.')) + { + value = "none.png"; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '\\'); + } + if (value.Contains('.')) { imageURL = value; } diff --git a/Sources/TestUnitaires/TU_Album.cs b/Sources/TestUnitaires/TU_Album.cs index 13861be..3c7966a 100644 --- a/Sources/TestUnitaires/TU_Album.cs +++ b/Sources/TestUnitaires/TU_Album.cs @@ -7,8 +7,8 @@ namespace TestUnitaires public class TU_Album { [Theory] - [InlineData("Fenêtre sur Rue","album2.jpg","Un banger","Sortie : 2012")] - [InlineData("Adios Bahamas", "album. jpg", "Un banger", "Sortie : 2012")] + [InlineData("Fenêtre sur Rue","album2. jpg","Un banger","Sortie : 2012")] + [InlineData("Adios Bahamas", "album.jpg", "Un banger", "Sortie : 2012")] [InlineData(null, "album2.jpg", "Un banger", "Sortie : 2012")] [InlineData("Dans La Légende", null, "Un banger", "Sortie : 2012")] [InlineData("Dans La Légende","album1.jpg", null, "Sortie : 2012")] @@ -16,12 +16,12 @@ namespace TestUnitaires [InlineData("Dans La Légende", "album1jpg", "Un banger", "Sortie : 2012")] public void TU_Attributes(string nameAlbum, string url, string desc, string info) { - Assert.True(nameAlbum != null && nameAlbum.Length < 75); - Assert.True(url != null && url.Contains('.')); - Assert.False(url.Contains(' ')); - Assert.True(desc != null && desc.Length < 500); - Assert.True(info != null && info.Length < 500); - + Album album = new Album(nameAlbum, url, new Artiste("test"), desc, info); + Assert.True(album.Name != null && album.Name.Length < 75); + Assert.True(album.ImageURL != null && album.ImageURL.Contains('.')); + Assert.False(album.ImageURL.Contains(' ')); + Assert.True(album.Description != null && album.Description.Length < 500); + Assert.True(album.Information != null && album.Information.Length < 500); } } From a774e0c904ea726230db9d4877a3664d033cedac Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Fri, 5 May 2023 13:30:39 +0200 Subject: [PATCH 08/45] Add .drone.yml and activated drone --- .drone.yml | 23 +++++++++++++++++++++++ Sources/Linaris/Linaris.csproj | 6 ++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0696232 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,23 @@ +kind: pipeline +type: docker +name: CI_Linaris_pipeline + +trigger: + event: + - push + +steps: + - name: build + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + - dotnet publish MyMauiApp/MyMauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - name: tests + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + depends_on: [build] diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj index bbcc06b..787cfe8 100644 --- a/Sources/Linaris/Linaris.csproj +++ b/Sources/Linaris/Linaris.csproj @@ -1,8 +1,10 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks> - <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks> + <TargetFrameworks>net7.0-android</TargetFrameworks> + <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks> + <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('ios'))">$(TargetFrameworks);net7.0-ios</TargetFrameworks> + <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('maccatalyst'))">$(TargetFrameworks);net7.0-maccatalyst</TargetFrameworks> <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET --> <!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> --> <OutputType>Exe</OutputType> From 38ccaf6a270076535367948e8f863cfc067152cb Mon Sep 17 00:00:00 2001 From: Louis LABORIE <louis.laborie@etu.uca.fr> Date: Sat, 6 May 2023 09:09:58 +0200 Subject: [PATCH 09/45] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'Sources/Conn?= =?UTF-8?q?sole/Program.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add line to build --- Sources/Connsole/Program.cs | 51 +++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/Sources/Connsole/Program.cs b/Sources/Connsole/Program.cs index fb87e4e..e568c3b 100644 --- a/Sources/Connsole/Program.cs +++ b/Sources/Connsole/Program.cs @@ -1,25 +1,26 @@ -using Model; - - -// See https://aka.ms/new-console-template for more information - -/*Album a = new Album("Adios Bahamas", "album1.jpg", "Népal"); -Album a1 = new Album("Fenêtre sur Rue", "album3.jpg", "HugoTSR"); -Album a2 = new Album("Dans la Légende", "album8.jpg", "PNL"); - -List<Album> lst = new List<Album> { a1, a2, a }; - -foreach (Album album in lst) -{ - Console.WriteLine($"Nom de l'album : " + album.Nom); - - Console.WriteLine($"Nom du fichier : " + album.File_Name); - - Console.WriteLine($"Artiste : " + album.Artiste); - - Console.WriteLine($"-------------------------"); -}*/ - - - - +using Model; + +Console.WriteLine("---"); + +// See https://aka.ms/new-console-template for more information + +/*Album a = new Album("Adios Bahamas", "album1.jpg", "Népal"); +Album a1 = new Album("Fenêtre sur Rue", "album3.jpg", "HugoTSR"); +Album a2 = new Album("Dans la Légende", "album8.jpg", "PNL"); + +List<Album> lst = new List<Album> { a1, a2, a }; + +foreach (Album album in lst) +{ + Console.WriteLine($"Nom de l'album : " + album.Nom); + + Console.WriteLine($"Nom du fichier : " + album.File_Name); + + Console.WriteLine($"Artiste : " + album.Artiste); + + Console.WriteLine($"-------------------------"); +}*/ + + + + From b238fadee6bf21984ec715f4952251e491efafc1 Mon Sep 17 00:00:00 2001 From: Louis LABORIE <louis.laborie@etu.uca.fr> Date: Sat, 6 May 2023 09:25:59 +0200 Subject: [PATCH 10/45] Update project name for Drone --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 0696232..a6cb69c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,7 +13,7 @@ steps: - cd Sources/ - dotnet restore Linaris.sln - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 - - dotnet publish MyMauiApp/MyMauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - dotnet publish Linaris/Linaris.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk - name: tests image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest commands: From caf7a23ae231405a2c0331211449d55795a15293 Mon Sep 17 00:00:00 2001 From: Louis LABORIE <laborie.louis1@gmail.com> Date: Sat, 6 May 2023 09:42:25 +0200 Subject: [PATCH 11/45] Add Artist's methods UT ; Trying to trigger events on buttons --- Sources/Linaris/MainPage.xaml.cs | 11 ++++++++++- Sources/TestUnitaires/TU_Artiste.cs | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Sources/Linaris/MainPage.xaml.cs b/Sources/Linaris/MainPage.xaml.cs index 9e8598f..de3a24b 100644 --- a/Sources/Linaris/MainPage.xaml.cs +++ b/Sources/Linaris/MainPage.xaml.cs @@ -7,7 +7,8 @@ public partial class MainPage : ContentPage public MainPage() { InitializeComponent(); - } + + } /*private void OnCounterClicked(object sender, EventArgs e) { @@ -20,5 +21,13 @@ public partial class MainPage : ContentPage SemanticScreenReader.Announce(CounterBtn.Text); }*/ + + /*async public void Go_Home() + { + await Navigation.PushAsync(new MainPage()); + + }*/ + + } diff --git a/Sources/TestUnitaires/TU_Artiste.cs b/Sources/TestUnitaires/TU_Artiste.cs index cb12bbd..4b24884 100644 --- a/Sources/TestUnitaires/TU_Artiste.cs +++ b/Sources/TestUnitaires/TU_Artiste.cs @@ -15,6 +15,21 @@ namespace TestUnitaires { Assert.True(name != null && name.Length < 75); } + + [Theory] + [InlineData("Hugo TSR")] + [InlineData(null)] + [InlineData("Hugo TSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")] + public void TU_Methods(string name) + { + Artiste a = new Artiste(name); + Album a1 = new Album("Fenêtre sur Rue", "album2. jpg", a, "Un banger", "Sortie : 2012"); + List<Album> verif = new List<Album>(); + verif.Add(a1); + a.AddAlbum(a1); + Assert.True(a.Albums == verif); + + } } } \ No newline at end of file From d2886147316db3b332ec07cfd8f4629ccc1514b0 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 6 May 2023 10:57:16 +0200 Subject: [PATCH 12/45] Activate SonarQube --- .drone.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.drone.yml b/.drone.yml index a6cb69c..1620d40 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,3 +21,21 @@ steps: - dotnet restore Linaris.sln - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 depends_on: [build] + - name: code-inspection + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7-maui + secrets: [ SECRET_SONAR_LOGIN ] + environment: + sonar_host: https://codefirst.iut.uca.fr/sonar/ + sonar_token: + from_secret: SECRET_SONAR_LOGIN + project_key: Linaris_LEMAIRE_LABORIE + coverage_exclusions: "Tests/**" + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} + - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - dotnet sonarscanner end /d:sonar.login=$${sonar_token} From c3e75af248bfb8f92635ae6273f92a48f96d81e3 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 6 May 2023 11:00:52 +0200 Subject: [PATCH 13/45] Fix dependencies --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index 1620d40..fb038e6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,3 +39,4 @@ steps: - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk - dotnet sonarscanner end /d:sonar.login=$${sonar_token} + depends on: [tests] From eabc98da0a60863d25332bd5dc0ad7f86bc6702f Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 6 May 2023 11:08:16 +0200 Subject: [PATCH 14/45] Comment lines waiting for tests merge --- .drone.yml | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.drone.yml b/.drone.yml index fb038e6..172afe1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -14,29 +14,29 @@ steps: - dotnet restore Linaris.sln - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 - dotnet publish Linaris/Linaris.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk - - name: tests - image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest - commands: - - cd Sources/ - - dotnet restore Linaris.sln - - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 - depends_on: [build] - - name: code-inspection - image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7-maui - secrets: [ SECRET_SONAR_LOGIN ] - environment: - sonar_host: https://codefirst.iut.uca.fr/sonar/ - sonar_token: - from_secret: SECRET_SONAR_LOGIN - project_key: Linaris_LEMAIRE_LABORIE - coverage_exclusions: "Tests/**" - commands: - - cd Sources/ - - dotnet restore Linaris.sln - - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} - - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 - - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" - - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" - - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk - - dotnet sonarscanner end /d:sonar.login=$${sonar_token} - depends on: [tests] +# - name: tests +# image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest +# commands: +# - cd Sources/ +# - dotnet restore Linaris.sln +# - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 +# depends_on: [build] +# - name: code-inspection +# image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7-maui +# secrets: [ SECRET_SONAR_LOGIN ] +# environment: +# sonar_host: https://codefirst.iut.uca.fr/sonar/ +# sonar_token: +# from_secret: SECRET_SONAR_LOGIN +# project_key: Linaris_LEMAIRE_LABORIE +# coverage_exclusions: "Tests/**" +# commands: +# - cd Sources/ +# - dotnet restore Linaris.sln +# - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} +# - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 +# - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" +# - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" +# - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk +# - dotnet sonarscanner end /d:sonar.login=$${sonar_token} +# depends on: [tests] From 2ae2b72997b621cb7a5c8e746f207678207fe0e4 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 6 May 2023 12:05:21 +0200 Subject: [PATCH 15/45] Split stubs --- Sources/Model/Stub/StubAlbum.cs | 53 +++++++- Sources/Model/Stub/StubArtist.cs | 28 +++++ Sources/Model/Stub/StubCustomTitle.cs | 22 ++++ Sources/Model/Stub/StubInfoTitle.cs | 51 ++++++++ Sources/Model/Stub/StubManager.cs | 171 ++++++++++++++++---------- Sources/Model/Stub/StubPlaylist.cs | 21 ++++ Sources/Model/Stub/StubTitle.cs | 6 - 7 files changed, 283 insertions(+), 69 deletions(-) delete mode 100644 Sources/Model/Stub/StubTitle.cs diff --git a/Sources/Model/Stub/StubAlbum.cs b/Sources/Model/Stub/StubAlbum.cs index 396733b..87de42e 100644 --- a/Sources/Model/Stub/StubAlbum.cs +++ b/Sources/Model/Stub/StubAlbum.cs @@ -1,6 +1,57 @@ -namespace Model.Stub; +using System.Linq; + +namespace Model.Stub; public class StubAlbum { + public List<Artist> Artists + { + get => artists; + } + + private List<Artist> artists; + + public List<Album> Albums + { + get => albums; + } + + private List<Album> albums; + + public StubAlbum() + { + albums = new List<Album>(); + StubArtist stubArtist = new StubArtist(); + artists = stubArtist.GetArtists(); + Artist? Artist1 = Artists.FirstOrDefault(a => a.Name == "Critien"); + if (Artist1 != null) + { + Album Album1 = new Album("la street", "lastreet.png", Artist1, "c'est la street", "plein d'infos1"); + Album Album2 = new Album("la jsp", "oui.png", Artist1, "c'est la couri", "plein d'infos2"); + albums.Add(Album1); + albums.Add(Album2); + } + Artist? Artist2 = Artists.FirstOrDefault(a => a.Name == "Gouriet"); + if (Artist2 != null) + { + + } + Artist? Artist3 = Artists.FirstOrDefault(a => a.Name == "Poulifer"); + if (Artist3 != null) + { + Album Album3 = new Album("la pas le temps", "non.png", Artist3, "c'est pas la street", "plein d'infos3"); + albums.Add(Album3); + } + Artist? Artist4 = Artists.FirstOrDefault(a => a.Name == "Credian"); + if (Artist4 != null) + { + Album Album4 = new Album("la pas le choix", "peutetre.png", Artist4, "c'est la parterre", "plein d'infos4"); + albums.Add(Album4); + } + } + public List<Album> GetAlbums() + { + return albums; + } } diff --git a/Sources/Model/Stub/StubArtist.cs b/Sources/Model/Stub/StubArtist.cs index ef769b1..d7bc027 100644 --- a/Sources/Model/Stub/StubArtist.cs +++ b/Sources/Model/Stub/StubArtist.cs @@ -2,5 +2,33 @@ public class StubArtist { + public List<Artist> Artists + { + get => artists; + } + private List<Artist> artists; + + public StubArtist() + { + Artist Artiste1 = new Artist("Critien"); + Artist Artiste2 = new Artist("Gouriet"); + Artist Artiste3 = new Artist("Poulifer"); + Artist Artiste4 = new Artist("Credian"); + + /*Artiste1.AddAlbum(Album1); + Artiste1.AddAlbum(Album2); + Artiste2.AddAlbum(Album3); + Artiste2.AddAlbum(Album4);*/ + + artists = new List<Artist>() + { + Artiste1, Artiste2, Artiste3, Artiste4 + }; + } + + public List<Artist> GetArtists() + { + return artists; + } } diff --git a/Sources/Model/Stub/StubCustomTitle.cs b/Sources/Model/Stub/StubCustomTitle.cs index b49a895..0137ae2 100644 --- a/Sources/Model/Stub/StubCustomTitle.cs +++ b/Sources/Model/Stub/StubCustomTitle.cs @@ -3,4 +3,26 @@ public class StubCustomTitle { + public List<CustomTitle> CustomTitles + { + get => customTitles; + } + + private List<CustomTitle> customTitles; + + public StubCustomTitle() + { + CustomTitle Custom1 = new CustomTitle("MaMusique", "url1.png", "info1", "chemin1"); + CustomTitle Custom2 = new CustomTitle("MusiqueGeniale", "url2.png", "info2", "chemin2"); + CustomTitle Custom3 = new CustomTitle("custom3", "url3.png", "info3", "chemin3"); + customTitles = new List<CustomTitle>() + { + Custom1, Custom2, Custom3 + }; + } + + public List<CustomTitle> GetCustomTitles() + { + return customTitles; + } } diff --git a/Sources/Model/Stub/StubInfoTitle.cs b/Sources/Model/Stub/StubInfoTitle.cs index 8dbade2..7dba94d 100644 --- a/Sources/Model/Stub/StubInfoTitle.cs +++ b/Sources/Model/Stub/StubInfoTitle.cs @@ -3,4 +3,55 @@ public class StubInfoTitle { + public List<Artist> Artists + { + get => artists; + } + + private List<Artist> artists; + + public List<InfoTitle> InfoTitles + { + get => infoTitles; + } + + private List<InfoTitle> infoTitles; + + public StubInfoTitle() + { + infoTitles = new List<InfoTitle>(); + StubArtist stubArtist = new StubArtist(); + artists = stubArtist.GetArtists(); + + Artist? Artist1 = Artists.FirstOrDefault(a => a.Name == "Critien"); + if (Artist1 != null) + { + + } + + Artist? Artist2 = Artists.FirstOrDefault(a => a.Name == "Gouriets"); + if (Artist2 != null) + { + InfoTitle InfoTitle1 = new InfoTitle("info1", "url1.png", "info1", Artist2, "desc1", Genre.K_POP); + infoTitles.Add(InfoTitle1); + } + + Artist? Artist3 = Artists.FirstOrDefault(a => a.Name == "Poulifer"); + if (Artist3 != null) + { + InfoTitle InfoTitle2 = new InfoTitle("info2", "url2.png", "info2", Artist3, "desc2", Genre.GOSPEL); + infoTitles.Add(InfoTitle2); + } + + Artist? Artist4 = Artists.FirstOrDefault(a => a.Name == "Credian"); + if (Artist4 != null) + { + + } + } + + public List<InfoTitle> GetInfoTitles() + { + return infoTitles; + } } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 4642fcd..b7836c3 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -3,7 +3,7 @@ public class StubManager : IDataManager { - private List<Artist> artists = new List<Artist>(); + private List<Artist> artists; public IEnumerable<Artist> Artists { @@ -13,7 +13,7 @@ public class StubManager : IDataManager } } - private List<Album> albums = new List<Album>(); + private List<Album> albums; public IEnumerable<Album> Albums { @@ -23,7 +23,7 @@ public class StubManager : IDataManager } } - private List<Playlist> playlists = new List<Playlist>(); + private List<Playlist> playlists; public IEnumerable<Playlist> Playlists { @@ -33,82 +33,124 @@ public class StubManager : IDataManager } } - private List<Title> titles = new List<Title>(); + private List<InfoTitle> infoTitles; - public IEnumerable<Title> Titles + public IEnumerable<InfoTitle> InfoTitles { get { - return titles.ToList(); + return infoTitles.ToList(); + } + } + + private List<CustomTitle> customTitles; + + public IEnumerable<CustomTitle> CustomTitles + { + get + { + return customTitles.ToList(); } } public StubManager() { - Artist Artiste1 = new Artist("Critien"); - Artist Artiste2 = new Artist("Gouriet"); - Artist Artiste3 = new Artist("Poulifer"); - Artist Artiste4 = new Artist("Credian"); + StubAlbum stubAlbum = new StubAlbum(); + albums = stubAlbum.GetAlbums(); - Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); - Album Album2 = new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2"); - Album Album3 = new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3"); - Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); + StubPlaylist stubPlaylist = new StubPlaylist(); + playlists = stubPlaylist.GetPlaylists(); - Artiste1.AddAlbum(Album1); - Artiste1.AddAlbum(Album2); - Artiste2.AddAlbum(Album3); - Artiste2.AddAlbum(Album4); + StubArtist stubArtist = new StubArtist(); + artists = stubArtist.GetArtists(); - Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); - Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); + StubInfoTitle stubInfoTitle = new StubInfoTitle(); + infoTitles = stubInfoTitle.GetInfoTitles(); - CustomTitle Custom1 = new CustomTitle("MaMusique", "url1.png", "info1", "chemin1"); - CustomTitle Custom2 = new CustomTitle("MusiqueGeniale", "url2.png", "info2", "chemin2"); - CustomTitle Custom3 = new CustomTitle("custom3", "url3.png", "info3", "chemin3"); + StubCustomTitle stubCustomTitle = new StubCustomTitle(); + customTitles = stubCustomTitle.GetCustomTitles(); - Playlist1.AddTitle(Custom1); - Playlist1.AddTitle(Custom2); - Playlist2.AddTitle(Custom2); - Playlist2.AddTitle(Custom3); + Artist? Artist1 = Artists.FirstOrDefault(a => a.Name == "Critien"); + Artist? Artist2 = Artists.FirstOrDefault(a => a.Name == "Gouriet"); + Artist? Artist3 = Artists.FirstOrDefault(a => a.Name == "Poulifer"); + Artist? Artist4 = Artists.FirstOrDefault(a => a.Name == "Credian"); - InfoTitle Info1 = new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP); - InfoTitle Info2 = new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL); + Album? Album1 = Albums.FirstOrDefault(a => a.Name == "la street"); + Album? Album2 = Albums.FirstOrDefault(a => a.Name == "la jsp"); + Album? Album3 = Albums.FirstOrDefault(a => a.Name == "la pas le temps"); + Album? Album4 = Albums.FirstOrDefault(a => a.Name == "la pas le choix"); - Album1.AddTitle(Info1); - Album1.AddTitle(Info2); - Album2.AddTitle(Info2); + Playlist? Playlist1 = Playlists.FirstOrDefault(a => a.Name == "Playlist1"); + Playlist? Playlist2 = Playlists.FirstOrDefault(a => a.Name == "Playlist2"); - artists = new List<Artist>() - { - Artiste1, - Artiste2, - Artiste3, - Artiste4 - }; + CustomTitle? CustomTitle1 = CustomTitles.FirstOrDefault(a => a.Name == "MaMusique"); + CustomTitle? CustomTitle2 = CustomTitles.FirstOrDefault(a => a.Name == "MusiqueGeniale"); + CustomTitle? CustomTitle3 = CustomTitles.FirstOrDefault(a => a.Name == "custom3"); + + InfoTitle? InfoTitle1 = InfoTitles.FirstOrDefault(a => a.Name == "info1"); + InfoTitle? InfoTitle2 = InfoTitles.FirstOrDefault(a => a.Name == "info2"); - albums = new List<Album>() + if (Artist1 != null) { - Album1, - Album2, - Album3, - Album4 - }; + if (Album1 != null) { + Artist1.AddAlbum(Album1); + } + if(Album2 != null) + { + Artist1.AddAlbum(Album2); + } + } + if (Artist2 != null) + { + if(Album3 != null) + { + Artist2.AddAlbum(Album3); + } + if(Album4 != null) + { + Artist2.AddAlbum(Album4); + } + } - playlists = new List<Playlist>() + if (Playlist1 != null) { - Playlist1, - Playlist2 - }; + if (CustomTitle1 != null) + { + Playlist1.AddTitle(CustomTitle1); + } + if (CustomTitle2 != null) + { + Playlist1.AddTitle(CustomTitle2); + } + } + if (Playlist2 != null) + { + if(CustomTitle2 != null) + { + Playlist2.AddTitle(CustomTitle2); + } + if(CustomTitle3 != null) + { + Playlist2.AddTitle(CustomTitle3); + } + } - titles = new List<Title>() + if (Album1 != null) { - Custom1, - Custom2, - Custom3, - Info1, - Info2 - }; + if(InfoTitle1 != null) + { + Album1.AddTitle(InfoTitle1); + } + if(InfoTitle2 != null) + { + Album1.AddTitle(InfoTitle2); + } + } + if (Album2 != null && InfoTitle2 != null) + { + Album2.AddTitle(InfoTitle2); + } + } public List<Album> GetAlbums() @@ -126,9 +168,14 @@ public class StubManager : IDataManager return playlists; } - public List<Title> GetTitles() + public List<CustomTitle> GetCustomTitles() + { + return customTitles; + } + + public List<InfoTitle> GetInfoTitles() { - return titles; + return infoTitles; } public void AddAlbum(Album album) @@ -136,10 +183,10 @@ public class StubManager : IDataManager albums.Add(album); } - public void AddTitle(Title title) + /*public void AddTitle(Title title) { titles.Add(title); - } + }*/ public void AddPlaylist(Playlist playlist) { playlists.Add(playlist); @@ -157,10 +204,10 @@ public class StubManager : IDataManager albums.Remove(album); } - public void RemoveTitle(Title title) + /*public void RemoveTitle(Title title) { titles.Remove(title); - } + }*/ public void RemovePlaylist(Playlist playlist) { diff --git a/Sources/Model/Stub/StubPlaylist.cs b/Sources/Model/Stub/StubPlaylist.cs index b07415c..6bed9f2 100644 --- a/Sources/Model/Stub/StubPlaylist.cs +++ b/Sources/Model/Stub/StubPlaylist.cs @@ -3,4 +3,25 @@ public class StubPlaylist { + public List<Playlist> Playlists + { + get => playlists; + } + + private List<Playlist> playlists; + + public StubPlaylist() + { + Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); + Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); + playlists = new List<Playlist>() + { + Playlist1, Playlist2 + }; + } + + public List<Playlist> GetPlaylists() + { + return playlists; + } } diff --git a/Sources/Model/Stub/StubTitle.cs b/Sources/Model/Stub/StubTitle.cs deleted file mode 100644 index f403fe9..0000000 --- a/Sources/Model/Stub/StubTitle.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Model.Stub; - -public class StubTitle -{ - -} From c1bf1f13bf6ed630b32850001ef989c78f9155ba Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Mon, 8 May 2023 20:15:19 +0200 Subject: [PATCH 16/45] Finished Stubs --- Sources/Model/IDataManager.cs | 12 +++++-- Sources/Model/Manager.cs | 53 ++++++++++++++++++++++++------- Sources/Model/Stub/StubManager.cs | 23 ++++++++++---- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 34fbb0f..7657f06 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -2,7 +2,9 @@ public interface IDataManager { - List<Title> GetTitles(); + List<CustomTitle> GetCustomTitles(); + + List<InfoTitle> GetInfoTitles(); List<Album> GetAlbums(); @@ -16,7 +18,9 @@ public interface IDataManager public void AddPlaylist(Playlist playlist); - public void AddTitle(Title title); + public void AddCustomTitle(CustomTitle title); + + public void AddInfoTitle(InfoTitle title); public void RemoveAlbum(Album album); @@ -24,6 +28,8 @@ public interface IDataManager public void RemovePlaylist(Playlist playlist); - public void RemoveTitle(Title title); + public void RemoveCustomTitle(CustomTitle title); + + public void RemoveInfoTitle(InfoTitle title); } \ No newline at end of file diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 02bb855..10598e7 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -14,13 +14,23 @@ public class Manager } } - private List<Title> titles = new List<Title>(); + private List<CustomTitle> customTitles = new List<CustomTitle>(); - public IEnumerable<Title> Titles + public IEnumerable<CustomTitle> CustomTitles { get { - return titles.ToList(); + return customTitles.ToList(); + } + } + + private List<InfoTitle> infoTitles = new List<InfoTitle>(); + + public IEnumerable<InfoTitle> InfoTitles + { + get + { + return infoTitles.ToList(); } } @@ -49,7 +59,8 @@ public class Manager DataManager = new StubManager(); albums = DataManager.GetAlbums(); - titles = DataManager.GetTitles(); + customTitles = DataManager.GetCustomTitles(); + infoTitles = DataManager.GetInfoTitles(); playlists = DataManager.GetPlaylists(); artists = DataManager.GetArtists(); } @@ -60,11 +71,18 @@ public class Manager albums = DataManager.GetAlbums(); } - public void AddTitle(Title title) + public void AddCustomTitle(CustomTitle title) { - DataManager.AddTitle(title); - titles = DataManager.GetTitles(); + DataManager.AddCustomTitle(title); + customTitles = DataManager.GetCustomTitles(); } + + public void AddInfoTitle(InfoTitle title) + { + DataManager.AddInfoTitle(title); + infoTitles = DataManager.GetInfoTitles(); + } + public void AddPlaylist(Playlist playlist) { DataManager.AddPlaylist(playlist); @@ -77,10 +95,16 @@ public class Manager albums = DataManager.GetAlbums(); } - public void RemoveTitle(Title title) + public void RemoveCustomTitle(CustomTitle title) + { + DataManager.RemoveCustomTitle(title); + customTitles = DataManager.GetCustomTitles(); + } + + public void RemoveInfoTitle(InfoTitle title) { - DataManager.RemoveTitle(title); - titles = DataManager.GetTitles(); + DataManager.RemoveInfoTitle(title); + infoTitles = DataManager.GetInfoTitles(); } public void RemovePlaylist(Playlist playlist) @@ -94,9 +118,14 @@ public class Manager return DataManager.GetAlbums(); } - public IEnumerable<Title> GetTitles() + public IEnumerable<CustomTitle> GetCustomTitles() + { + return DataManager.GetCustomTitles(); + } + + public IEnumerable<InfoTitle> GetInfoTitles() { - return DataManager.GetTitles(); + return DataManager.GetInfoTitles(); } public IEnumerable<Artist> GetArtists() diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index b7836c3..f73fcfb 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -183,10 +183,16 @@ public class StubManager : IDataManager albums.Add(album); } - /*public void AddTitle(Title title) + public void AddCustomTitle(CustomTitle title) { - titles.Add(title); - }*/ + customTitles.Add(title); + } + + public void AddInfoTitle(InfoTitle title) + { + infoTitles.Add(title); + } + public void AddPlaylist(Playlist playlist) { playlists.Add(playlist); @@ -204,10 +210,15 @@ public class StubManager : IDataManager albums.Remove(album); } - /*public void RemoveTitle(Title title) + public void RemoveCustomTitle(CustomTitle title) { - titles.Remove(title); - }*/ + customTitles.Remove(title); + } + + public void RemoveInfoTitle(InfoTitle title) + { + infoTitles.Remove(title); + } public void RemovePlaylist(Playlist playlist) { From 48fc84b337c62a0722ae3f585e32d4b466b46db6 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Mon, 8 May 2023 20:27:10 +0200 Subject: [PATCH 17/45] Uncomment lines to test drone and sonar --- .drone.yml | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.drone.yml b/.drone.yml index 172afe1..fb038e6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -14,29 +14,29 @@ steps: - dotnet restore Linaris.sln - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 - dotnet publish Linaris/Linaris.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk -# - name: tests -# image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest -# commands: -# - cd Sources/ -# - dotnet restore Linaris.sln -# - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 -# depends_on: [build] -# - name: code-inspection -# image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7-maui -# secrets: [ SECRET_SONAR_LOGIN ] -# environment: -# sonar_host: https://codefirst.iut.uca.fr/sonar/ -# sonar_token: -# from_secret: SECRET_SONAR_LOGIN -# project_key: Linaris_LEMAIRE_LABORIE -# coverage_exclusions: "Tests/**" -# commands: -# - cd Sources/ -# - dotnet restore Linaris.sln -# - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} -# - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 -# - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" -# - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" -# - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk -# - dotnet sonarscanner end /d:sonar.login=$${sonar_token} -# depends on: [tests] + - name: tests + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dotnet7-maui:latest + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet test Linaris.sln --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + depends_on: [build] + - name: code-inspection + image: hub.codefirst.iut.uca.fr/marc.chevaldonne/codefirst-dronesonarplugin-dotnet7-maui + secrets: [ SECRET_SONAR_LOGIN ] + environment: + sonar_host: https://codefirst.iut.uca.fr/sonar/ + sonar_token: + from_secret: SECRET_SONAR_LOGIN + project_key: Linaris_LEMAIRE_LABORIE + coverage_exclusions: "Tests/**" + commands: + - cd Sources/ + - dotnet restore Linaris.sln + - dotnet sonarscanner begin /k:$${project_key} /d:sonar.host.url=$${sonar_host} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions=$${coverage_exclusions} /d:sonar.login=$${sonar_token} + - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 + - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - dotnet sonarscanner end /d:sonar.login=$${sonar_token} + depends on: [tests] From cab27bc4d53290c10bf3346d2161c5c17ac2a8f7 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Mon, 8 May 2023 20:29:40 +0200 Subject: [PATCH 18/45] Fix dependency issue --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index fb038e6..cd7bf0d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,4 +39,4 @@ steps: - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk - dotnet sonarscanner end /d:sonar.login=$${sonar_token} - depends on: [tests] + depends_on: [tests] From 45ceaa5a5a32cfc59dc063c63acaebec2f79c830 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Mon, 8 May 2023 21:07:08 +0200 Subject: [PATCH 19/45] Fix Unit tests --- Sources/Model/Album.cs | 30 +++++++++++++----------- Sources/Model/Artiste.cs | 13 ++++++++--- Sources/Model/CustomTitle.cs | 6 +++-- Sources/Model/Playlist.cs | 34 ++++++++++++++++++++-------- Sources/Model/Title.cs | 17 ++++++++++---- Sources/TestUnitaires/TU_Artiste.cs | 10 ++++---- Sources/TestUnitaires/TU_Playlist.cs | 9 ++++---- Sources/TestUnitaires/TU_Title.cs | 9 ++++---- 8 files changed, 85 insertions(+), 43 deletions(-) diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 32a57eb..323ddb0 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -15,7 +15,7 @@ } } - private string name; + private string name = "Unknown"; public string Description { @@ -30,9 +30,17 @@ } } - private string description; + private string description = ""; - public IEnumerable<Title> Titles { get; set; } + public IEnumerable<Title> Titles + { + get + { + return titles; + } + } + + private List<Title> titles = new List<Title>(); public string ImageURL { @@ -47,16 +55,16 @@ } if (value.Contains(' ')) { - imageURL = value.Replace(' ', '\\'); + imageURL = value.Replace(' ', '_'); } - if (value.Contains('.')) + else if (value.Contains('.')) { imageURL = value; } } } - private string imageURL; + private string imageURL = "unknown.png"; public Artiste Artist { get; set; } @@ -73,7 +81,7 @@ } } - private string information; + private string information = ""; public Album(string name, string file_Name, Artiste artist, string description, string information) { @@ -82,20 +90,16 @@ Artist = artist; Description = description; Information = information; - Titles = new List<Title>(); } public void AddTitle(Title title) { - Titles.Prepend(title); + titles.Add(title); } public void RemoveTitle(Title title) { - foreach(var item in Titles) - { - Titles = Titles.Where(item => item != title).ToList(); - } + titles.Remove(title); } } diff --git a/Sources/Model/Artiste.cs b/Sources/Model/Artiste.cs index bcab081..ab29d82 100644 --- a/Sources/Model/Artiste.cs +++ b/Sources/Model/Artiste.cs @@ -17,16 +17,23 @@ public class Artiste private string name = "Unknown"; - public IEnumerable<Album> Albums { get; set; } + public IEnumerable<Album> Albums + { + get + { + return albums.ToList(); + } + } + + private List<Album> albums = new List<Album>(); public Artiste(string name) { Name = name; - Albums = new List<Album>(); } public void AddAlbum(Album album) { - Albums.Prepend(album); + albums.Add(album); } } diff --git a/Sources/Model/CustomTitle.cs b/Sources/Model/CustomTitle.cs index 9b41237..e3639c5 100644 --- a/Sources/Model/CustomTitle.cs +++ b/Sources/Model/CustomTitle.cs @@ -1,4 +1,6 @@ -namespace Model; +using System.Runtime.CompilerServices; + +namespace Model; public class CustomTitle : Title { @@ -15,7 +17,7 @@ public class CustomTitle : Title { } } - private string path; + private string path = "unknown.mp3"; public CustomTitle(string name, string imageURL, string information, string path) : base(name, imageURL, information) { diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 97d3e43..a3882d0 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -15,7 +15,7 @@ public class Playlist } } - private string name; + private string name = "unknown"; public string Description { @@ -30,9 +30,17 @@ public class Playlist } } - private string description; + private string description = ""; - public IEnumerable<Title> Morceaux { get; set; } + public IEnumerable<Title> Titles + { + get + { + return titles; + } + } + + private List<Title> titles = new List<Title>(); public string ImageURL { @@ -40,31 +48,39 @@ public class Playlist set { - if (value != null && value.Contains('.')) + if (value == null || !value.Contains('.')) + { + value = "none.png"; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '_'); + } + else if (value.Contains('.')) { imageURL = value; } } } - private string imageURL; + private string imageURL = "none.png"; public Playlist(string nom, string description, string imageURL) { Name = nom; Description = description; - Morceaux = new List<Title>(); - this.imageURL = imageURL; + ImageURL = imageURL; } public void AddTitle(Title morceau) { - Morceaux.Prepend(morceau); + titles.Add(morceau); } public void RemoveTitle(Title morceau) { - Morceaux.ToList().Remove(morceau); + titles.Remove(morceau); } } diff --git a/Sources/Model/Title.cs b/Sources/Model/Title.cs index 1d985e8..b7782d2 100644 --- a/Sources/Model/Title.cs +++ b/Sources/Model/Title.cs @@ -15,7 +15,7 @@ } } - private string name; + private string name = "unknown"; public string ImageURL { @@ -23,14 +23,23 @@ set { - if (value != null && value.Contains('.')) + if (value == null || !value.Contains('.')) + { + value = "none.png"; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '_'); + } + else if (value.Contains('.')) { imageURL = value; } } } - private string imageURL; + private string imageURL = "unknown.png"; public string Information { @@ -45,7 +54,7 @@ } } - private string information; + private string information = ""; public Title(string nom, string file_Name, string informations) { diff --git a/Sources/TestUnitaires/TU_Artiste.cs b/Sources/TestUnitaires/TU_Artiste.cs index 4b24884..6d29157 100644 --- a/Sources/TestUnitaires/TU_Artiste.cs +++ b/Sources/TestUnitaires/TU_Artiste.cs @@ -13,7 +13,8 @@ namespace TestUnitaires [InlineData("Hugo TSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR")] public void TU_Attributes(string name) { - Assert.True(name != null && name.Length < 75); + Artiste a = new Artiste(name); + Assert.True(a.Name != null && a.Name.Length < 75); } [Theory] @@ -23,11 +24,12 @@ namespace TestUnitaires public void TU_Methods(string name) { Artiste a = new Artiste(name); + Album a1 = new Album("Fenêtre sur Rue", "album2. jpg", a, "Un banger", "Sortie : 2012"); - List<Album> verif = new List<Album>(); - verif.Add(a1); + a.AddAlbum(a1); - Assert.True(a.Albums == verif); + + Assert.Contains(a1, a.Albums); } } diff --git a/Sources/TestUnitaires/TU_Playlist.cs b/Sources/TestUnitaires/TU_Playlist.cs index f1ca0d0..6a4d78c 100644 --- a/Sources/TestUnitaires/TU_Playlist.cs +++ b/Sources/TestUnitaires/TU_Playlist.cs @@ -16,10 +16,11 @@ namespace TestUnitaires [InlineData("Sons Soirées", "red-sky .png", "Contient les sons que je mets quand je suis en soirée.")] public void TU_Attributes(string name, string url, string desc) { - Assert.True(name != null && name.Length < 75); - Assert.True(url != null && url.Contains('.')); - Assert.False(url.Contains(' ')); - Assert.True(desc != null && desc.Length < 500); + Playlist p = new Playlist(name, desc, url); + Assert.True(p.Name != null && p.Name.Length < 75); + Assert.True(p.ImageURL != null && p.ImageURL.Contains('.')); + Assert.False(p.ImageURL.Contains(' ')); + Assert.True(p.Description != null && p.Description.Length < 500); } } diff --git a/Sources/TestUnitaires/TU_Title.cs b/Sources/TestUnitaires/TU_Title.cs index d5162c3..c22de93 100644 --- a/Sources/TestUnitaires/TU_Title.cs +++ b/Sources/TestUnitaires/TU_Title.cs @@ -16,10 +16,11 @@ namespace TestUnitaires [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020")] public void TU_Attributes(string name, string url, string info) { - Assert.True(name != null && name.Length < 75); - Assert.True(url != null && url.Contains('.')); - Assert.False(url.Contains(' ')); - Assert.True(info != null && info.Length < 500); + Title t = new Title(name, url, info); + Assert.True(t.Name != null && t.Name.Length < 75); + Assert.True(t.ImageURL != null && t.ImageURL.Contains('.')); + Assert.False(t.ImageURL.Contains(' ')); + Assert.True(t.Information != null && t.Information.Length < 500); } } From e4d3f3f3fea80cf68fa1e30a5be7152fa092377a Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Mon, 8 May 2023 21:13:42 +0200 Subject: [PATCH 20/45] Fix publish issue --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index cd7bf0d..c6dcbe4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -37,6 +37,6 @@ steps: - dotnet build Linaris.sln -c Release --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 - dotnet test Linaris.sln --logger trx --no-restore /p:AndroidSdkDirectory=$ANDROID_SDK_ROOT -property:Aapt2ToolPath=$ANDROID_SDK_ROOT/build-tools/33.0.0 /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" - - dotnet publish MauiApp/MauiApp.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk + - dotnet publish Linaris/Linaris.csproj -c Release --no-restore -o $CI_PROJECT_DIR/build/release -f:net7.0-android /p:AndroidSdkDirectory=/usr/lib/android-sdk - dotnet sonarscanner end /d:sonar.login=$${sonar_token} depends_on: [tests] From 377b9eb129255a443bde6738ac6463d317e584cd Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Mon, 8 May 2023 21:26:53 +0200 Subject: [PATCH 21/45] Fix future unit tests --- Sources/Model/InfoTitle.cs | 20 ++++++++++------- Sources/Model/Manager.cs | 46 +++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index bb9eb4d..eb4e688 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -17,9 +17,17 @@ public class InfoTitle : Title } } - private string description; + private string description = ""; - public IEnumerable<Artiste> Feat { get; set; } + public IEnumerable<Artiste> Feat + { + get + { + return feat; + } + } + + private List<Artiste> feat = new List<Artiste>(); public Genre Genre { get; set; } @@ -28,19 +36,15 @@ public class InfoTitle : Title Artiste = artist; Description = description; Genre = genre; - Feat = new List<Artiste>(); } public void AddFeat(Artiste artist) { - Feat.Prepend(artist); + feat.Add(artist); } public void RemoveFeat(Artiste artiste) { - foreach (var item in Feat) - { - Feat = Feat.Where(item => item != artiste).ToList(); - } + feat.Remove(artiste); } } diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 9de8d13..4f8e51b 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -4,48 +4,68 @@ public class Manager { public IDataManager DataManager { get; set; } - public IEnumerable<Album> Albums; + public IEnumerable<Album> Albums + { + get + { + return albums; + } + } + + private List<Album> albums = new List<Album>(); - public IEnumerable<Title> Titles; + public IEnumerable<Title> Titles + { + get + { + return titles; + } + } + + private List<Title> titles = new List<Title>(); + + public IEnumerable<Playlist> Playlists + { + get + { + return playlists; + } + } - public IEnumerable<Playlist> Playlists; + private List<Playlist> playlists = new List<Playlist>(); public Manager() { DataManager = new Stub(); - // Albums = DataManager.GetAlbum(); - Albums = new List<Album>(); - Titles = new List<Title>(); - Playlists = new List<Playlist>(); } public void AddAlbum(Album album) { - Albums.Prepend(album); + albums.Add(album); } public void AddTitle(Title title) { - Titles.Prepend(title); + titles.Add(title); } public void AddPlaylist(Playlist playlist) { - Playlists.Prepend(playlist); + playlists.Add(playlist); } public void RemoveAlbum(Album album) { - Albums.ToList().Remove(album); + albums.Remove(album); } public void RemoveTitle(Title title) { - Titles.ToList().Remove(title); + titles.Remove(title); } public void RemovePlaylist(Playlist playlist) { - Playlists.ToList().Remove(playlist); + playlists.Remove(playlist); } } From 4c6cf42e79bee1cb38e07b93037b7832ef52f322 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Tue, 9 May 2023 22:10:04 +0200 Subject: [PATCH 22/45] Started Serialization w/ Playlists --- Sources/Linaris/FooterPage.xaml.cs | 4 +- Sources/Model/IDataManager.cs | 4 + Sources/Model/Manager.cs | 4 +- Sources/Model/Playlist.cs | 6 +- .../Serialization/LINQ_XML_Serialization.cs | 185 ++++++++++++++++++ Sources/Model/Stub/StubManager.cs | 10 + 6 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 Sources/Model/Serialization/LINQ_XML_Serialization.cs diff --git a/Sources/Linaris/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index fdf1855..fcc1e8e 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -19,9 +19,9 @@ public partial class FooterPage : ContentView // (s,a) = convention, s = sender, a = arguments, si appli fermée, on free tout outputDevice.PlaybackStopped += PlaybackStoppedHandler; - morceauEnCours = "peaches.mp3"; + /*morceauEnCours = "peaches.mp3"; audioFile = new AudioFileReader(morceauEnCours); - outputDevice.Init(audioFile); + outputDevice.Init(audioFile);*/ } public void PlayButton_Clicked(object sender, EventArgs e) diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 7657f06..dde2dad 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -32,4 +32,8 @@ public interface IDataManager public void RemoveInfoTitle(InfoTitle title); + public void LoadPlaylists(); + + public void SavePlaylists(); + } \ No newline at end of file diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 10598e7..cfbfbe1 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -54,9 +54,9 @@ public class Manager } } - public Manager() + public Manager(IDataManager dataManager) { - DataManager = new StubManager(); + DataManager = dataManager; albums = DataManager.GetAlbums(); customTitles = DataManager.GetCustomTitles(); diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 3d30732..dbe9704 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -101,15 +101,15 @@ public class Playlist { Name = nom; Description = description; - this.imageURL = imageURL; + ImageURL = imageURL; } - public void AddTitle(Title morceau) + public void AddTitle(CustomTitle morceau) { morceaux.Add(morceau); } - public void RemoveTitle(Title morceau) + public void RemoveTitle(CustomTitle morceau) { morceaux.Remove(morceau); } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs new file mode 100644 index 0000000..20c3c1b --- /dev/null +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -0,0 +1,185 @@ +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); + } + } + } +} diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index f73fcfb..c772bd1 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -229,4 +229,14 @@ public class StubManager : IDataManager { artists.Remove(artist); } + + public void LoadPlaylists() + { + return; + } + + public void SavePlaylists() + { + return; + } } From ed203a99976cd330daea304056b7f546b68258ce Mon Sep 17 00:00:00 2001 From: Louis LABORIE <lolaborie> Date: Wed, 10 May 2023 09:28:44 +0200 Subject: [PATCH 23/45] Add Artists Serialization --- .../Serialization/LINQ_XML_Serialization.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index 20c3c1b..37cb1ba 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -182,4 +182,22 @@ public class LINQ_XML_Serialization : IDataManager } } } + + public void LoadArtists() + { + XDocument ArtistsFile = XDocument.Load("artists.xml"); + artists = ArtistsFile.Descendants("artist") + .Select(eltArtist => new Artist( + eltArtist.Attribute("Name")!.Value + )).ToList(); + + } + + public void SaveArtists() + { + XDocument ArtistsFile = new XDocument(); + var artist = artists.Select(artist => new XElement("artist", + new XAttribute("Name", artist.Name) + )); + } } From dbdd5a6de758b78fa3c0fc2a5d7d09826ea11578 Mon Sep 17 00:00:00 2001 From: Louis LABORIE <lolaborie> Date: Wed, 10 May 2023 16:11:37 +0200 Subject: [PATCH 24/45] Add UT for classes's methods --- Sources/TestUnitaires/TU_Album.cs | 18 ++++++++++++++++++ Sources/TestUnitaires/TU_CustomTitle.cs | 1 + Sources/TestUnitaires/TU_Playlist.cs | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/Sources/TestUnitaires/TU_Album.cs b/Sources/TestUnitaires/TU_Album.cs index 3c7966a..3c5453f 100644 --- a/Sources/TestUnitaires/TU_Album.cs +++ b/Sources/TestUnitaires/TU_Album.cs @@ -24,5 +24,23 @@ namespace TestUnitaires Assert.True(album.Information != null && album.Information.Length < 500); } + [Theory] + [InlineData("Fenêtre sur Rue", "album2. jpg", "Un banger", "Sortie : 2012")] + [InlineData("Adios Bahamas", "album.jpg", "Un banger", "Sortie : 2012")] + [InlineData(null, "album2.jpg", "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende", null, "Un banger", "Sortie : 2012")] + [InlineData("Dans La Légende", "album1.jpg", null, "Sortie : 2012")] + [InlineData("Dans La Légende", "album1.jpg", "Un banger", null)] + [InlineData("Dans La Légende", "album1jpg", "Un banger", "Sortie : 2012")] + public void TU_Methods(string nameAlbum, string url, string desc, string info) + { + Album album = new Album(nameAlbum, url, new Artiste("test"), desc, info); + Title t = new Title("Débitage", "test. mp3", "Banger"); + album.AddTitle(t); + Assert.Contains(t, album.Titles); + album.RemoveTitle(t); + Assert.DoesNotContain(t, album.Titles); + } + } } \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_CustomTitle.cs b/Sources/TestUnitaires/TU_CustomTitle.cs index 03c096c..5599ad1 100644 --- a/Sources/TestUnitaires/TU_CustomTitle.cs +++ b/Sources/TestUnitaires/TU_CustomTitle.cs @@ -25,6 +25,7 @@ namespace TestUnitaires Assert.True(ct.Path != null && ct.Path.Contains('.')); Assert.False(ct.Path.Contains(' ')); } + } } \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Playlist.cs b/Sources/TestUnitaires/TU_Playlist.cs index 6a4d78c..4380ab3 100644 --- a/Sources/TestUnitaires/TU_Playlist.cs +++ b/Sources/TestUnitaires/TU_Playlist.cs @@ -22,6 +22,24 @@ namespace TestUnitaires Assert.False(p.ImageURL.Contains(' ')); Assert.True(p.Description != null && p.Description.Length < 500); } + [Theory] + [InlineData("Sons Soirées", "red-sky.png", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData(null, "red-sky.png", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", null, "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky.png", null)] + [InlineData("Sons Soirées", "redskypng", "Contient les sons que je mets quand je suis en soirée.")] + [InlineData("Sons Soirées", "red-sky .png", "Contient les sons que je mets quand je suis en soirée.")] + public void TU_Methods(string name, string url, string desc) + { + Playlist p = new Playlist(name, desc, url); + Title t = new Title("Débitage","test. mp3","Banger"); + p.AddTitle(t); + Assert.Contains(t,p.Titles); + p.RemoveTitle(t); + Assert.DoesNotContain(t,p.Titles); + + + } } } \ No newline at end of file From 835a7a54b2125638930ec2506575aa8157c9885b Mon Sep 17 00:00:00 2001 From: Louis LABORIE <lolaborie> Date: Wed, 10 May 2023 17:22:43 +0200 Subject: [PATCH 25/45] Add InfoTitle's UT --- Sources/TestUnitaires/TU_InfoTitle.cs | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Sources/TestUnitaires/TU_InfoTitle.cs diff --git a/Sources/TestUnitaires/TU_InfoTitle.cs b/Sources/TestUnitaires/TU_InfoTitle.cs new file mode 100644 index 0000000..49727a8 --- /dev/null +++ b/Sources/TestUnitaires/TU_InfoTitle.cs @@ -0,0 +1,45 @@ +using Model; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; + +namespace TestUnitaires +{ + + public class TU_InfoTitle + { + [Theory] + [InlineData("Trajectoire","morceau1.png","Sortie : 2020","Morceau de Népal",Genre.HIP_HOP)] + [InlineData(null, "morceau1.png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", null, "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1.png", null, "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + public void TU_Attributes(string name, string url, string info, string desc, Genre g) + { + InfoTitle it = new InfoTitle(name, url, info, new Artiste("test"), desc, g); + Assert.True(it.Name != null && it.Name.Length < 75); + Assert.True(it.ImageURL != null && it.ImageURL.Contains('.')); + Assert.False(it.ImageURL.Contains(' ')); + Assert.True(it.Information != null && it.Information.Length < 500); + Assert.True(it.Description != null && it.Description.Length < 500); + } + + [Theory] + [InlineData("Trajectoire", "morceau1.png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData(null, "morceau1.png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", null, "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1.png", null, "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + [InlineData("Trajectoire", "morceau1. png", "Sortie : 2020", "Morceau de Népal", Genre.HIP_HOP)] + public void TU_Methods(string name, string url, string info, string desc, Genre g) + { + InfoTitle it = new InfoTitle(name, url, info, new Artiste("test"), desc, g); + Artiste a = new Artiste("Lahuiss"); + it.AddFeat(a); + Assert.Contains(a, it.Feat); + it.RemoveFeat(a); + Assert.DoesNotContain(a, it.Feat); + } + } + +} \ No newline at end of file From c104cf17585038e656f66ccd3b8fef585774cb56 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Wed, 10 May 2023 23:04:50 +0200 Subject: [PATCH 26/45] Serialization coded and a little bit optimized --- Sources/Console/Console.csproj | 4 + Sources/Console/Program.cs | 49 +- Sources/Model/Album.cs | 47 +- Sources/Model/Artist.cs | 39 +- Sources/Model/CustomTitle.cs | 28 +- Sources/Model/Genre.cs | 3 +- Sources/Model/IDataManager.cs | 26 +- Sources/Model/InfoTitle.cs | 137 +-- Sources/Model/Manager.cs | 31 + Sources/Model/Playlist.cs | 36 +- .../Serialization/LINQ_XML_Serialization.cs | 800 +++++++++++++----- Sources/Model/Stub/StubAlbum.cs | 62 +- Sources/Model/Stub/StubArtist.cs | 24 +- Sources/Model/Stub/StubCustomTitle.cs | 23 + Sources/Model/Stub/StubInfoTitle.cs | 72 +- Sources/Model/Stub/StubManager.cs | 207 ++--- Sources/Model/Stub/StubPlaylist.cs | 19 + Sources/Model/Title.cs | 32 +- 18 files changed, 1147 insertions(+), 492 deletions(-) diff --git a/Sources/Console/Console.csproj b/Sources/Console/Console.csproj index 6abd0f7..e171fb5 100644 --- a/Sources/Console/Console.csproj +++ b/Sources/Console/Console.csproj @@ -11,4 +11,8 @@ <ProjectReference Include="..\Model\Model.csproj" /> </ItemGroup> + <ItemGroup> + <Folder Include="xml\" /> + </ItemGroup> + </Project> diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index dec48a1..1900769 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -1,9 +1,12 @@ using Model; +using Model.Serialization; using Model.Stub; -Manager Manager = new Manager(); +IDataManager DataManager = new LINQ_XML_Serialization(); -foreach(Album Album in Manager.GetAlbums()) +Manager Manager = new Manager(DataManager); + +/*foreach(Album Album in Manager.GetAlbums()) { Console.WriteLine(Album.Name); } @@ -15,9 +18,9 @@ Manager.AddAlbum(new Album("coucou", "path.png", new Artist("lorenzo"), "descLol foreach (Album Album in Manager.GetAlbums()) { Console.WriteLine(Album.Name); -} +}*/ -Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); +/*Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); Playlist p1 = Manager.Playlists.First(); @@ -114,9 +117,35 @@ p1.PreviousTitle(); current = p1.GetCurrentTitle(); Console.WriteLine(current?.Name); p1.PreviousTitle(); -current = p1.GetCurrentTitle(); -Console.WriteLine(current?.Name); - - - - +current = p1.GetCurrentTitle();*/ +/*Console.WriteLine(current?.Name);*/ +Manager.LoadSerialization(); +foreach (var p in Manager.GetPlaylists()) +{ + Console.WriteLine(p.Name); +} +foreach (var a in Manager.GetAlbums()) +{ + Console.WriteLine(a.Name); +} +foreach (var a in Manager.GetArtists()) +{ + Console.WriteLine(a.Name); +} +foreach (var ct in Manager.GetCustomTitles()) +{ + Console.WriteLine(ct.Name); +} +foreach (var it in Manager.GetInfoTitles()) +{ + Console.WriteLine(it.Name); +} +Artist newArtist = new Artist(); +Manager.AddArtist(newArtist); +Manager.AddAlbum(new Album("Nouvel album", "nouveau.png", newArtist, "nouvelle desc", "nouvelles infos")); +Console.WriteLine("------"); +foreach (var a in Manager.GetAlbums()) +{ + Console.WriteLine(a.Name); +} +Manager.SaveSerialization(); \ No newline at end of file diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index a2beba3..7ececfb 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -1,21 +1,26 @@ -namespace Model +using Model.Stub; +using System.Diagnostics; +using System.Xml.Serialization; + +namespace Model { - public class Album + public class Album { + public string Name { get => name; set { - if (value != null && value.Length < 75) + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) { name = value; } } } - private string name ="Unknown"; + private string name = Manager.DEFAULT_NAME; public string Description { @@ -23,14 +28,14 @@ set { - if (value != null && value.Length < 500) + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) { description = value; } } } - private string description =""; + private string description = Manager.DEFAULT_DESC; private List<Title> titles = new List<Title>(); @@ -38,7 +43,7 @@ { get { - return titles.ToList(); + return new List<Title>(titles); } } @@ -55,7 +60,7 @@ } } - private string imageURL = "none.png"; + private string imageURL = Manager.DEFAULT_URL; public Artist Artist { get; set; } @@ -65,14 +70,14 @@ set { - if (value != null && value.Length < 500) + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) { information = value; } } } - private string information = ""; + private string information = Manager.DEFAULT_DESC; public Album(string name, string file_Name, Artist artist, string description, string information) { @@ -83,6 +88,11 @@ Information = information; } + public Album() + { + Artist = new Artist(Manager.DEFAULT_NAME); + } + public void AddTitle(Title title) { titles.Add(title); @@ -96,5 +106,22 @@ } } + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (obj.GetType() != typeof(Artist)) return false; + if (obj is Album album && ImageURL == album.ImageURL) return true; + else return false; + } + + public override int GetHashCode() + { + return ImageURL.GetHashCode(); + } + + public override string ToString() + { + return $"Name : {Name}, Artist : {Artist}"; + } } } \ No newline at end of file diff --git a/Sources/Model/Artist.cs b/Sources/Model/Artist.cs index a5b8e48..936131d 100644 --- a/Sources/Model/Artist.cs +++ b/Sources/Model/Artist.cs @@ -1,4 +1,7 @@ -namespace Model; +using Model.Stub; +using System.Xml.Serialization; + +namespace Model; public class Artist { @@ -8,32 +11,40 @@ public class Artist set { - if (value != null && value.Length < 75) + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) { name = value; } } } - private string name = "Unknown"; + private string name = Manager.DEFAULT_NAME; - private List<Album> albums = new List<Album>(); + public Artist(string name) + { + Name = name; + } + + public Artist() + { - public IEnumerable<Album> Albums - { - get - { - return albums.ToList(); - } } - public Artist(string name) + public override bool Equals(object? obj) { - Name = name; + if(obj == null) return false; + if(obj.GetType() != typeof(Artist)) return false; + if(obj is Artist artist && Name == artist.Name) return true; + else return false; + } + + public override int GetHashCode() + { + return Name.GetHashCode(); } - public void AddAlbum(Album album) + public override string ToString() { - albums.Add(album); + return $"Name : {Name}"; } } diff --git a/Sources/Model/CustomTitle.cs b/Sources/Model/CustomTitle.cs index 4f9958f..ab7b192 100644 --- a/Sources/Model/CustomTitle.cs +++ b/Sources/Model/CustomTitle.cs @@ -1,4 +1,6 @@ -namespace Model; +using Model.Stub; + +namespace Model; public class CustomTitle : Title { @@ -8,17 +10,37 @@ public class CustomTitle : Title { set { - if (value != null && value.Length < 500) + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) { path = value; } } } - private string path = "none.mp3"; + private string path = Manager.DEFAULT_URL; public CustomTitle(string name, string imageURL, string information, string path) : base(name, imageURL, information) { Path = path; } + + public CustomTitle() : base(Manager.DEFAULT_NAME, Manager.DEFAULT_URL, Manager.DEFAULT_DESC) { } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (obj.GetType() != typeof(CustomTitle)) return false; + if (obj is CustomTitle customTitle && ImageURL == customTitle.ImageURL) return true; + else return false; + } + + public override int GetHashCode() + { + return ImageURL.GetHashCode(); + } + + public override string ToString() + { + return $"Name : {Name}, Path : {Path}"; + } } diff --git a/Sources/Model/Genre.cs b/Sources/Model/Genre.cs index 4298509..f0aec92 100644 --- a/Sources/Model/Genre.cs +++ b/Sources/Model/Genre.cs @@ -2,5 +2,6 @@ public enum Genre { - HIP_HOP, POP, ROCK, ELECTRO, CLASSIQUE, JAZZ, VARIETE_FRANCAISE, VARIETE_INTERNATIONALE, REGGAE, RAP, RNB, DISCO, BLUES, COUNTRY, FUNK, GOSPEL, METAL, K_POP + HIP_HOP, POP, ROCK, ELECTRO, CLASSIQUE, JAZZ, VARIETE_FRANCAISE, VARIETE_INTERNATIONALE, REGGAE, RAP, RNB, DISCO, BLUES, COUNTRY, FUNK, GOSPEL, + METAL, K_POP } diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index dde2dad..6c9e14a 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -12,28 +12,30 @@ public interface IDataManager List<Playlist> GetPlaylists(); - public void AddAlbum(Album album); + CustomTitle? GetCustomTitleByUrl(string custom); - public void AddArtist(Artist artist); + void AddAlbum(Album album); - public void AddPlaylist(Playlist playlist); + void AddArtist(Artist artist); - public void AddCustomTitle(CustomTitle title); + void AddPlaylist(Playlist playlist); - public void AddInfoTitle(InfoTitle title); + void AddCustomTitle(CustomTitle title); - public void RemoveAlbum(Album album); + void AddInfoTitle(InfoTitle title); - public void RemoveArtist(Artist artist); + void RemoveAlbum(Album album); - public void RemovePlaylist(Playlist playlist); + void RemoveArtist(Artist artist); - public void RemoveCustomTitle(CustomTitle title); + void RemovePlaylist(Playlist playlist); - public void RemoveInfoTitle(InfoTitle title); + void RemoveCustomTitle(CustomTitle title); - public void LoadPlaylists(); + void RemoveInfoTitle(InfoTitle title); - public void SavePlaylists(); + void LoadSerialization(); + + void SaveSerialization(); } \ No newline at end of file diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index 2c6b46a..1ee8b2f 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -1,53 +1,90 @@ -namespace Model; - -public class InfoTitle : Title -{ - public Artist Artiste { get; set; } - - public string Description - { - get => description; - - set - { - if (value != null && value.Length < 500) - { - description = value; - } - } - } - - private string description =""; - - private List<Artist> feat = new List<Artist>(); - - public IEnumerable<Artist> Feat - { +using System.Xml.Serialization; +using Model.Stub; + +namespace Model; + +public class InfoTitle : Title +{ + public Artist Artist + { + get + { + return artist; + } + set + { + artist = value; + } + } + + private Artist artist = new Artist(); + + public string Description + { + get => description; + + set + { + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) + { + description = value; + } + } + } + + private string description = Manager.DEFAULT_DESC; + + private List<Artist> feat = new List<Artist>(); + + public IEnumerable<Artist> Feat + { get { return feat.ToList(); - } - } - - public Genre Genre { get; set; } - - public InfoTitle(string name, string imageURL, string information, Artist artist, string description, Genre genre) : base(name,imageURL,information) - { - Artiste = artist; - Description = description; - Genre = genre; - } - - public void AddFeat(Artist artist) - { - feat.Add(artist); - } - public void RemoveFeat(Artist artiste) - { - foreach (var item in Feat) - { - feat = Feat.Where(item => item != artiste).ToList(); - } - } - -} + } + } + + public Genre Genre { get; set; } + + public InfoTitle(string name, string imageURL, string information, Artist artist, string description, Genre genre) : base(name,imageURL,information) + { + this.artist = artist; + Description = description; + Genre = genre; + } + + public InfoTitle() : base(Manager.DEFAULT_NAME, Manager.DEFAULT_URL, Manager.DEFAULT_DESC) + { + Artist = new Artist(Manager.DEFAULT_NAME); + } + + public void AddFeat(Artist artist) + { + feat.Add(artist); + } + public void RemoveFeat(Artist artiste) + { + foreach (var item in Feat) + { + feat = Feat.Where(item => item != artiste).ToList(); + } + } + + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (obj.GetType() != typeof(InfoTitle)) return false; + if (obj is InfoTitle infoTitle && ImageURL == infoTitle.ImageURL) return true; + else return false; + } + + public override int GetHashCode() + { + return ImageURL.GetHashCode(); + } + + public override string ToString() + { + return $"Name : {Name}, ImageUrl : {ImageURL}"; + } +} diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index cfbfbe1..08c405c 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -2,6 +2,16 @@ public class Manager { + public static int MAX_NAME_LENGTH = 75; + + public static int MAX_DESCRIPTION_LENGTH = 500; + + public static string DEFAULT_NAME = "Unknown"; + + public static string DEFAULT_URL = "none.png"; + + public static string DEFAULT_DESC = ""; + public IDataManager DataManager { get; set; } private List<Album> albums = new List<Album>(); @@ -89,6 +99,12 @@ public class Manager playlists = DataManager.GetPlaylists(); } + public void AddArtist(Artist artist) + { + DataManager.AddArtist(artist); + artists = DataManager.GetArtists(); + } + public void RemoveAlbum(Album album) { DataManager.RemoveAlbum(album); @@ -113,6 +129,11 @@ public class Manager playlists = DataManager.GetPlaylists(); } + public IEnumerable<Playlist> GetPlaylists() + { + return DataManager.GetPlaylists(); + } + public IEnumerable<Album> GetAlbums() { return DataManager.GetAlbums(); @@ -133,4 +154,14 @@ public class Manager return DataManager.GetArtists(); } + public void LoadSerialization() + { + DataManager.LoadSerialization(); + } + + public void SaveSerialization() + { + DataManager.SaveSerialization(); + } + } diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index dbe9704..efa68d8 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -1,4 +1,7 @@ -namespace Model; +using Model.Stub; +using System.Xml.Serialization; + +namespace Model; public class Playlist { @@ -8,14 +11,14 @@ public class Playlist set { - if (value != null && value.Length < 75) + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) { name = value; } } } - private string name ="Unknown"; + private string name = Manager.DEFAULT_NAME; public string Description { @@ -23,14 +26,14 @@ public class Playlist set { - if (value != null && value.Length < 500) + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) { description = value; } } } - private string description = ""; + private string description = Manager.DEFAULT_DESC; private List<Title> morceaux = new List<Title>(); @@ -54,7 +57,7 @@ public class Playlist } } - private string imageURL = "none.png"; + private string imageURL = Manager.DEFAULT_URL; public int Index { @@ -104,6 +107,10 @@ public class Playlist ImageURL = imageURL; } + public Playlist() + { + } + public void AddTitle(CustomTitle morceau) { morceaux.Add(morceau); @@ -169,4 +176,21 @@ public class Playlist } + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (obj.GetType() != typeof(Playlist)) return false; + if (obj is Playlist playlist && ImageURL == playlist.ImageURL) return true; + else return false; + } + + public override int GetHashCode() + { + return ImageURL.GetHashCode(); + } + + public override string ToString() + { + return $"Name : {Name}"; + } } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index 37cb1ba..a4f0ed3 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -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; + } +} diff --git a/Sources/Model/Stub/StubAlbum.cs b/Sources/Model/Stub/StubAlbum.cs index 87de42e..9c61a5d 100644 --- a/Sources/Model/Stub/StubAlbum.cs +++ b/Sources/Model/Stub/StubAlbum.cs @@ -4,12 +4,15 @@ namespace Model.Stub; public class StubAlbum { - public List<Artist> Artists + public StubArtist StubArtist { - get => artists; + get + { + return stubArtist; + } } - private List<Artist> artists; + private StubArtist stubArtist; public List<Album> Albums { @@ -20,38 +23,39 @@ public class StubAlbum public StubAlbum() { - albums = new List<Album>(); - StubArtist stubArtist = new StubArtist(); - artists = stubArtist.GetArtists(); - Artist? Artist1 = Artists.FirstOrDefault(a => a.Name == "Critien"); - if (Artist1 != null) - { - Album Album1 = new Album("la street", "lastreet.png", Artist1, "c'est la street", "plein d'infos1"); - Album Album2 = new Album("la jsp", "oui.png", Artist1, "c'est la couri", "plein d'infos2"); - albums.Add(Album1); - albums.Add(Album2); - } - Artist? Artist2 = Artists.FirstOrDefault(a => a.Name == "Gouriet"); - if (Artist2 != null) - { + stubArtist = new StubArtist(); - } - Artist? Artist3 = Artists.FirstOrDefault(a => a.Name == "Poulifer"); - if (Artist3 != null) - { - Album Album3 = new Album("la pas le temps", "non.png", Artist3, "c'est pas la street", "plein d'infos3"); - albums.Add(Album3); - } - Artist? Artist4 = Artists.FirstOrDefault(a => a.Name == "Credian"); - if (Artist4 != null) + Album Album1 = new Album("la street", "lastreet.png", StubArtist.GetArtistByName("Critien"), "c'est la street", "plein d'infos1"); + Album Album2 = new Album("la jsp", "oui.png", StubArtist.GetArtistByName("Critien"), "c'est la couri", "plein d'infos2"); + Album Album3 = new Album("la pas le temps", "non.png", StubArtist.GetArtistByName("Poulifer"), "c'est pas la street", "plein d'infos3"); + Album Album4 = new Album("la pas le choix", "peutetre.png", StubArtist.GetArtistByName("Credian"), "c'est la parterre", "plein d'infos4"); + albums = new List<Album>() { - Album Album4 = new Album("la pas le choix", "peutetre.png", Artist4, "c'est la parterre", "plein d'infos4"); - albums.Add(Album4); - } + Album1, Album2, Album3, Album4 + }; } public List<Album> GetAlbums() { return albums; } + public Album? GetAlbumByUrl(string url) + { + foreach(Album album in albums) + { + if (url == album.ImageURL) + { + return album; + } + } + return null; + } + public void AddAlbum(Album album) + { + albums.Add(album); + } + public void RemoveAlbum(Album album) + { + albums.Remove(album); + } } diff --git a/Sources/Model/Stub/StubArtist.cs b/Sources/Model/Stub/StubArtist.cs index d7bc027..9634124 100644 --- a/Sources/Model/Stub/StubArtist.cs +++ b/Sources/Model/Stub/StubArtist.cs @@ -16,11 +16,6 @@ public class StubArtist Artist Artiste3 = new Artist("Poulifer"); Artist Artiste4 = new Artist("Credian"); - /*Artiste1.AddAlbum(Album1); - Artiste1.AddAlbum(Album2); - Artiste2.AddAlbum(Album3); - Artiste2.AddAlbum(Album4);*/ - artists = new List<Artist>() { Artiste1, Artiste2, Artiste3, Artiste4 @@ -31,4 +26,23 @@ public class StubArtist { return artists; } + public Artist? GetArtistByName(string name) + { + foreach (var artist in artists) + { + if (artist.Name == name) + { + return artist; + } + } + return null; + } + public void AddArtist(Artist artist) + { + artists.Add(artist); + } + public void RemoveArtist(Artist artist) + { + artists.Remove(artist); + } } diff --git a/Sources/Model/Stub/StubCustomTitle.cs b/Sources/Model/Stub/StubCustomTitle.cs index 0137ae2..e8a7cbc 100644 --- a/Sources/Model/Stub/StubCustomTitle.cs +++ b/Sources/Model/Stub/StubCustomTitle.cs @@ -25,4 +25,27 @@ public class StubCustomTitle { return customTitles; } + public List<CustomTitle> GetCustomTitlesByUrl(List<string> urls) + { + List<CustomTitle> Customs = new List<CustomTitle>(); + foreach(var url in urls) + { + foreach (var title in customTitles) + { + if (url == title.ImageURL) + { + Customs.Add(title); + } + } + } + return Customs; + } + public void AddCustomTitle(CustomTitle customTitle) + { + customTitles.Add(customTitle); + } + public void RemoveCustomTitle(CustomTitle customTitle) + { + customTitles.Remove(customTitle); + } } diff --git a/Sources/Model/Stub/StubInfoTitle.cs b/Sources/Model/Stub/StubInfoTitle.cs index 7dba94d..3854697 100644 --- a/Sources/Model/Stub/StubInfoTitle.cs +++ b/Sources/Model/Stub/StubInfoTitle.cs @@ -3,12 +3,15 @@ public class StubInfoTitle { - public List<Artist> Artists + public StubArtist StubArtist { - get => artists; + get + { + return stubArtist; + } } - private List<Artist> artists; + private StubArtist stubArtist; public List<InfoTitle> InfoTitles { @@ -19,39 +22,50 @@ public class StubInfoTitle public StubInfoTitle() { - infoTitles = new List<InfoTitle>(); - StubArtist stubArtist = new StubArtist(); - artists = stubArtist.GetArtists(); - - Artist? Artist1 = Artists.FirstOrDefault(a => a.Name == "Critien"); - if (Artist1 != null) - { - - } - - Artist? Artist2 = Artists.FirstOrDefault(a => a.Name == "Gouriets"); - if (Artist2 != null) - { - InfoTitle InfoTitle1 = new InfoTitle("info1", "url1.png", "info1", Artist2, "desc1", Genre.K_POP); - infoTitles.Add(InfoTitle1); - } + stubArtist = new StubArtist(); - Artist? Artist3 = Artists.FirstOrDefault(a => a.Name == "Poulifer"); - if (Artist3 != null) - { - InfoTitle InfoTitle2 = new InfoTitle("info2", "url2.png", "info2", Artist3, "desc2", Genre.GOSPEL); - infoTitles.Add(InfoTitle2); - } + InfoTitle InfoTitle1 = new InfoTitle("info1", "url1.png", "info1", StubArtist.GetArtistByName("Gouriet"), "desc1", Genre.K_POP); + InfoTitle InfoTitle2 = new InfoTitle("info2", "url2.png", "info2", StubArtist.GetArtistByName("Poulifer"), "desc2", Genre.GOSPEL); - Artist? Artist4 = Artists.FirstOrDefault(a => a.Name == "Credian"); - if (Artist4 != null) + infoTitles = new List<InfoTitle>() { - - } + InfoTitle1, InfoTitle2 + }; } public List<InfoTitle> GetInfoTitles() { return infoTitles; } + public List<InfoTitle> GetInfoTitlesByUrl(List<string> urls) + { + List<InfoTitle> infos = new List<InfoTitle>(); + foreach(var url in urls) + { + foreach(var titles in infoTitles) + { + if (url == titles.ImageURL) + { + infos.Add(titles); + } + } + } + return infos; + } + public void AddInfoTitle(InfoTitle title) + { + infoTitles.Add(title); + } + public void RemoveInfoTitle(InfoTitle title) + { + infoTitles.Remove(title); + } + public void AddFeat(InfoTitle infoTitle, Artist artist) + { + infoTitle.AddFeat(artist); + } + public void RemoveFeat(InfoTitle infoTitle, Artist artist) + { + infoTitle.RemoveFeat(artist); + } } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index c772bd1..938aef7 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -3,240 +3,203 @@ public class StubManager : IDataManager { - private List<Artist> artists; + // Dictionaries - public IEnumerable<Artist> Artists + IDictionary<Album, List<InfoTitle>> DictAlbumInfo { get { - return artists.ToList(); + return dictAlbumInfo; } } - private List<Album> albums; + Dictionary<Album, List<InfoTitle>> dictAlbumInfo; - public IEnumerable<Album> Albums + IDictionary<Playlist, List<CustomTitle>> DictPlaylistTitles { get { - return albums.ToList(); + return dictPlaylistTitles; } } - private List<Playlist> playlists; + Dictionary<Playlist, List<CustomTitle>> dictPlaylistTitles; - public IEnumerable<Playlist> Playlists + // Stubs + + public StubAlbum StubAlbum { get { - return playlists.ToList(); + return stubAlbum; } } - private List<InfoTitle> infoTitles; + private StubAlbum stubAlbum; - public IEnumerable<InfoTitle> InfoTitles + public StubArtist StubArtist { get { - return infoTitles.ToList(); + return stubArtist; } } - private List<CustomTitle> customTitles; + private StubArtist stubArtist; - public IEnumerable<CustomTitle> CustomTitles + public StubCustomTitle StubCustomTitle { get { - return customTitles.ToList(); + return stubCustomTitle; } } - public StubManager() - { - StubAlbum stubAlbum = new StubAlbum(); - albums = stubAlbum.GetAlbums(); - - StubPlaylist stubPlaylist = new StubPlaylist(); - playlists = stubPlaylist.GetPlaylists(); - - StubArtist stubArtist = new StubArtist(); - artists = stubArtist.GetArtists(); - - StubInfoTitle stubInfoTitle = new StubInfoTitle(); - infoTitles = stubInfoTitle.GetInfoTitles(); - - StubCustomTitle stubCustomTitle = new StubCustomTitle(); - customTitles = stubCustomTitle.GetCustomTitles(); - - Artist? Artist1 = Artists.FirstOrDefault(a => a.Name == "Critien"); - Artist? Artist2 = Artists.FirstOrDefault(a => a.Name == "Gouriet"); - Artist? Artist3 = Artists.FirstOrDefault(a => a.Name == "Poulifer"); - Artist? Artist4 = Artists.FirstOrDefault(a => a.Name == "Credian"); - - Album? Album1 = Albums.FirstOrDefault(a => a.Name == "la street"); - Album? Album2 = Albums.FirstOrDefault(a => a.Name == "la jsp"); - Album? Album3 = Albums.FirstOrDefault(a => a.Name == "la pas le temps"); - Album? Album4 = Albums.FirstOrDefault(a => a.Name == "la pas le choix"); + private StubCustomTitle stubCustomTitle; - Playlist? Playlist1 = Playlists.FirstOrDefault(a => a.Name == "Playlist1"); - Playlist? Playlist2 = Playlists.FirstOrDefault(a => a.Name == "Playlist2"); - - CustomTitle? CustomTitle1 = CustomTitles.FirstOrDefault(a => a.Name == "MaMusique"); - CustomTitle? CustomTitle2 = CustomTitles.FirstOrDefault(a => a.Name == "MusiqueGeniale"); - CustomTitle? CustomTitle3 = CustomTitles.FirstOrDefault(a => a.Name == "custom3"); - - InfoTitle? InfoTitle1 = InfoTitles.FirstOrDefault(a => a.Name == "info1"); - InfoTitle? InfoTitle2 = InfoTitles.FirstOrDefault(a => a.Name == "info2"); - - if (Artist1 != null) - { - if (Album1 != null) { - Artist1.AddAlbum(Album1); - } - if(Album2 != null) - { - Artist1.AddAlbum(Album2); - } - } - if (Artist2 != null) + public StubInfoTitle StubInfoTitle + { + get { - if(Album3 != null) - { - Artist2.AddAlbum(Album3); - } - if(Album4 != null) - { - Artist2.AddAlbum(Album4); - } + return stubInfoTitle; } + } - if (Playlist1 != null) - { - if (CustomTitle1 != null) - { - Playlist1.AddTitle(CustomTitle1); - } - if (CustomTitle2 != null) - { - Playlist1.AddTitle(CustomTitle2); - } - } - if (Playlist2 != null) - { - if(CustomTitle2 != null) - { - Playlist2.AddTitle(CustomTitle2); - } - if(CustomTitle3 != null) - { - Playlist2.AddTitle(CustomTitle3); - } - } + private StubInfoTitle stubInfoTitle; - if (Album1 != null) - { - if(InfoTitle1 != null) - { - Album1.AddTitle(InfoTitle1); - } - if(InfoTitle2 != null) - { - Album1.AddTitle(InfoTitle2); - } - } - if (Album2 != null && InfoTitle2 != null) + public StubPlaylist StubPlaylist + { + get { - Album2.AddTitle(InfoTitle2); + return stubPlaylist; } + } + + private StubPlaylist stubPlaylist; + + public StubManager() + { + dictAlbumInfo = new Dictionary<Album, List<InfoTitle>>(); + dictPlaylistTitles = new Dictionary<Playlist, List<CustomTitle>>(); + stubAlbum = new StubAlbum(); + stubArtist = new StubArtist(); + stubCustomTitle = new StubCustomTitle(); + stubInfoTitle = new StubInfoTitle(); + stubPlaylist = new StubPlaylist(); + + dictAlbumInfo.Add(StubAlbum.GetAlbumByUrl("lastreet.png"), StubInfoTitle.GetInfoTitlesByUrl(new List<string>() { "url1.png", "url2.png" })); + dictAlbumInfo.Add(StubAlbum.GetAlbumByUrl("oui.png"), StubInfoTitle.GetInfoTitlesByUrl(new List<string>() { "url2.png" })); + + dictPlaylistTitles.Add(StubPlaylist.GetPlaylistByUrl("url1.png"), StubCustomTitle.GetCustomTitlesByUrl(new List<string>() { "url1.png", "url2.png" })); + dictPlaylistTitles.Add(StubPlaylist.GetPlaylistByUrl("url2.png"), StubCustomTitle.GetCustomTitlesByUrl(new List<string>() { "url2.png", "url3.png" })); } public List<Album> GetAlbums() { - return albums; + return StubAlbum.GetAlbums(); } public List<Artist> GetArtists() { - return artists; + return StubArtist.GetArtists(); } public List<Playlist> GetPlaylists() { - return playlists; + return StubPlaylist.GetPlaylists(); } public List<CustomTitle> GetCustomTitles() { - return customTitles; + return StubCustomTitle.GetCustomTitles(); } public List<InfoTitle> GetInfoTitles() { - return infoTitles; + return StubInfoTitle.GetInfoTitles(); } public void AddAlbum(Album album) { - albums.Add(album); + StubAlbum.AddAlbum(album); } public void AddCustomTitle(CustomTitle title) { - customTitles.Add(title); + StubCustomTitle.AddCustomTitle(title); } public void AddInfoTitle(InfoTitle title) { - infoTitles.Add(title); + StubInfoTitle.AddInfoTitle(title); + } + + public void AddFeat(InfoTitle infoTitle, Artist artist) + { + StubInfoTitle.AddFeat(infoTitle, artist); } public void AddPlaylist(Playlist playlist) { - playlists.Add(playlist); + StubPlaylist.AddPlaylist(playlist); } public void AddArtist(Artist artist) { - artists.Add(artist); + StubArtist.AddArtist(artist); } public void RemoveAlbum(Album album) { - albums.Remove(album); + StubAlbum.RemoveAlbum(album); } public void RemoveCustomTitle(CustomTitle title) { - customTitles.Remove(title); + StubCustomTitle.RemoveCustomTitle(title); } public void RemoveInfoTitle(InfoTitle title) { - infoTitles.Remove(title); + StubInfoTitle.RemoveInfoTitle(title); } public void RemovePlaylist(Playlist playlist) { - playlists.Remove(playlist); + StubPlaylist.RemovePlaylist(playlist); } public void RemoveArtist(Artist artist) { - artists.Remove(artist); + StubArtist.RemoveArtist(artist); } - public void LoadPlaylists() + + + + + public void LoadSerialization() { return; } - public void SavePlaylists() + public void SaveSerialization() { return; } + + public CustomTitle? GetCustomTitleByUrl(string custom) + { + foreach (CustomTitle customTitle in StubCustomTitle.GetCustomTitles()) + { + if (customTitle.Name == custom) + { + return customTitle; + } + } + return null; + } } diff --git a/Sources/Model/Stub/StubPlaylist.cs b/Sources/Model/Stub/StubPlaylist.cs index 6bed9f2..9c11fbb 100644 --- a/Sources/Model/Stub/StubPlaylist.cs +++ b/Sources/Model/Stub/StubPlaylist.cs @@ -24,4 +24,23 @@ public class StubPlaylist { return playlists; } + public Playlist? GetPlaylistByUrl(string url) + { + foreach(var playlist in playlists) + { + if (playlist.ImageURL == url) + { + return playlist; + } + } + return null; + } + public void AddPlaylist(Playlist playlist) + { + playlists.Add(playlist); + } + public void RemovePlaylist(Playlist playlist) + { + playlists.Remove(playlist); + } } diff --git a/Sources/Model/Title.cs b/Sources/Model/Title.cs index 0410f66..bc297a8 100644 --- a/Sources/Model/Title.cs +++ b/Sources/Model/Title.cs @@ -1,4 +1,7 @@ -namespace Model +using Model.Stub; +using System.Xml.Serialization; + +namespace Model { public class Title { @@ -8,14 +11,14 @@ set { - if (value != null && value.Length < 75) + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) { name = value; } } } - private string name = "Unknown"; + private string name = Manager.DEFAULT_NAME; public string ImageURL { @@ -30,7 +33,7 @@ } } - private string imageURL = "none.png"; + private string imageURL = Manager.DEFAULT_URL; public string Information { @@ -38,14 +41,14 @@ set { - if (value != null && value.Length < 500) + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) { information = value; } } } - private string information =""; + private string information = Manager.DEFAULT_DESC; public Title(string nom, string file_Name, string informations) { @@ -54,5 +57,22 @@ Information = informations; } + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (obj.GetType() != typeof(Title)) return false; + if (obj is Title title && ImageURL == title.ImageURL) return true; + else return false; + } + + public override int GetHashCode() + { + return ImageURL.GetHashCode(); + } + + public override string ToString() + { + return $"Name : {Name}"; + } } } From adfebf218fb3634449eda9283041759fe32c6ce9 Mon Sep 17 00:00:00 2001 From: Louis LABORIE <lolaborie> Date: Sat, 13 May 2023 08:28:37 +0200 Subject: [PATCH 27/45] Add Manager's UT --- Sources/TestUnitaires/TU_Manager.cs | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Sources/TestUnitaires/TU_Manager.cs diff --git a/Sources/TestUnitaires/TU_Manager.cs b/Sources/TestUnitaires/TU_Manager.cs new file mode 100644 index 0000000..990a9c1 --- /dev/null +++ b/Sources/TestUnitaires/TU_Manager.cs @@ -0,0 +1,36 @@ +using Model; +using Model.Stub; +using Newtonsoft.Json.Linq; +using NuGet.Frameworks; +using System; + +namespace TestUnitaires +{ + + public class TU_Manager + { + [Theory] + [InlineData(null)] + [InlineData("Réference")] + public void TU_Methods(string? test) + { + Playlist p = new Playlist(test, "PlaceHolder", "place.holder"); + Album album = new Album(test, "place.holder", new Artiste("test"), "PlaceHolder", "PlaceHolder"); + Title t = new Title(test, "test. mp3", "Banger"); + Manager m = new Manager(); + m.AddTitle(t); + m.AddPlaylist(p); + m.AddAlbum(album); + Assert.Contains(t, m.Titles); + Assert.Contains(album, m.Albums); + Assert.Contains(p, m.Playlists); + m.RemovePlaylist(p); + m.RemoveAlbum(album); + m.RemoveTitle(t); + Assert.DoesNotContain(t, m.Titles); + Assert.DoesNotContain(p, m.Playlists); + Assert.DoesNotContain(album, m.Albums); + } + } + +} \ No newline at end of file From b71461d7a9bf07f10daabc1a5da2b7acf4e370f8 Mon Sep 17 00:00:00 2001 From: Louis LABORIE <lolaborie> Date: Sat, 13 May 2023 09:31:12 +0200 Subject: [PATCH 28/45] Enhanced model (add readonly keyword to multiple fields) --- Sources/Model/Album.cs | 2 +- Sources/Model/Artiste.cs | 2 +- Sources/Model/InfoTitle.cs | 2 +- Sources/Model/Manager.cs | 6 +++--- Sources/Model/Playlist.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 323ddb0..06380d0 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -40,7 +40,7 @@ } } - private List<Title> titles = new List<Title>(); + private readonly List<Title> titles = new List<Title>(); public string ImageURL { diff --git a/Sources/Model/Artiste.cs b/Sources/Model/Artiste.cs index ab29d82..bc2a9b3 100644 --- a/Sources/Model/Artiste.cs +++ b/Sources/Model/Artiste.cs @@ -25,7 +25,7 @@ public class Artiste } } - private List<Album> albums = new List<Album>(); + private readonly List<Album> albums = new List<Album>(); public Artiste(string name) { diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index eb4e688..7a3c3b6 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -27,7 +27,7 @@ public class InfoTitle : Title } } - private List<Artiste> feat = new List<Artiste>(); + private readonly List<Artiste> feat = new List<Artiste>(); public Genre Genre { get; set; } diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 4f8e51b..3f1de5d 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -12,7 +12,7 @@ public class Manager } } - private List<Album> albums = new List<Album>(); + private readonly List<Album> albums = new List<Album>(); public IEnumerable<Title> Titles { @@ -22,7 +22,7 @@ public class Manager } } - private List<Title> titles = new List<Title>(); + private readonly List<Title> titles = new List<Title>(); public IEnumerable<Playlist> Playlists { @@ -32,7 +32,7 @@ public class Manager } } - private List<Playlist> playlists = new List<Playlist>(); + private readonly List<Playlist> playlists = new List<Playlist>(); public Manager() { diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index a3882d0..afb3cd8 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -40,7 +40,7 @@ public class Playlist } } - private List<Title> titles = new List<Title>(); + private readonly List<Title> titles = new List<Title>(); public string ImageURL { From bda7f3c45b7f490cfbd94616da369e60deb64a87 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 13 May 2023 10:37:08 +0200 Subject: [PATCH 29/45] Fix critical issue --- Sources/Model/Artiste.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Model/Artiste.cs b/Sources/Model/Artiste.cs index bc2a9b3..e4626ba 100644 --- a/Sources/Model/Artiste.cs +++ b/Sources/Model/Artiste.cs @@ -21,7 +21,7 @@ public class Artiste { get { - return albums.ToList(); + return new List<Album>(albums); } } From fd704f8b0ab235e77d832a976e068d437c8f1654 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 13 May 2023 10:47:14 +0200 Subject: [PATCH 30/45] Fix major issues --- Sources/Console/Program.cs | 19 ------------------- Sources/Linaris/AlbumPage.xaml.cs | 9 --------- Sources/Linaris/MainPage.xaml.cs | 21 ++++----------------- Sources/Model/IDataManager.cs | 2 +- Sources/Model/Stub/Stub.cs | 2 -- 5 files changed, 5 insertions(+), 48 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 0806a11..1d3bfa7 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -2,23 +2,4 @@ Console.WriteLine("---"); -// See https://aka.ms/new-console-template for more information - -/*Album a = new Album("Adios Bahamas", "album1.jpg", "Népal"); -Album a1 = new Album("Fenêtre sur Rue", "album3.jpg", "HugoTSR"); -Album a2 = new Album("Dans la Légende", "album8.jpg", "PNL"); - -List<Album> lst = new List<Album> { a1, a2, a }; - -foreach (Album album in lst) -{ - Console.WriteLine($"Nom de l'album : " + album.Nom); - - Console.WriteLine($"Nom du fichier : " + album.File_Name); - - Console.WriteLine($"Artiste : " + album.Artiste); - - Console.WriteLine($"-------------------------"); -}*/ - diff --git a/Sources/Linaris/AlbumPage.xaml.cs b/Sources/Linaris/AlbumPage.xaml.cs index 821b100..adde9b9 100644 --- a/Sources/Linaris/AlbumPage.xaml.cs +++ b/Sources/Linaris/AlbumPage.xaml.cs @@ -6,13 +6,4 @@ public partial class AlbumPage : ContentPage { InitializeComponent(); } - - /* async void Button_Clicked(object sender, EventArgs e) - { - var random = new Random(); - var color = String.Format("#{0:X6}", random.Next(0x1000000)); - bouton.BackgroundColor = Color.FromArgb(color); - await bouton.RelRotateTo(360, 1000); - bouton.Rotation = 0; - }*/ } \ No newline at end of file diff --git a/Sources/Linaris/MainPage.xaml.cs b/Sources/Linaris/MainPage.xaml.cs index de3a24b..5a08d5f 100644 --- a/Sources/Linaris/MainPage.xaml.cs +++ b/Sources/Linaris/MainPage.xaml.cs @@ -2,7 +2,6 @@ public partial class MainPage : ContentPage { - // int count = 0; public MainPage() { @@ -10,23 +9,11 @@ public partial class MainPage : ContentPage } - /*private void OnCounterClicked(object sender, EventArgs e) - { - count++; - - if (count == 1) - CounterBtn.Text = $"Clicked {count} time"; - else - CounterBtn.Text = $"Clicked {count} times"; - - SemanticScreenReader.Announce(CounterBtn.Text); - }*/ - - /*async public void Go_Home() - { - await Navigation.PushAsync(new MainPage()); + async public void Go_Home() + { + await Navigation.PushAsync(new MainPage()); - }*/ + } } diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 4799ef5..895bf1d 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -2,5 +2,5 @@ public interface IDataManager { - //méthodes style IEnumerable<Groupe> RecupGFroupe(); + } \ No newline at end of file diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/Stub.cs index 9a60c86..23abbec 100644 --- a/Sources/Model/Stub/Stub.cs +++ b/Sources/Model/Stub/Stub.cs @@ -33,8 +33,6 @@ public class Stub : IDataManager Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); - Playlist Playlist3 = new Playlist("Playlist3", "desc3", "url3.png"); - Playlist Playlist4 = new Playlist("Playlist4", "desc4", "url4.png"); Playlist1.AddTitle(new CustomTitle("custom1", "url1.png", "info1", "chemin1")); Playlist1.AddTitle(new CustomTitle("custom2", "url2.png", "info2", "chemin2")); From 061dc31cea7ca71d91ca06eefd8fbf2bcbe63a17 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 13 May 2023 10:54:32 +0200 Subject: [PATCH 31/45] Fix minor and major issues --- Sources/Linaris/MainPage.xaml.cs | 2 +- Sources/Model/Stub/Stub.cs | 36 +++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Sources/Linaris/MainPage.xaml.cs b/Sources/Linaris/MainPage.xaml.cs index 5a08d5f..d6caaeb 100644 --- a/Sources/Linaris/MainPage.xaml.cs +++ b/Sources/Linaris/MainPage.xaml.cs @@ -9,7 +9,7 @@ public partial class MainPage : ContentPage } - async public void Go_Home() + async public Task Go_Home() { await Navigation.PushAsync(new MainPage()); diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/Stub.cs index 23abbec..906c959 100644 --- a/Sources/Model/Stub/Stub.cs +++ b/Sources/Model/Stub/Stub.cs @@ -3,20 +3,40 @@ public class Stub : IDataManager { - public IEnumerable<Artiste> Artistes; + public IEnumerable<Artiste> Artistes + { + get => artistes; + } + + public IEnumerable<Album> Albums + { + get => albums; + } + + public IEnumerable<Playlist> Playlists + { + get => playlists; + } + + public IEnumerable<Title> Titles + { + get => titles; + } + + private IEnumerable<Artiste> artistes; - public IEnumerable<Album> Albums; + private IEnumerable<Album> albums; - public IEnumerable<Playlist> Playlists; + private IEnumerable<Playlist> playlists; - public IEnumerable<Title> Titles; + private IEnumerable<Title> titles; public Stub() { - Artistes = new List<Artiste>(); - Albums = new List<Album>(); - Playlists = new List<Playlist>(); - Titles = new List<Title>(); + artistes = new List<Artiste>(); + albums = new List<Album>(); + playlists = new List<Playlist>(); + titles = new List<Title>(); Artiste Artiste1 = new Artiste("Critien"); Artiste Artiste2 = new Artiste("Gouriet"); From ddd0f8956debe640bdd2746b433b877bc0e23fcf Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 13 May 2023 11:32:23 +0200 Subject: [PATCH 32/45] Add CRUD --- Sources/Model/IDataManager.cs | 84 +++++- .../Serialization/LINQ_XML_Serialization.cs | 253 ++++++++++++++++ Sources/Model/Stub/StubManager.cs | 273 +++++++++++++++++- 3 files changed, 593 insertions(+), 17 deletions(-) diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 6c9e14a..257e0b9 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -1,39 +1,101 @@ namespace Model; public interface IDataManager -{ - List<CustomTitle> GetCustomTitles(); +{ + // Create + void AddAlbum(Album album); - List<InfoTitle> GetInfoTitles(); + void AddAlbums(List<Album> albumsList); - List<Album> GetAlbums(); + void AddArtist(Artist artist); - List<Artist> GetArtists(); + void AddArtists(List<Artist> artistsList); - List<Playlist> GetPlaylists(); + void AddPlaylist(Playlist playlist); + + void AddPlaylists(List<Playlist> playlistsList); + + void AddCustomTitle(CustomTitle title); + + void AddCustomTitles(List<CustomTitle> customTitlesList); + + void AddInfoTitle(InfoTitle title); + + void AddInfoTitles(List<InfoTitle> infoTitlesList); + + // Read + List<CustomTitle> GetCustomTitles(); CustomTitle? GetCustomTitleByUrl(string custom); - void AddAlbum(Album album); + List<InfoTitle> GetInfoTitles(); - void AddArtist(Artist artist); + InfoTitle? GetInfoTitleByUrl(string url); - void AddPlaylist(Playlist playlist); + List<Album> GetAlbums(); - void AddCustomTitle(CustomTitle title); + Album? GetAlbumByUrl(string url); + + List<Artist> GetArtists(); - void AddInfoTitle(InfoTitle title); + Artist? GetArtistByName(string name); + List<Playlist> GetPlaylists(); + + Playlist? GetPlaylistByUrl(string url); + + + // Update + void UpdateCustomTitle(CustomTitle title, string name, string url, string info, string path); + + void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path); + + void UpdateInfoTitle(InfoTitle title, string name, string url, string info, Artist artist, string description, Genre genre); + + void UpdateInfoTitleByName(string url, string name, string newUrl, string info, Artist artist, string description, Genre genre); + + void UpdateInfoTitleByArtistName(InfoTitle title, string name, string url, string info, string artist, string description, Genre genre); + + void UpdateInfoTitleByNameByArtistName(string url, string name, string newUrl, string info, string artist, string description, Genre genre); + + void UpdateAlbum(Album album, string name, string url, Artist artist, string description, string info); + + void UpdateAlbumByUrl(string url, string name, string newUrl, Artist artist, string description, string info); + + void UpdateAlbumByArtistName(Album album, string name, string url, string artist, string description, string info); + + void UpdateAlbumByUrlByArtistName(string url, string name, string newUrl, string artist, string description, string info); + + void UpdatePlaylist(Playlist playlist, string name, string description, string url); + + void UpdatePlaylistByUrl(string url, string name, string description, string newUrl); + + void UpdateArtist(Artist artist, string name); + + void UpdateArtistByName(string name, string newName); + + // Delete void RemoveAlbum(Album album); + void RemoveAlbums(List<Album> albumsList); + void RemoveArtist(Artist artist); + void RemoveArtists(List<Artist> artistsList); + void RemovePlaylist(Playlist playlist); + void RemovePlaylists(List<Playlist> playlistsList); + void RemoveCustomTitle(CustomTitle title); + void RemoveCustomTitles(List<CustomTitle> customTitlesList); + void RemoveInfoTitle(InfoTitle title); + void RemoveInfoTitles(List<InfoTitle> infoTitlesList); + + // Serialization void LoadSerialization(); void SaveSerialization(); diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index a4f0ed3..b955139 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using System.Xml.Serialization; using static System.Reflection.Metadata.BlobBuilder; using System.Reflection.Metadata; +using System.IO; namespace Model.Serialization; @@ -610,4 +611,256 @@ public class LINQ_XML_Serialization : IDataManager } return null; } + + public void AddAlbums(List<Album> albumsList) + { + foreach(Album a in albumsList) + { + albums.Add(a); + } + } + + public void AddArtists(List<Artist> artistsList) + { + foreach (Artist a in artistsList) + { + artists.Add(a); + } + } + + public void AddPlaylists(List<Playlist> playlistsList) + { + foreach (Playlist p in playlistsList) + { + playlists.Add(p); + } + } + + public void AddCustomTitles(List<CustomTitle> customTitlesList) + { + foreach (CustomTitle ct in customTitlesList) + { + customTitles.Add(ct); + } + } + + public void AddInfoTitles(List<InfoTitle> infoTitlesList) + { + foreach (InfoTitle it in infoTitlesList) + { + infoTitles.Add(it); + } + } + + public Playlist? GetPlaylistByUrl(string url) + { + foreach(Playlist p in playlists) + { + if (p.ImageURL == url) + { + return p; + } + } + return null; + } + + public void UpdateCustomTitle(CustomTitle title, string name, string url, string info, string path) + { + title.Name = name; + title.ImageURL = url; + title.Information = info; + title.Path = path; + } + + public void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path) + { + CustomTitle? title = GetCustomTitleByUrl(url); + if (title != null) + { + title.Name = name; + title.ImageURL = newUrl; + title.Information = info; + title.Path = path; + } + } + + public void UpdateInfoTitle(InfoTitle title, string name, string url, string info, Artist artist, string description, Genre genre) + { + title.Name = name; + title.ImageURL = url; + title.Information = info; + title.Artist = artist; + title.Description = description; + title.Genre = genre; + } + + public void UpdateInfoTitleByName(string url, string name, string newUrl, string info, Artist artist, string description, Genre genre) + { + InfoTitle? title = GetInfoTitleByUrl(url); + if (title != null) + { + 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 url, string name, string newUrl, string info, string artist, string description, Genre genre) + { + InfoTitle? title = GetInfoTitleByUrl(url); + 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; + } + } + + public void UpdateAlbum(Album album, string name, string url, Artist artist, string description, string info) + { + album.Name = name; + album.ImageURL = url; + album.Artist = artist; + album.Description = description; + album.Information = info; + } + + public void UpdateAlbumByUrl(string url, string name, string newUrl, Artist artist, string description, string info) + { + Album? album = GetAlbumByUrl(url); + if (album != null) + { + album.Name = name; + album.ImageURL = newUrl; + album.Artist = artist; + album.Description = description; + album.Information= info; + } + } + + public void UpdateAlbumByArtistName(Album album, string name, string url, string artist, string description, string info) + { + album.Name = name; + album.ImageURL = url; + Artist? artist2 = GetArtistByName(artist); + if (artist2 != null) + { + album.Artist = artist2; + } + album.Description = description; + album.Information = info; + } + + public void UpdateAlbumByUrlByArtistName(string url, string name, string newUrl, string artist, string description, string info) + { + Album? album = GetAlbumByUrl(url); + if (album != null) + { + album.Name = name; + album.ImageURL = newUrl; + Artist? artist2 = GetArtistByName(artist); + if (artist2 != null) + { + album.Artist = artist2; + } + album.Description = description; + album.Information = info; + } + } + + public void UpdatePlaylist(Playlist playlist, string name, string description, string url) + { + playlist.Name = name; + playlist.Description = description; + playlist.ImageURL = url; + } + + public void UpdatePlaylistByUrl(string url, string name, string description, string newUrl) + { + Playlist? playlist = GetPlaylistByUrl(url); + if (playlist != null) + { + playlist.Name = name; + playlist.Description = description; + playlist.ImageURL = newUrl; + } + } + + public void UpdateArtist(Artist artist, string name) + { + artist.Name = name; + } + + public void UpdateArtistByName(string name, string newName) + { + Artist? artist = GetArtistByName(newName); + if (artist != null) + { + artist.Name = newName; + } + } + + public void RemoveAlbums(List<Album> albumsList) + { + foreach (Album album in albumsList) + { + albums.Remove(album); + } + } + + public void RemoveArtists(List<Artist> artistsList) + { + foreach(Artist artist in artistsList) + { + artists.Remove(artist); + } + } + + public void RemovePlaylists(List<Playlist> playlistsList) + { + foreach (Playlist playlist in playlistsList) + { + playlists.Remove(playlist); + } + } + + public void RemoveCustomTitles(List<CustomTitle> customTitlesList) + { + foreach(CustomTitle customTitle in customTitlesList) + { + customTitles.Remove(customTitle); + } + } + + public void RemoveInfoTitles(List<InfoTitle> infoTitlesList) + { + foreach (InfoTitle infoTitle in infoTitlesList) + { + infoTitles.Remove(infoTitle); + } + } } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 938aef7..416d46c 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -87,12 +87,6 @@ public class StubManager : IDataManager stubCustomTitle = new StubCustomTitle(); stubInfoTitle = new StubInfoTitle(); stubPlaylist = new StubPlaylist(); - - dictAlbumInfo.Add(StubAlbum.GetAlbumByUrl("lastreet.png"), StubInfoTitle.GetInfoTitlesByUrl(new List<string>() { "url1.png", "url2.png" })); - dictAlbumInfo.Add(StubAlbum.GetAlbumByUrl("oui.png"), StubInfoTitle.GetInfoTitlesByUrl(new List<string>() { "url2.png" })); - - dictPlaylistTitles.Add(StubPlaylist.GetPlaylistByUrl("url1.png"), StubCustomTitle.GetCustomTitlesByUrl(new List<string>() { "url1.png", "url2.png" })); - dictPlaylistTitles.Add(StubPlaylist.GetPlaylistByUrl("url2.png"), StubCustomTitle.GetCustomTitlesByUrl(new List<string>() { "url2.png", "url3.png" })); } public List<Album> GetAlbums() @@ -202,4 +196,271 @@ public class StubManager : IDataManager } return null; } + + public InfoTitle? GetInfoTitleByUrl(string url) + { + throw new NotImplementedException(); + } + + public Album? GetAlbumByUrl(string url) + { + throw new NotImplementedException(); + } + + public Artist? GetArtistByName(string name) + { + throw new NotImplementedException(); + } + + public void AddAlbums(List<Album> albumsList) + { + foreach (Album a in albumsList) + { + StubAlbum.AddAlbum(a); + } + } + + public void AddArtists(List<Artist> artistsList) + { + foreach (Artist a in artistsList) + { + StubArtist.AddArtist(a); + } + } + + public void AddPlaylists(List<Playlist> playlistsList) + { + foreach (Playlist p in playlistsList) + { + StubPlaylist.AddPlaylist(p); + } + } + + public void AddCustomTitles(List<CustomTitle> customTitlesList) + { + foreach (CustomTitle ct in customTitlesList) + { + StubCustomTitle.AddCustomTitle(ct); + } + } + + public void AddInfoTitles(List<InfoTitle> infoTitlesList) + { + foreach (InfoTitle it in infoTitlesList) + { + StubInfoTitle.AddInfoTitle(it); + } + } + + public Playlist? GetPlaylistByUrl(string url) + { + foreach (Playlist p in StubPlaylist.Playlists) + { + if (p.ImageURL == url) + { + return p; + } + } + return null; + } + + public void UpdateCustomTitle(CustomTitle title, string name, string url, string info, string path) + { + title.Name = name; + title.ImageURL = url; + title.Information = info; + title.Path = path; + } + + public void UpdateCustomTitleByUrl(string url, string name, string newUrl, string info, string path) + { + CustomTitle? title = GetCustomTitleByUrl(url); + if (title != null) + { + title.Name = name; + title.ImageURL = newUrl; + title.Information = info; + title.Path = path; + } + } + + public void UpdateInfoTitle(InfoTitle title, string name, string url, string info, Artist artist, string description, Genre genre) + { + title.Name = name; + title.ImageURL = url; + title.Information = info; + title.Artist = artist; + title.Description = description; + title.Genre = genre; + } + + public void UpdateInfoTitleByName(string url, string name, string newUrl, string info, Artist artist, string description, Genre genre) + { + InfoTitle? title = GetInfoTitleByUrl(url); + if (title != null) + { + 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 url, string name, string newUrl, string info, string artist, string description, Genre genre) + { + InfoTitle? title = GetInfoTitleByUrl(url); + 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; + } + } + + public void UpdateAlbum(Album album, string name, string url, Artist artist, string description, string info) + { + album.Name = name; + album.ImageURL = url; + album.Artist = artist; + album.Description = description; + album.Information = info; + } + + public void UpdateAlbumByUrl(string url, string name, string newUrl, Artist artist, string description, string info) + { + Album? album = GetAlbumByUrl(url); + if (album != null) + { + album.Name = name; + album.ImageURL = newUrl; + album.Artist = artist; + album.Description = description; + album.Information = info; + } + } + + public void UpdateAlbumByArtistName(Album album, string name, string url, string artist, string description, string info) + { + album.Name = name; + album.ImageURL = url; + Artist? artist2 = GetArtistByName(artist); + if (artist2 != null) + { + album.Artist = artist2; + } + album.Description = description; + album.Information = info; + } + + public void UpdateAlbumByUrlByArtistName(string url, string name, string newUrl, string artist, string description, string info) + { + Album? album = GetAlbumByUrl(url); + if (album != null) + { + album.Name = name; + album.ImageURL = newUrl; + Artist? artist2 = GetArtistByName(artist); + if (artist2 != null) + { + album.Artist = artist2; + } + album.Description = description; + album.Information = info; + } + } + + public void UpdatePlaylist(Playlist playlist, string name, string description, string url) + { + playlist.Name = name; + playlist.Description = description; + playlist.ImageURL = url; + } + + public void UpdatePlaylistByUrl(string url, string name, string description, string newUrl) + { + Playlist? playlist = GetPlaylistByUrl(url); + if (playlist != null) + { + playlist.Name = name; + playlist.Description = description; + playlist.ImageURL = newUrl; + } + } + + public void UpdateArtist(Artist artist, string name) + { + artist.Name = name; + } + + public void UpdateArtistByName(string name, string newName) + { + Artist? artist = GetArtistByName(newName); + if (artist != null) + { + artist.Name = newName; + } + } + + public void RemoveAlbums(List<Album> albumsList) + { + foreach (Album album in albumsList) + { + StubAlbum.RemoveAlbum(album); + } + } + + public void RemoveArtists(List<Artist> artistsList) + { + foreach (Artist artist in artistsList) + { + StubArtist.RemoveArtist(artist); + } + } + + public void RemovePlaylists(List<Playlist> playlistsList) + { + foreach (Playlist playlist in playlistsList) + { + StubPlaylist.RemovePlaylist(playlist); + } + } + + public void RemoveCustomTitles(List<CustomTitle> customTitlesList) + { + foreach (CustomTitle customTitle in customTitlesList) + { + StubCustomTitle.RemoveCustomTitle(customTitle); + } + } + + public void RemoveInfoTitles(List<InfoTitle> infoTitlesList) + { + foreach (InfoTitle infoTitle in infoTitlesList) + { + StubInfoTitle.RemoveInfoTitle(infoTitle); + } + } } From b54dd51b121dac5b4cea27f2fc647e71287ce4da Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <colemaire> Date: Sat, 13 May 2023 12:07:27 +0200 Subject: [PATCH 33/45] Enhance serialization --- .../Serialization/LINQ_XML_Serialization.cs | 60 +++++++++++++++---- Sources/Model/Stub/StubManager.cs | 30 ---------- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index b955139..b82a511 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -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", diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 416d46c..9405d37 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -2,29 +2,6 @@ public class StubManager : IDataManager { - - // Dictionaries - - IDictionary<Album, List<InfoTitle>> DictAlbumInfo - { - get - { - return dictAlbumInfo; - } - } - - Dictionary<Album, List<InfoTitle>> dictAlbumInfo; - - IDictionary<Playlist, List<CustomTitle>> DictPlaylistTitles - { - get - { - return dictPlaylistTitles; - } - } - - Dictionary<Playlist, List<CustomTitle>> dictPlaylistTitles; - // Stubs public StubAlbum StubAlbum @@ -79,9 +56,6 @@ public class StubManager : IDataManager public StubManager() { - dictAlbumInfo = new Dictionary<Album, List<InfoTitle>>(); - dictPlaylistTitles = new Dictionary<Playlist, List<CustomTitle>>(); - stubAlbum = new StubAlbum(); stubArtist = new StubArtist(); stubCustomTitle = new StubCustomTitle(); @@ -171,10 +145,6 @@ public class StubManager : IDataManager StubArtist.RemoveArtist(artist); } - - - - public void LoadSerialization() { return; From 4c2417f27124cca79fc12d9fd82c2f59badf08af Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sat, 13 May 2023 15:51:11 +0200 Subject: [PATCH 34/45] Finish the Serialization development --- Sources/Model/IDataManager.cs | 20 ++ .../Serialization/LINQ_XML_Serialization.cs | 184 ++++++++++++++---- Sources/Model/Stub/StubManager.cs | 120 ++++++++++++ 3 files changed, 282 insertions(+), 42 deletions(-) diff --git a/Sources/Model/IDataManager.cs b/Sources/Model/IDataManager.cs index 257e0b9..e0907ce 100644 --- a/Sources/Model/IDataManager.cs +++ b/Sources/Model/IDataManager.cs @@ -100,4 +100,24 @@ public interface IDataManager void SaveSerialization(); + // Exists + bool ExistsPlaylist(Playlist playlist); + + bool ExistsPlaylistByUrl(string url); + + bool ExistsAlbum(Album album); + + bool ExistsAlbumByUrl(string url); + + bool ExistsArtist(Artist artist); + + bool ExistsArtistByName(string name); + + bool ExistsCustomTitle(CustomTitle title); + + bool ExistsCustomTitleByUrl(string url); + + bool ExistsInfoTitle(InfoTitle title); + + bool ExistsInfoTitleByUrl(string url); } \ No newline at end of file diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index b82a511..c8c3b3f 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -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; + } } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 9405d37..7b48b03 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -433,4 +433,124 @@ public class StubManager : IDataManager StubInfoTitle.RemoveInfoTitle(infoTitle); } } + + public bool ExistsPlaylist(Playlist playlist) + { + foreach (Playlist p in StubPlaylist.Playlists) + { + if (p == playlist) + { + return true; + } + } + return false; + } + + public bool ExistsPlaylistByUrl(string url) + { + foreach (Playlist p in StubPlaylist.Playlists) + { + if (p.ImageURL == url) + { + return true; + } + } + return false; + } + + public bool ExistsAlbum(Album album) + { + foreach (Album a in StubAlbum.Albums) + { + if (a == album) + { + return true; + } + } + return false; + } + + public bool ExistsAlbumByUrl(string url) + { + foreach (Album a in StubAlbum.Albums) + { + if (a.ImageURL == url) + { + return true; + } + } + return false; + } + + public bool ExistsArtist(Artist artist) + { + foreach (Artist a in StubArtist.Artists) + { + if (a == artist) + { + return true; + } + } + return false; + } + + public bool ExistsArtistByName(string name) + { + foreach (Artist a in StubArtist.Artists) + { + if (a.Name == name) + { + return true; + } + } + return false; + } + + public bool ExistsCustomTitle(CustomTitle title) + { + foreach (CustomTitle ct in StubCustomTitle.CustomTitles) + { + if (title == ct) + { + return true; + } + } + return false; + } + + public bool ExistsCustomTitleByUrl(string url) + { + foreach (CustomTitle ct in StubCustomTitle.CustomTitles) + { + if (ct.ImageURL == url) + { + return true; + } + } + return false; + } + + public bool ExistsInfoTitle(InfoTitle title) + { + foreach (InfoTitle it in StubInfoTitle.InfoTitles) + { + if (it == title) + { + return true; + } + } + return false; + } + + public bool ExistsInfoTitleByUrl(string url) + { + foreach (InfoTitle it in StubInfoTitle.InfoTitles) + { + if (it.ImageURL == url) + { + return true; + } + } + return false; + } } From d4d304f9cda10350c4ff616ca086e71836ad5268 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 18:09:53 +0200 Subject: [PATCH 35/45] Fix Major issues --- Sources/Model/Stub/Stub.cs | 110 ++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/Sources/Model/Stub/Stub.cs b/Sources/Model/Stub/Stub.cs index 906c959..dcef669 100644 --- a/Sources/Model/Stub/Stub.cs +++ b/Sources/Model/Stub/Stub.cs @@ -1,67 +1,67 @@ -namespace Model.Stub; - -public class Stub : IDataManager -{ - +namespace Model.Stub; + +public class Stub : IDataManager +{ + public IEnumerable<Artiste> Artistes { get => artistes; - } - + } + public IEnumerable<Album> Albums { get => albums; - } - + } + public IEnumerable<Playlist> Playlists { get => playlists; - } - + } + public IEnumerable<Title> Titles { get => titles; - } - - private IEnumerable<Artiste> artistes; - - private IEnumerable<Album> albums; - - private IEnumerable<Playlist> playlists; - - private IEnumerable<Title> titles; - - public Stub() - { - artistes = new List<Artiste>(); - albums = new List<Album>(); - playlists = new List<Playlist>(); - titles = new List<Title>(); - - Artiste Artiste1 = new Artiste("Critien"); - Artiste Artiste2 = new Artiste("Gouriet"); - Artiste Artiste3 = new Artiste("Poulifer"); - Artiste Artiste4 = new Artiste("Credian"); - - Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); - Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); - - Artiste1.AddAlbum(Album1); - Artiste1.AddAlbum(new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2")); - Artiste2.AddAlbum(new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3")); - Artiste2.AddAlbum(Album4); - - Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); - Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); - - Playlist1.AddTitle(new CustomTitle("custom1", "url1.png", "info1", "chemin1")); - Playlist1.AddTitle(new CustomTitle("custom2", "url2.png", "info2", "chemin2")); - Playlist1.AddTitle(new CustomTitle("custom3", "url3.png", "info3", "chemin3")); - Playlist2.AddTitle(new CustomTitle("custom4", "url4.png", "info4", "chemin4")); - - Album1.AddTitle(new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP)); - Album1.AddTitle(new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL)); - Album1.AddTitle(new InfoTitle("info3", "url3.png", "info3", Artiste4, "desc3", Genre.BLUES)); - Album4.AddTitle(new InfoTitle("info4", "url4.png", "info4", Artiste3, "desc4", Genre.DISCO)); - } -} + } + + private readonly IEnumerable<Artiste> artistes; + + private readonly IEnumerable<Album> albums; + + private readonly IEnumerable<Playlist> playlists; + + private readonly IEnumerable<Title> titles; + + public Stub() + { + artistes = new List<Artiste>(); + albums = new List<Album>(); + playlists = new List<Playlist>(); + titles = new List<Title>(); + + Artiste Artiste1 = new Artiste("Critien"); + Artiste Artiste2 = new Artiste("Gouriet"); + Artiste Artiste3 = new Artiste("Poulifer"); + Artiste Artiste4 = new Artiste("Credian"); + + Album Album1 = new Album("la street", "lastreet.png", Artiste1, "c'est la street", "plein d'infos1"); + Album Album4 = new Album("la pas le choix", "peutetre.png", Artiste4, "c'est la parterre", "plein d'infos4"); + + Artiste1.AddAlbum(Album1); + Artiste1.AddAlbum(new Album("la jsp", "oui.png", Artiste1, "c'est la couri", "plein d'infos2")); + Artiste2.AddAlbum(new Album("la pas le temps", "non.png", Artiste3, "c'est pas la street", "plein d'infos3")); + Artiste2.AddAlbum(Album4); + + Playlist Playlist1 = new Playlist("Playlist1", "desc1", "url1.png"); + Playlist Playlist2 = new Playlist("Playlist2", "desc2", "url2.png"); + + Playlist1.AddTitle(new CustomTitle("custom1", "url1.png", "info1", "chemin1")); + Playlist1.AddTitle(new CustomTitle("custom2", "url2.png", "info2", "chemin2")); + Playlist1.AddTitle(new CustomTitle("custom3", "url3.png", "info3", "chemin3")); + Playlist2.AddTitle(new CustomTitle("custom4", "url4.png", "info4", "chemin4")); + + Album1.AddTitle(new InfoTitle("info1", "url1.png", "info1", Artiste2, "desc1", Genre.K_POP)); + Album1.AddTitle(new InfoTitle("info2", "url2.png", "info2", Artiste3, "desc2", Genre.GOSPEL)); + Album1.AddTitle(new InfoTitle("info3", "url3.png", "info3", Artiste4, "desc3", Genre.BLUES)); + Album4.AddTitle(new InfoTitle("info4", "url4.png", "info4", Artiste3, "desc4", Genre.DISCO)); + } +} From 6b5fa02017613ffeb8cec94b261ee9100017ef18 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 18:58:07 +0200 Subject: [PATCH 36/45] Fix Serialization merge's issue --- Sources/Model/Serialization/LINQ_XML_Serialization.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index c8c3b3f..e0e242f 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -195,7 +195,7 @@ public class LINQ_XML_Serialization : IDataManager 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) : "") + new XElement("Titles", p.Titles.Count() > 0 ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") )); PlaylistFile.Add(new XElement("Playlists", playlist)); @@ -247,7 +247,7 @@ public class LINQ_XML_Serialization : IDataManager 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) : "") + new XElement("Titles", playlist.Titles.Count() > 0 ? playlist.Titles.Select(p => p.ImageURL).Aggregate((playlistUrl, nextPlaylist) => playlistUrl + " " + nextPlaylist) : "") )); PlaylistsFichier.Add(new XElement("Playlists", playlist)); From aa518b70d849bd93c46a553a545ee4a625853846 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 19:12:50 +0200 Subject: [PATCH 37/45] Fix test issue --- Sources/Model/Album.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 2ca3032..8ff0fd0 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -115,7 +115,7 @@ namespace Model public override bool Equals(object? obj) { if (obj is null) return false; - if (obj.GetType() != typeof(Artist)) return false; + if (obj.GetType() != typeof(Album)) return false; if (obj is Album album && ImageURL == album.ImageURL) return true; else return false; } From 33d695b1e5a59ad9f67df4281f194b4170e22acd Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 19:41:29 +0200 Subject: [PATCH 38/45] Fix 1 Medium security hostpost --- Sources/Console/Program.cs | 13 +++++++------ Sources/Model/Playlist.cs | 21 ++++++++++++++++----- Sources/Model/Stub/StubManager.cs | 1 + 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 1900769..97219d7 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -2,7 +2,7 @@ using Model.Serialization; using Model.Stub; -IDataManager DataManager = new LINQ_XML_Serialization(); +IDataManager DataManager = new StubManager(); Manager Manager = new Manager(DataManager); @@ -20,7 +20,7 @@ foreach (Album Album in Manager.GetAlbums()) Console.WriteLine(Album.Name); }*/ -/*Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); +Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); Playlist p1 = Manager.Playlists.First(); @@ -117,9 +117,10 @@ p1.PreviousTitle(); current = p1.GetCurrentTitle(); Console.WriteLine(current?.Name); p1.PreviousTitle(); -current = p1.GetCurrentTitle();*/ -/*Console.WriteLine(current?.Name);*/ -Manager.LoadSerialization(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +/*Manager.LoadSerialization(); foreach (var p in Manager.GetPlaylists()) { Console.WriteLine(p.Name); @@ -148,4 +149,4 @@ foreach (var a in Manager.GetAlbums()) { Console.WriteLine(a.Name); } -Manager.SaveSerialization(); \ No newline at end of file +Manager.SaveSerialization();*/ \ No newline at end of file diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 356156f..8488ebf 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -1,4 +1,5 @@ using Model.Stub; +using System.Security.Cryptography; using System.Xml.Serialization; namespace Model; @@ -98,8 +99,6 @@ public class Playlist public bool LoopTitle = false; - Random Aleatoire = new Random(); - private List<int> played = new List<int>(); public IEnumerable<int> Played @@ -146,7 +145,7 @@ public class Playlist } else { - Index = Aleatoire.Next(titles.Count()); + Index = RandomGenerator(titles.Count()); played.Add(Index); } } @@ -160,8 +159,11 @@ public class Playlist if(!Shuffle) { - Index--; - played.RemoveAt(played.Count - 1); + if(Index != 0) + { + Index--; + played.RemoveAt(played.Count - 1); + } } else { @@ -204,4 +206,13 @@ public class Playlist { return $"Name : {Name}"; } + + int RandomGenerator(int n) + { + RandomNumberGenerator rng = RandomNumberGenerator.Create(); + byte[] randomBytes = new byte[4]; + rng.GetBytes(randomBytes); + int randomNumber = BitConverter.ToInt32(randomBytes, 0); + return randomNumber % n + 1; + } } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 7b48b03..316bac8 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -61,6 +61,7 @@ public class StubManager : IDataManager stubCustomTitle = new StubCustomTitle(); stubInfoTitle = new StubInfoTitle(); stubPlaylist = new StubPlaylist(); + StubPlaylist.Playlists.First().AddTitle(StubCustomTitle.CustomTitles.First()); } public List<Album> GetAlbums() From a87d611c4f96d74bc9804da19826d2f66255060a Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 21:43:53 +0200 Subject: [PATCH 39/45] Fix Critical issues --- Sources/Model/InfoTitle.cs | 2 +- Sources/Model/Manager.cs | 20 ++++++++--------- Sources/Model/Playlist.cs | 2 +- .../Serialization/LINQ_XML_Serialization.cs | 22 +++++++++---------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index a3483c7..444a6ff 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -40,7 +40,7 @@ public class InfoTitle : Title { get { - return feat.ToList(); + return new List<Artist>(feat); } } diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index 08c405c..a084883 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -2,15 +2,15 @@ public class Manager { - public static int MAX_NAME_LENGTH = 75; + public readonly static int MAX_NAME_LENGTH = 75; - public static int MAX_DESCRIPTION_LENGTH = 500; + public readonly static int MAX_DESCRIPTION_LENGTH = 500; - public static string DEFAULT_NAME = "Unknown"; + public readonly static string DEFAULT_NAME = "Unknown"; - public static string DEFAULT_URL = "none.png"; + public readonly static string DEFAULT_URL = "none.png"; - public static string DEFAULT_DESC = ""; + public readonly static string DEFAULT_DESC = ""; public IDataManager DataManager { get; set; } @@ -20,7 +20,7 @@ public class Manager { get { - return albums.ToList(); + return new List<Album>(albums); } } @@ -30,7 +30,7 @@ public class Manager { get { - return customTitles.ToList(); + return new List<CustomTitle>(customTitles); } } @@ -40,7 +40,7 @@ public class Manager { get { - return infoTitles.ToList(); + return new List<InfoTitle>(infoTitles); } } @@ -50,7 +50,7 @@ public class Manager { get { - return playlists.ToList(); + return new List<Playlist>(playlists); } } @@ -60,7 +60,7 @@ public class Manager { get { - return artists.ToList(); + return new List<Artist>(artists); } } diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 8488ebf..aa67ba3 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -105,7 +105,7 @@ public class Playlist { get { - return played.ToList(); + return new List<int>(played); } } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index e0e242f..c976886 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -31,7 +31,7 @@ public class LINQ_XML_Serialization : IDataManager { get { - return artists.ToList(); + return new List<Artist>(artists); } } @@ -41,7 +41,7 @@ public class LINQ_XML_Serialization : IDataManager { get { - return albums.ToList(); + return new List<Album>(albums); } } @@ -51,7 +51,7 @@ public class LINQ_XML_Serialization : IDataManager { get { - return playlists.ToList(); + return new List<Playlist>(playlists); } } @@ -61,7 +61,7 @@ public class LINQ_XML_Serialization : IDataManager { get { - return infoTitles.ToList(); + return new List<InfoTitle>(infoTitles); } } @@ -71,7 +71,7 @@ public class LINQ_XML_Serialization : IDataManager { get { - return customTitles.ToList(); + return new List<CustomTitle>(customTitles); } } @@ -582,11 +582,11 @@ public class LINQ_XML_Serialization : IDataManager else return Genre.K_POP; } - public InfoTitle? GetInfoTitleByUrl(string infoUrl) + public InfoTitle? GetInfoTitleByUrl(string url) { foreach(InfoTitle it in infoTitles) { - if (it.Name == infoUrl) + if (it.Name == url) { return it; } @@ -594,11 +594,11 @@ public class LINQ_XML_Serialization : IDataManager return null; } - public Artist? GetArtistByName(string artist) + public Artist? GetArtistByName(string name) { foreach(Artist a in artists) { - if (a.Name == artist) + if (a.Name == name) { return a; } @@ -606,11 +606,11 @@ public class LINQ_XML_Serialization : IDataManager return null; } - public Album? GetAlbumByUrl(string album) + public Album? GetAlbumByUrl(string url) { foreach(Album a in albums) { - if (a.ImageURL == album) + if (a.ImageURL == url) { return a; } From 94cb705c522be78186f4aeb1394cd4bb86eb15cd Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 22:01:27 +0200 Subject: [PATCH 40/45] Fix Major issues --- Sources/Console/Program.cs | 18 ++---------------- Sources/Model/Album.cs | 4 ++-- Sources/Model/Playlist.cs | 10 +++++----- .../Serialization/LINQ_XML_Serialization.cs | 18 ++++++++++-------- Sources/Model/Stub/StubAlbum.cs | 12 ++++++------ Sources/Model/Stub/StubArtist.cs | 2 +- Sources/Model/Stub/StubCustomTitle.cs | 2 +- Sources/Model/Stub/StubInfoTitle.cs | 8 ++++---- Sources/Model/Stub/StubManager.cs | 10 +++++----- Sources/Model/Stub/StubPlaylist.cs | 2 +- 10 files changed, 37 insertions(+), 49 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 97219d7..85e3b24 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -6,20 +6,6 @@ IDataManager DataManager = new StubManager(); Manager Manager = new Manager(DataManager); -/*foreach(Album Album in Manager.GetAlbums()) -{ - Console.WriteLine(Album.Name); -} - -Console.WriteLine("---------------"); - -Manager.AddAlbum(new Album("coucou", "path.png", new Artist("lorenzo"), "descLolo", "infoLolo")); - -foreach (Album Album in Manager.GetAlbums()) -{ - Console.WriteLine(Album.Name); -}*/ - Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); Playlist p1 = Manager.Playlists.First(); @@ -120,7 +106,7 @@ p1.PreviousTitle(); current = p1.GetCurrentTitle(); Console.WriteLine(current?.Name); -/*Manager.LoadSerialization(); +Manager.LoadSerialization(); foreach (var p in Manager.GetPlaylists()) { Console.WriteLine(p.Name); @@ -149,4 +135,4 @@ foreach (var a in Manager.GetAlbums()) { Console.WriteLine(a.Name); } -Manager.SaveSerialization();*/ \ No newline at end of file +Manager.SaveSerialization(); \ No newline at end of file diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 8ff0fd0..3512f0a 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -37,7 +37,7 @@ namespace Model private string description = Manager.DEFAULT_DESC; - private List<Title> titles = new List<Title>(); + private readonly List<Title> titles = new List<Title>(); public IEnumerable<Title> Titles { @@ -55,7 +55,7 @@ namespace Model { if (value == null || !value.Contains('.')) { - value = "none.png"; + value = Manager.DEFAULT_URL; imageURL = value; } if (value.Contains(' ')) diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index aa67ba3..0a323fb 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -76,7 +76,7 @@ public class Playlist set { - if (value < titles.Count()) + if (value < titles.Count) { index = value; } @@ -99,7 +99,7 @@ public class Playlist public bool LoopTitle = false; - private List<int> played = new List<int>(); + private readonly List<int> played = new List<int>(); public IEnumerable<int> Played { @@ -145,7 +145,7 @@ public class Playlist } else { - Index = RandomGenerator(titles.Count()); + Index = RandomGenerator(titles.Count); played.Add(Index); } } @@ -167,7 +167,7 @@ public class Playlist } else { - if (played.Count() == 0) + if (played.Count == 0) { return; } @@ -178,7 +178,7 @@ public class Playlist public Title? GetCurrentTitle() { - if (Index < titles.Count()) + if (Index < titles.Count) { return titles[Index]; } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index c976886..c38ff66 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -419,13 +419,15 @@ public class LINQ_XML_Serialization : IDataManager XDocument AlbumsFile = XDocument.Load(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(); + .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(); + + foreach (Album a in albums) { @@ -510,7 +512,7 @@ public class LINQ_XML_Serialization : IDataManager eltPlaylist.Attribute("Name")!.Value, eltPlaylist.Element("ImageURL")!.Value, eltPlaylist.Element("Information")!.Value, - GetArtistByName(eltPlaylist.Element("Feats")!.Value), + GetArtistByName(eltPlaylist.Element("Feats")!.Value) ?? new Artist(), eltPlaylist.Element("Description")!.Value, GetGenreByName(eltPlaylist.Element("Genre")!.Value) )).ToList(); diff --git a/Sources/Model/Stub/StubAlbum.cs b/Sources/Model/Stub/StubAlbum.cs index 9c61a5d..3de4e1a 100644 --- a/Sources/Model/Stub/StubAlbum.cs +++ b/Sources/Model/Stub/StubAlbum.cs @@ -12,23 +12,23 @@ public class StubAlbum } } - private StubArtist stubArtist; + private readonly StubArtist stubArtist; public List<Album> Albums { get => albums; } - private List<Album> albums; + private readonly List<Album> albums; public StubAlbum() { stubArtist = new StubArtist(); - Album Album1 = new Album("la street", "lastreet.png", StubArtist.GetArtistByName("Critien"), "c'est la street", "plein d'infos1"); - Album Album2 = new Album("la jsp", "oui.png", StubArtist.GetArtistByName("Critien"), "c'est la couri", "plein d'infos2"); - Album Album3 = new Album("la pas le temps", "non.png", StubArtist.GetArtistByName("Poulifer"), "c'est pas la street", "plein d'infos3"); - Album Album4 = new Album("la pas le choix", "peutetre.png", StubArtist.GetArtistByName("Credian"), "c'est la parterre", "plein d'infos4"); + Album Album1 = new Album("la street", "lastreet.png", StubArtist.GetArtistByName("Critien") ?? new Artist("Critien"), "c'est la street", "plein d'infos1"); + Album Album2 = new Album("la jsp", "oui.png", StubArtist.GetArtistByName("Critien") ?? new Artist("Critien"), "c'est la couri", "plein d'infos2"); + Album Album3 = new Album("la pas le temps", "non.png", StubArtist.GetArtistByName("Poulifer") ?? new Artist("Poulifer"), "c'est pas la street", "plein d'infos3"); + Album Album4 = new Album("la pas le choix", "peutetre.png", StubArtist.GetArtistByName("Credian") ?? new Artist("Credian"), "c'est la parterre", "plein d'infos4"); albums = new List<Album>() { Album1, Album2, Album3, Album4 diff --git a/Sources/Model/Stub/StubArtist.cs b/Sources/Model/Stub/StubArtist.cs index 9634124..04b445b 100644 --- a/Sources/Model/Stub/StubArtist.cs +++ b/Sources/Model/Stub/StubArtist.cs @@ -7,7 +7,7 @@ public class StubArtist get => artists; } - private List<Artist> artists; + private readonly List<Artist> artists; public StubArtist() { diff --git a/Sources/Model/Stub/StubCustomTitle.cs b/Sources/Model/Stub/StubCustomTitle.cs index e8a7cbc..2886a0b 100644 --- a/Sources/Model/Stub/StubCustomTitle.cs +++ b/Sources/Model/Stub/StubCustomTitle.cs @@ -8,7 +8,7 @@ public class StubCustomTitle get => customTitles; } - private List<CustomTitle> customTitles; + private readonly List<CustomTitle> customTitles; public StubCustomTitle() { diff --git a/Sources/Model/Stub/StubInfoTitle.cs b/Sources/Model/Stub/StubInfoTitle.cs index 3854697..7e32d4b 100644 --- a/Sources/Model/Stub/StubInfoTitle.cs +++ b/Sources/Model/Stub/StubInfoTitle.cs @@ -11,21 +11,21 @@ public class StubInfoTitle } } - private StubArtist stubArtist; + private readonly StubArtist stubArtist; public List<InfoTitle> InfoTitles { get => infoTitles; } - private List<InfoTitle> infoTitles; + private readonly List<InfoTitle> infoTitles; public StubInfoTitle() { stubArtist = new StubArtist(); - InfoTitle InfoTitle1 = new InfoTitle("info1", "url1.png", "info1", StubArtist.GetArtistByName("Gouriet"), "desc1", Genre.K_POP); - InfoTitle InfoTitle2 = new InfoTitle("info2", "url2.png", "info2", StubArtist.GetArtistByName("Poulifer"), "desc2", Genre.GOSPEL); + InfoTitle InfoTitle1 = new InfoTitle("info1", "url1.png", "info1", StubArtist.GetArtistByName("Gouriet") ?? new Artist("Gouriet"), "desc1", Genre.K_POP); + InfoTitle InfoTitle2 = new InfoTitle("info2", "url2.png", "info2", StubArtist.GetArtistByName("Poulifer") ?? new Artist("Poulifer"), "desc2", Genre.GOSPEL); infoTitles = new List<InfoTitle>() { diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 316bac8..7f86638 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -12,7 +12,7 @@ public class StubManager : IDataManager } } - private StubAlbum stubAlbum; + private readonly StubAlbum stubAlbum; public StubArtist StubArtist { @@ -22,7 +22,7 @@ public class StubManager : IDataManager } } - private StubArtist stubArtist; + private readonly StubArtist stubArtist; public StubCustomTitle StubCustomTitle { @@ -32,7 +32,7 @@ public class StubManager : IDataManager } } - private StubCustomTitle stubCustomTitle; + private readonly StubCustomTitle stubCustomTitle; public StubInfoTitle StubInfoTitle { @@ -42,7 +42,7 @@ public class StubManager : IDataManager } } - private StubInfoTitle stubInfoTitle; + private readonly StubInfoTitle stubInfoTitle; public StubPlaylist StubPlaylist { @@ -52,7 +52,7 @@ public class StubManager : IDataManager } } - private StubPlaylist stubPlaylist; + private readonly StubPlaylist stubPlaylist; public StubManager() { diff --git a/Sources/Model/Stub/StubPlaylist.cs b/Sources/Model/Stub/StubPlaylist.cs index 9c11fbb..681750d 100644 --- a/Sources/Model/Stub/StubPlaylist.cs +++ b/Sources/Model/Stub/StubPlaylist.cs @@ -8,7 +8,7 @@ public class StubPlaylist get => playlists; } - private List<Playlist> playlists; + private readonly List<Playlist> playlists; public StubPlaylist() { From 099892fcf0de58d3e6740b952f97a32f98144bbd Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 22:13:22 +0200 Subject: [PATCH 41/45] Fix Minor issues --- Sources/Model/InfoTitle.cs | 12 +------- Sources/Model/Manager.cs | 10 +++---- Sources/Model/Playlist.cs | 30 ++++++++++++++----- .../Serialization/LINQ_XML_Serialization.cs | 18 +++++------ Sources/Model/Stub/StubManager.cs | 4 +-- 5 files changed, 39 insertions(+), 35 deletions(-) diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index 444a6ff..1bb263e 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -5,17 +5,7 @@ namespace Model; public class InfoTitle : Title { - public Artist Artist - { - get - { - return artist; - } - set - { - artist = value; - } - } + public Artist Artist { get; set; } private Artist artist = new Artist(); diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs index a084883..008c17e 100644 --- a/Sources/Model/Manager.cs +++ b/Sources/Model/Manager.cs @@ -14,7 +14,7 @@ public class Manager public IDataManager DataManager { get; set; } - private List<Album> albums = new List<Album>(); + private List<Album> albums; public IEnumerable<Album> Albums { @@ -24,7 +24,7 @@ public class Manager } } - private List<CustomTitle> customTitles = new List<CustomTitle>(); + private List<CustomTitle> customTitles; public IEnumerable<CustomTitle> CustomTitles { @@ -34,7 +34,7 @@ public class Manager } } - private List<InfoTitle> infoTitles = new List<InfoTitle>(); + private List<InfoTitle> infoTitles; public IEnumerable<InfoTitle> InfoTitles { @@ -44,7 +44,7 @@ public class Manager } } - private List<Playlist> playlists = new List<Playlist>(); + private List<Playlist> playlists; public IEnumerable<Playlist> Playlists { @@ -54,7 +54,7 @@ public class Manager } } - private List<Artist> artists = new List<Artist>(); + private List<Artist> artists; public IEnumerable<Artist> Artists { diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 0a323fb..25dd7eb 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -84,20 +84,34 @@ public class Playlist { index = 0; } - else - { - return; - } } } private int index = 0; - public bool Shuffle = false; + public bool Shuffle + { + get => shuffle; + set { shuffle = value; } + } + + private bool shuffle = false; - public bool Loop = false; + public bool Loop + { + get => loop; + set { loop = value; } + } + + private bool loop = false; + + public bool LoopTitle + { + get => loopTitle; + set { loopTitle = value; } + } - public bool LoopTitle = false; + private bool loopTitle = false; private readonly List<int> played = new List<int>(); @@ -167,7 +181,7 @@ public class Playlist } else { - if (played.Count == 0) + if (!played.Any()) { return; } diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index c38ff66..c0a4b44 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -11,7 +11,7 @@ using System.IO; namespace Model.Serialization; -public class LINQ_XML_Serialization : IDataManager +public class Linq_Xml_Serialization : IDataManager { private static string XMLPATH = Path.Combine(Environment.CurrentDirectory, "Data"); @@ -75,7 +75,7 @@ public class LINQ_XML_Serialization : IDataManager } } - public LINQ_XML_Serialization() + public Linq_Xml_Serialization() { playlists = new List<Playlist>(); artists = new List<Artist>(); @@ -195,7 +195,7 @@ public class LINQ_XML_Serialization : IDataManager new XAttribute("Name", p.Name), new XElement("Description", p.Description), new XElement("ImageURL", p.ImageURL), - new XElement("Titles", p.Titles.Count() > 0 ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") + new XElement("Titles", p.Titles.Any() ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") )); PlaylistFile.Add(new XElement("Playlists", playlist)); @@ -247,7 +247,7 @@ public class LINQ_XML_Serialization : IDataManager new XAttribute("Name", playlist.Name), new XElement("Description", playlist.Description), new XElement("ImageURL", playlist.ImageURL), - new XElement("Titles", playlist.Titles.Count() > 0 ? playlist.Titles.Select(p => p.ImageURL).Aggregate((playlistUrl, nextPlaylist) => playlistUrl + " " + nextPlaylist) : "") + new XElement("Titles", playlist.Titles.Any() ? playlist.Titles.Select(p => p.ImageURL).Aggregate((playlistUrl, nextPlaylist) => playlistUrl + " " + nextPlaylist) : "") )); PlaylistsFichier.Add(new XElement("Playlists", playlist)); @@ -398,10 +398,10 @@ public class LINQ_XML_Serialization : IDataManager 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("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.Count() > 0 ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") + new XElement("Titles", p.Titles.Any() ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") )); AlbumFile.Add(new XElement("Albums", album)); @@ -460,7 +460,7 @@ public class LINQ_XML_Serialization : IDataManager 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) : "") + new XElement("Titles", a.Titles.Any() ? a.Titles.Select(p => p.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") )); AlbumsFile.Add(new XElement("Albums", album)); @@ -488,7 +488,7 @@ public class LINQ_XML_Serialization : IDataManager 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("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) )); @@ -547,7 +547,7 @@ public class LINQ_XML_Serialization : IDataManager 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) : "") + new XElement("Feats", it.Feat.Any() ? it.Feat.Select(p => p.Name).Aggregate((featName, nextFeat) => featName + " " + nextFeat) : "") )); InfosFile.Add(new XElement("InfoTitles", info)); diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 7f86638..91d1431 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -148,12 +148,12 @@ public class StubManager : IDataManager public void LoadSerialization() { - return; + } public void SaveSerialization() { - return; + } public CustomTitle? GetCustomTitleByUrl(string custom) From a0da582aecaced62cc88f65d6e81ac8ce5a7aa4b Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 22:19:12 +0200 Subject: [PATCH 42/45] Fix name issue --- Sources/TestUnitaires/TU_Manager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TestUnitaires/TU_Manager.cs b/Sources/TestUnitaires/TU_Manager.cs index 3ff8d81..d4fc553 100644 --- a/Sources/TestUnitaires/TU_Manager.cs +++ b/Sources/TestUnitaires/TU_Manager.cs @@ -15,7 +15,7 @@ namespace TestUnitaires [InlineData("Réference")] public void TU_Methods(string? test) { - IDataManager DataManager = new LINQ_XML_Serialization(); + IDataManager DataManager = new Linq_Xml_Serialization(); Playlist p = new Playlist(test, "PlaceHolder", "place.holder"); Album album = new Album(test, "place.holder", new Artist("test"), "PlaceHolder", "PlaceHolder"); CustomTitle t = new CustomTitle(test, "test. mp3", "Banger", "path"); From c4c4c645f30a8696ea3cf06bb954ffc1e7a3fe7b Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 22:32:25 +0200 Subject: [PATCH 43/45] Fix some Critical, Major, Minor and Info issues --- Sources/Model/InfoTitle.cs | 4 +-- Sources/Model/Playlist.cs | 26 +++---------------- .../Serialization/LINQ_XML_Serialization.cs | 6 ++--- Sources/Model/Stub/StubInfoTitle.cs | 4 +-- Sources/Model/Stub/StubManager.cs | 4 +-- Sources/TestUnitaires/TU_Manager.cs | 2 +- 6 files changed, 13 insertions(+), 33 deletions(-) diff --git a/Sources/Model/InfoTitle.cs b/Sources/Model/InfoTitle.cs index 1bb263e..2330477 100644 --- a/Sources/Model/InfoTitle.cs +++ b/Sources/Model/InfoTitle.cs @@ -7,8 +7,6 @@ public class InfoTitle : Title { public Artist Artist { get; set; } - private Artist artist = new Artist(); - public string Description { get => description; @@ -38,7 +36,7 @@ public class InfoTitle : Title public InfoTitle(string name, string imageURL, string information, Artist artist, string description, Genre genre) : base(name,imageURL,information) { - this.artist = artist; + Artist = artist; Description = description; Genre = genre; } diff --git a/Sources/Model/Playlist.cs b/Sources/Model/Playlist.cs index 25dd7eb..a1d5727 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -89,29 +89,11 @@ public class Playlist private int index = 0; - public bool Shuffle - { - get => shuffle; - set { shuffle = value; } - } - - private bool shuffle = false; + public bool Shuffle { get; set; } = false; - public bool Loop - { - get => loop; - set { loop = value; } - } - - private bool loop = false; - - public bool LoopTitle - { - get => loopTitle; - set { loopTitle = value; } - } + public bool Loop { get; set; } = false; - private bool loopTitle = false; + public bool LoopTitle { get; set; } = false; private readonly List<int> played = new List<int>(); @@ -221,7 +203,7 @@ public class Playlist return $"Name : {Name}"; } - int RandomGenerator(int n) + static int RandomGenerator(int n) { RandomNumberGenerator rng = RandomNumberGenerator.Create(); byte[] randomBytes = new byte[4]; diff --git a/Sources/Model/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs index c0a4b44..63b9261 100644 --- a/Sources/Model/Serialization/LINQ_XML_Serialization.cs +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -11,7 +11,7 @@ using System.IO; namespace Model.Serialization; -public class Linq_Xml_Serialization : IDataManager +public class LinqXmlSerialization : IDataManager { private static string XMLPATH = Path.Combine(Environment.CurrentDirectory, "Data"); @@ -75,7 +75,7 @@ public class Linq_Xml_Serialization : IDataManager } } - public Linq_Xml_Serialization() + public LinqXmlSerialization() { playlists = new List<Playlist>(); artists = new List<Artist>(); @@ -562,7 +562,7 @@ public class Linq_Xml_Serialization : IDataManager } } } - public Genre GetGenreByName(string genre) + public static Genre GetGenreByName(string genre) { if (genre == "HIP_HOP") return Genre.HIP_HOP; if (genre == "POP") return Genre.POP; diff --git a/Sources/Model/Stub/StubInfoTitle.cs b/Sources/Model/Stub/StubInfoTitle.cs index 7e32d4b..3ee4cf2 100644 --- a/Sources/Model/Stub/StubInfoTitle.cs +++ b/Sources/Model/Stub/StubInfoTitle.cs @@ -60,11 +60,11 @@ public class StubInfoTitle { infoTitles.Remove(title); } - public void AddFeat(InfoTitle infoTitle, Artist artist) + public static void AddFeat(InfoTitle infoTitle, Artist artist) { infoTitle.AddFeat(artist); } - public void RemoveFeat(InfoTitle infoTitle, Artist artist) + public static void RemoveFeat(InfoTitle infoTitle, Artist artist) { infoTitle.RemoveFeat(artist); } diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index 91d1431..ce74617 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -148,12 +148,12 @@ public class StubManager : IDataManager public void LoadSerialization() { - + // Doesn't do anything because it's Stubs } public void SaveSerialization() { - + // Doesn't do anything because it's Stubs } public CustomTitle? GetCustomTitleByUrl(string custom) diff --git a/Sources/TestUnitaires/TU_Manager.cs b/Sources/TestUnitaires/TU_Manager.cs index d4fc553..026112e 100644 --- a/Sources/TestUnitaires/TU_Manager.cs +++ b/Sources/TestUnitaires/TU_Manager.cs @@ -15,7 +15,7 @@ namespace TestUnitaires [InlineData("Réference")] public void TU_Methods(string? test) { - IDataManager DataManager = new Linq_Xml_Serialization(); + IDataManager DataManager = new LinqXmlSerialization(); Playlist p = new Playlist(test, "PlaceHolder", "place.holder"); Album album = new Album(test, "place.holder", new Artist("test"), "PlaceHolder", "PlaceHolder"); CustomTitle t = new CustomTitle(test, "test. mp3", "Banger", "path"); From 620d9c2d7adb5c5b02cd0d7f99d8b9be50ba2364 Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Sun, 14 May 2023 22:38:46 +0200 Subject: [PATCH 44/45] Fix Info issues --- Sources/Model/Stub/StubManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Model/Stub/StubManager.cs b/Sources/Model/Stub/StubManager.cs index ce74617..ceb463f 100644 --- a/Sources/Model/Stub/StubManager.cs +++ b/Sources/Model/Stub/StubManager.cs @@ -104,7 +104,7 @@ public class StubManager : IDataManager StubInfoTitle.AddInfoTitle(title); } - public void AddFeat(InfoTitle infoTitle, Artist artist) + public static void AddFeat(InfoTitle infoTitle, Artist artist) { StubInfoTitle.AddFeat(infoTitle, artist); } From 237e80e1f9d9fca2670eabc5b5db14e0ceff52ed Mon Sep 17 00:00:00 2001 From: Corentin LEMAIRE <corentin.lemaire@etu.uca.fr> Date: Wed, 17 May 2023 19:26:49 +0200 Subject: [PATCH 45/45] Fix security hostposts --- Sources/Linaris/MauiProgram.cs | 11 +++++++---- Sources/Linaris/Platforms/Android/AndroidManifest.xml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/Linaris/MauiProgram.cs b/Sources/Linaris/MauiProgram.cs index 73e78be..0d06b48 100644 --- a/Sources/Linaris/MauiProgram.cs +++ b/Sources/Linaris/MauiProgram.cs @@ -10,17 +10,20 @@ public static class MauiProgram var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() - .ConfigureSyncfusionCore() - .ConfigureFonts(fonts => + .ConfigureSyncfusionCore() + .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); #if DEBUG - builder.Logging.AddDebug(); + builder.Services.AddLogging(configure => + { + configure.AddDebug(); + }); #endif - return builder.Build(); + return builder.Build(); } } diff --git a/Sources/Linaris/Platforms/Android/AndroidManifest.xml b/Sources/Linaris/Platforms/Android/AndroidManifest.xml index bdec9b5..0e5999b 100644 --- a/Sources/Linaris/Platforms/Android/AndroidManifest.xml +++ b/Sources/Linaris/Platforms/Android/AndroidManifest.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> - <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> + <application android:allowBackup="false" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:usesCleartextTraffic="false"></application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> </manifest> \ No newline at end of file