diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..c6dcbe4 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,42 @@ +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 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 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] diff --git a/Sources/Connsole/Program.cs b/Sources/Connsole/Program.cs deleted file mode 100644 index fb87e4e..0000000 --- a/Sources/Connsole/Program.cs +++ /dev/null @@ -1,25 +0,0 @@ -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 lst = new List { 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/Connsole/Console.csproj b/Sources/Console/Console.csproj similarity index 80% rename from Sources/Connsole/Console.csproj rename to Sources/Console/Console.csproj index 6abd0f7..e171fb5 100644 --- a/Sources/Connsole/Console.csproj +++ b/Sources/Console/Console.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs new file mode 100644 index 0000000..85e3b24 --- /dev/null +++ b/Sources/Console/Program.cs @@ -0,0 +1,138 @@ +using Model; +using Model.Serialization; +using Model.Stub; + +IDataManager DataManager = new StubManager(); + +Manager Manager = new Manager(DataManager); + +Manager.AddPlaylist(new Playlist("MegaTeuf", "DescPlaylist", "ImagePlaylist")); + +Playlist p1 = Manager.Playlists.First(); + +Title? current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +p1.NextTitle(); +current = p1.GetCurrentTitle(); +Console.WriteLine(current?.Name); + +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.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); + +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/Linaris.sln b/Sources/Linaris.sln index 413e4e5..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", "Connsole\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/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/FooterPage.xaml.cs b/Sources/Linaris/FooterPage.xaml.cs index 18f18ab..5a13306 100644 --- a/Sources/Linaris/FooterPage.xaml.cs +++ b/Sources/Linaris/FooterPage.xaml.cs @@ -19,7 +19,6 @@ public partial class FooterPage : ContentView // (s,a) = convention, s = sender, a = arguments, si appli fermée, on free tout outputDevice.PlaybackStopped += PlaybackStoppedHandler; - // morceauEnCours = "Musics/peaches.mp3"; morceauEnCours = Path.Combine(AppContext.BaseDirectory, "Resources", "Musics", "winter.mp3"); audioFile = new AudioFileReader(morceauEnCours); outputDevice.Init(audioFile); diff --git a/Sources/Linaris/Linaris.csproj b/Sources/Linaris/Linaris.csproj index bba3941..244b651 100644 --- a/Sources/Linaris/Linaris.csproj +++ b/Sources/Linaris/Linaris.csproj @@ -1,8 +1,10 @@  - net7.0-android;net7.0-ios;net7.0-maccatalyst - $(TargetFrameworks);net7.0-windows10.0.19041.0 + net7.0-android + $(TargetFrameworks);net7.0-windows10.0.19041.0 + $(TargetFrameworks);net7.0-ios + $(TargetFrameworks);net7.0-maccatalyst Exe @@ -45,7 +47,8 @@ - + + diff --git a/Sources/Linaris/MainPage.xaml.cs b/Sources/Linaris/MainPage.xaml.cs index 9e8598f..d6caaeb 100644 --- a/Sources/Linaris/MainPage.xaml.cs +++ b/Sources/Linaris/MainPage.xaml.cs @@ -2,23 +2,19 @@ public partial class MainPage : ContentPage { - // int count = 0; public MainPage() { InitializeComponent(); - } - /*private void OnCounterClicked(object sender, EventArgs e) - { - count++; + } + + async public Task Go_Home() + { + await Navigation.PushAsync(new MainPage()); + + } - if (count == 1) - CounterBtn.Text = $"Clicked {count} time"; - else - CounterBtn.Text = $"Clicked {count} times"; - SemanticScreenReader.Announce(CounterBtn.Text); - }*/ } 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() - .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 @@  - + \ No newline at end of file diff --git a/Sources/Model/Album.cs b/Sources/Model/Album.cs index 1eafa3e..3512f0a 100644 --- a/Sources/Model/Album.cs +++ b/Sources/Model/Album.cs @@ -1,33 +1,133 @@ -namespace Model +using Model.Stub; +using System.Diagnostics; +using System.Xml.Serialization; + +namespace Model { public class Album { - public string Nom { get; set; } - public string File_Name { get; set; } + public string Name + { + get => name; + + set + { + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) + { + name = value; + } + } + } + + private string name = Manager.DEFAULT_NAME; + + public string Description + { + get => description; + + set + { + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) + { + description = value; + } + } + } + + private string description = Manager.DEFAULT_DESC; + + private readonly List titles = new List<Title>(); + + public IEnumerable<Title> Titles + { + get + { + return new List<Title>(titles); + } + } + + public string ImageURL + { + get => imageURL; + + set + { + if (value == null || !value.Contains('.')) + { + value = Manager.DEFAULT_URL; + imageURL = value; + } + if (value.Contains(' ')) + { + imageURL = value.Replace(' ', '_'); + } + else if (value.Contains('.')) + { + imageURL = value; + } + } + } + + private string imageURL = Manager.DEFAULT_URL; - public Artiste Artiste { get; set; } + public Artist Artist { get; set; } - public string Description { get; set; } + public string Information + { + get => information; - public string Informations { get; set; } + set + { + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) + { + information = value; + } + } + } - public IEnumerable<Morceau> Morceaux { get; set; } + private string information = Manager.DEFAULT_DESC; - public Album(string nom, string file_Name, Artiste artiste, string description, string informations) + public Album(string name, string file_Name, Artist artist, string description, string information) { - Nom = nom; - File_Name = file_Name; - Artiste = artiste; + Name = name; + ImageURL = file_Name; + Artist = artist; Description = description; - Informations = informations; - Morceaux = new List<Morceau>(); + Information = information; + } + + public Album() + { + Artist = new Artist(Manager.DEFAULT_NAME); + } + + public void AddTitle(Title title) + { + titles.Add(title); } - public void addMorceau(Morceau morceau) + public void RemoveTitle(Title title) { - Morceaux.Prepend(morceau); + titles.Remove(title); } + public override bool Equals(object? obj) + { + if (obj is null) return false; + if (obj.GetType() != typeof(Album)) 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 new file mode 100644 index 0000000..936131d --- /dev/null +++ b/Sources/Model/Artist.cs @@ -0,0 +1,50 @@ +using Model.Stub; +using System.Xml.Serialization; + +namespace Model; + +public class Artist +{ + public string Name + { + get => name; + + set + { + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) + { + name = value; + } + } + } + + private string name = Manager.DEFAULT_NAME; + + public Artist(string name) + { + Name = name; + } + + public Artist() + { + + } + + public override bool Equals(object? obj) + { + 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 override string ToString() + { + return $"Name : {Name}"; + } +} diff --git a/Sources/Model/Artiste.cs b/Sources/Model/Artiste.cs deleted file mode 100644 index fa84929..0000000 --- a/Sources/Model/Artiste.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model -{ - public class Artiste - { - public string Nom { get; set; } - - public IEnumerable<Album> Albums { get; set; } - - public Artiste(string nom) - { - Nom = nom; - 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..c10039f --- /dev/null +++ b/Sources/Model/CustomTitle.cs @@ -0,0 +1,47 @@ +using Model.Stub; +using System.Runtime.CompilerServices; + +namespace Model; + +public class CustomTitle : Title { + + public string Path + { + get => path; + + set + { + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) + { + path = value; + } + } + } + + 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 new file mode 100644 index 0000000..f0aec92 --- /dev/null +++ b/Sources/Model/Genre.cs @@ -0,0 +1,7 @@ +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..af316ba --- /dev/null +++ b/Sources/Model/IDataManager.cs @@ -0,0 +1,123 @@ +namespace Model; + +public interface IDataManager +{ + // Create + void AddAlbum(Album album); + + void AddAlbums(List<Album> albumsList); + + void AddArtist(Artist artist); + + void AddArtists(List<Artist> artistsList); + + 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); + + List<InfoTitle> GetInfoTitles(); + + InfoTitle? GetInfoTitleByUrl(string url); + + List<Album> GetAlbums(); + + Album? GetAlbumByUrl(string url); + + List<Artist> GetArtists(); + + 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(); + + // 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/InfoTitle.cs b/Sources/Model/InfoTitle.cs new file mode 100644 index 0000000..2330477 --- /dev/null +++ b/Sources/Model/InfoTitle.cs @@ -0,0 +1,78 @@ +using System.Xml.Serialization; +using Model.Stub; + +namespace Model; + +public class InfoTitle : Title +{ + public Artist Artist { get; set; } + + 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 new List<Artist>(feat); + } + } + + public Genre Genre { get; set; } + + public InfoTitle(string name, string imageURL, string information, Artist artist, string description, Genre genre) : base(name,imageURL,information) + { + 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}"; + } +} \ No newline at end of file diff --git a/Sources/Model/Manager.cs b/Sources/Model/Manager.cs new file mode 100644 index 0000000..008c17e --- /dev/null +++ b/Sources/Model/Manager.cs @@ -0,0 +1,167 @@ +namespace Model.Stub; + +public class Manager +{ + public readonly static int MAX_NAME_LENGTH = 75; + + public readonly static int MAX_DESCRIPTION_LENGTH = 500; + + public readonly static string DEFAULT_NAME = "Unknown"; + + public readonly static string DEFAULT_URL = "none.png"; + + public readonly static string DEFAULT_DESC = ""; + + public IDataManager DataManager { get; set; } + + private List<Album> albums; + + public IEnumerable<Album> Albums + { + get + { + return new List<Album>(albums); + } + } + + private List<CustomTitle> customTitles; + + public IEnumerable<CustomTitle> CustomTitles + { + get + { + return new List<CustomTitle>(customTitles); + } + } + + private List<InfoTitle> infoTitles; + + public IEnumerable<InfoTitle> InfoTitles + { + get + { + return new List<InfoTitle>(infoTitles); + } + } + + private List<Playlist> playlists; + + public IEnumerable<Playlist> Playlists + { + get + { + return new List<Playlist>(playlists); + } + } + + private List<Artist> artists; + + public IEnumerable<Artist> Artists + { + get + { + return new List<Artist>(artists); + } + } + + public Manager(IDataManager dataManager) + { + DataManager = dataManager; + + albums = DataManager.GetAlbums(); + customTitles = DataManager.GetCustomTitles(); + infoTitles = DataManager.GetInfoTitles(); + playlists = DataManager.GetPlaylists(); + artists = DataManager.GetArtists(); + } + + public void AddAlbum(Album album) + { + DataManager.AddAlbum(album); + albums = DataManager.GetAlbums(); + } + + public void AddCustomTitle(CustomTitle title) + { + 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); + playlists = DataManager.GetPlaylists(); + } + + public void AddArtist(Artist artist) + { + DataManager.AddArtist(artist); + artists = DataManager.GetArtists(); + } + + public void RemoveAlbum(Album album) + { + DataManager.RemoveAlbum(album); + albums = DataManager.GetAlbums(); + } + + public void RemoveCustomTitle(CustomTitle title) + { + DataManager.RemoveCustomTitle(title); + customTitles = DataManager.GetCustomTitles(); + } + + public void RemoveInfoTitle(InfoTitle title) + { + DataManager.RemoveInfoTitle(title); + infoTitles = DataManager.GetInfoTitles(); + } + + public void RemovePlaylist(Playlist playlist) + { + DataManager.RemovePlaylist(playlist); + playlists = DataManager.GetPlaylists(); + } + + public IEnumerable<Playlist> GetPlaylists() + { + return DataManager.GetPlaylists(); + } + + public IEnumerable<Album> GetAlbums() + { + return DataManager.GetAlbums(); + } + + public IEnumerable<CustomTitle> GetCustomTitles() + { + return DataManager.GetCustomTitles(); + } + + public IEnumerable<InfoTitle> GetInfoTitles() + { + return DataManager.GetInfoTitles(); + } + + public IEnumerable<Artist> GetArtists() + { + return DataManager.GetArtists(); + } + + public void LoadSerialization() + { + DataManager.LoadSerialization(); + } + + public void SaveSerialization() + { + DataManager.SaveSerialization(); + } + +} 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..a1d5727 100644 --- a/Sources/Model/Playlist.cs +++ b/Sources/Model/Playlist.cs @@ -1,35 +1,214 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Model.Stub; +using System.Security.Cryptography; +using System.Xml.Serialization; -namespace Model +namespace Model; + +public class Playlist { - public class Playlist + public string Name + { + get => name; + + set + { + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) + { + name = value; + } + } + } + + private string name = Manager.DEFAULT_NAME; + + public string Description + { + get => description; + + set + { + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) + { + description = value; + } + } + } + + private string description = Manager.DEFAULT_DESC; + + public IEnumerable<Title> Titles + { + get + { + return titles; + } + } + + private readonly List<Title> titles = new List<Title>(); + + public string ImageURL + { + get => imageURL; + + set + { + 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 = Manager.DEFAULT_URL; + + public int Index + { + get => index; + + set + { + if (value < titles.Count) + { + index = value; + } + else if(Loop) + { + index = 0; + } + } + } + + private int index = 0; + + public bool Shuffle { get; set; } = false; + + public bool Loop { get; set; } = false; + + public bool LoopTitle { get; set; } = false; + + private readonly List<int> played = new List<int>(); + + public IEnumerable<int> Played + { + get + { + return new List<int>(played); + } + } + + public Playlist(string nom, string description, string imageURL) { - public string Nom { get; set; } + Name = nom; + Description = description; + ImageURL = imageURL; + } - public string Description { get; set; } + public Playlist() + { - public IEnumerable<Morceau> Morceaux { get; set; } + } - public Playlist(string nom, string description) + public void AddTitle(CustomTitle morceau) + { + titles.Add(morceau); + } + + public void RemoveTitle(CustomTitle morceau) + { + titles.Remove(morceau); + } + + public void NextTitle() + { + if (LoopTitle) { - Nom = nom; - Description = description; - Morceaux = new List<Morceau>(); + return; } - public void addMorceau(Morceau morceau) + if (!Shuffle) { - Morceaux.Prepend(morceau); + Index++; + played.Add(Index); } + else + { + Index = RandomGenerator(titles.Count); + played.Add(Index); + } + } - public void removeMorceau(Morceau morceau) + public void PreviousTitle() + { + if (LoopTitle) { - Morceaux.ToList().Remove(morceau); + return; } + if(!Shuffle) + { + if(Index != 0) + { + Index--; + played.RemoveAt(played.Count - 1); + } + } + else + { + if (!played.Any()) + { + return; + } + Index = played[played.Count - 1]; + played.RemoveAt(played.Count - 1); + } + } + + public Title? GetCurrentTitle() + { + if (Index < titles.Count) + { + return titles[Index]; + } + else + { + return null; + } + + } + + 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}"; + } + + static 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/Serialization/LINQ_XML_Serialization.cs b/Sources/Model/Serialization/LINQ_XML_Serialization.cs new file mode 100644 index 0000000..63b9261 --- /dev/null +++ b/Sources/Model/Serialization/LINQ_XML_Serialization.cs @@ -0,0 +1,1006 @@ +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; +using System.IO; + +namespace Model.Serialization; + +public class LinqXmlSerialization : IDataManager +{ + private static string XMLPATH = Path.Combine(Environment.CurrentDirectory, "Data"); + + private static string XMLFILEPLAYLISTS = Path.Combine(XMLPATH, "playlists.xml"); + + private static string XMLFILEALBUMS = Path.Combine(XMLPATH, "albums.xml"); + + private static string XMLFILECUSTOMS = Path.Combine(XMLPATH, "customs.xml"); + + private static string XMLFILEINFOS = Path.Combine(XMLPATH, "infos.xml"); + + private static string XMLFILEARTISTS = Path.Combine(XMLPATH, "artists.xml"); + + private List<Artist> artists; + + public IEnumerable<Artist> Artists + { + get + { + return new List<Artist>(artists); + } + } + + private List<Album> albums; + + public IEnumerable<Album> Albums + { + get + { + return new List<Album>(albums); + } + } + + private List<Playlist> playlists; + + public IEnumerable<Playlist> Playlists + { + get + { + return new List<Playlist>(playlists); + } + } + + private List<InfoTitle> infoTitles; + + public IEnumerable<InfoTitle> InfoTitles + { + get + { + return new List<InfoTitle>(infoTitles); + } + } + + private List<CustomTitle> customTitles; + + public IEnumerable<CustomTitle> CustomTitles + { + get + { + return new List<CustomTitle>(customTitles); + } + } + + public LinqXmlSerialization() + { + playlists = new List<Playlist>(); + artists = new List<Artist>(); + albums = new List<Album>(); + infoTitles = new List<InfoTitle>(); + customTitles = new List<CustomTitle>(); + if (!Directory.Exists(XMLPATH)) + { + Directory.CreateDirectory(XMLPATH); + } + Directory.SetCurrentDirectory(XMLPATH); + 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(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.Titles.Any() ? p.Titles.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(XMLFILEPLAYLISTS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + { + PlaylistFile.Save(writer); + } + } + } + XDocument PlaylistsFichier = XDocument.Load(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() + { + 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.Titles.Any() ? playlist.Titles.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() + { + if (!File.Exists(XMLFILEARTISTS)) + { + XDocument ArtistFile = new XDocument(); + Artist a1 = new Artist("a1"); + Artist a2 = new Artist("a2"); + + artists.Add(a1); + artists.Add(a2); + + var artist = artists.Select(artist => new XElement("Artist", + new XAttribute("Name", artist.Name) + )); + + ArtistFile.Add(new XElement("Artists", artist)); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + using (TextWriter tw = File.CreateText(XMLFILEARTISTS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + { + ArtistFile.Save(writer); + } + } + } + + XDocument ArtistsFile = XDocument.Load(XMLFILEARTISTS); + artists = ArtistsFile.Descendants("Artist") + .Select(eltArtist => new Artist( + eltArtist.Attribute("Name")!.Value + )).ToList(); + + } + + public void SaveArtists() + { + XDocument ArtistsFile = new XDocument(); + var artist = artists.Select(artist => new XElement("Artist", + new XAttribute("Name", artist.Name) + )); + + ArtistsFile.Add(new XElement("Artists", artist)); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + + using (TextWriter tw = File.CreateText(XMLFILEARTISTS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + { + ArtistsFile.Save(writer); + } + } + + } + + public void LoadCustomTitles() + { + if (!File.Exists(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(XMLFILECUSTOMS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + + CustomsFile2.Save(writer); + } + } + XDocument CustomsFile = XDocument.Load(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() + { + 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(XMLFILEALBUMS)) + { + XDocument AlbumFile = new XDocument(); + Album a1 = new Album(); + albums.Add(a1); + + var album = albums.Select(p => new XElement("Album", + new XAttribute("Name", p.Name), + new XElement("ImageURL", p.ImageURL), + new XElement("Artist", p.Titles.Any() ? p.Titles.Select(a => a.Name).Aggregate((artistName, nextArtist) => artistName + " " + nextArtist) : ""), + new XElement("Description", p.Description), + new XElement("Information", p.Information), + new XElement("Titles", p.Titles.Any() ? p.Titles.Select(a => a.ImageURL).Aggregate((albumUrl, nextAlbum) => albumUrl + " " + nextAlbum) : "") + )); + + AlbumFile.Add(new XElement("Albums", album)); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + using (TextWriter tw = File.CreateText(XMLFILEALBUMS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + { + AlbumFile.Save(writer); + } + } + } + XDocument AlbumsFile = XDocument.Load(XMLFILEALBUMS); + + albums = AlbumsFile.Descendants("Album") + .Select(eltPlaylist => new Album( + eltPlaylist.Attribute("Name")!.Value, + eltPlaylist.Element("ImageURL")!.Value, + GetArtistByName(eltPlaylist.Element("Artist")!.Value) ?? new Artist(), + eltPlaylist.Element("Description")!.Value, + eltPlaylist.Element("Information")!.Value + )).ToList(); + + + + 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() + { + XDocument AlbumsFile = new XDocument(); + + var album = albums.Select(a => new XElement("Album", + new XAttribute("Name", a.Name), + new XElement("ImageURL", a.ImageURL), + new XElement("Artist", a.Artist.Name), + new XElement("Description", a.Description), + new XElement("Information", a.Information), + new XElement("Titles", a.Titles.Any() ? a.Titles.Select(p => p.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(XMLFILEINFOS)) + { + XDocument InfoFile = new XDocument(); + InfoTitle it1 = new InfoTitle(); + infoTitles.Add(it1); + + var infoTitle = infoTitles.Select(p => new XElement("InfoTitle", + new XAttribute("Name", p.Name), + new XElement("ImageURL", p.ImageURL), + new XElement("Information", p.Information), + new XElement("Feats", p.Feat.Any() ? p.Feat.Select(a => a.Name).Aggregate((artistName, nextArtist) => artistName + " " + nextArtist) : ""), + new XElement("Description", p.Description), + new XElement("Genre", p.Genre) + )); + + InfoFile.Add(new XElement("InfoTitles", infoTitle)); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + using (TextWriter tw = File.CreateText(XMLFILEINFOS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + { + InfoFile.Save(writer); + } + } + } + XDocument InfosFile = XDocument.Load(XMLFILEINFOS); + + 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) ?? new Artist(), + 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() + { + XDocument InfosFile = new XDocument(); + + var info = infoTitles.Select(it => new XElement("InfoTitle", + new XAttribute("Name", it.Name), + new XElement("ImageURL", it.ImageURL), + new XElement("Information", it.Information), + new XElement("Genre", it.Genre.ToString()), + new XElement("Description", it.Description), + new XElement("Feats", it.Feat.Any() ? it.Feat.Select(p => p.Name).Aggregate((featName, nextFeat) => featName + " " + nextFeat) : "") + )); + InfosFile.Add(new XElement("InfoTitles", info)); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Indent = true; + + using (TextWriter tw = File.CreateText(XMLFILEINFOS)) + { + using (XmlWriter writer = XmlWriter.Create(tw, settings)) + { + InfosFile.Save(writer); + } + } + } + public static 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 url) + { + foreach(InfoTitle it in infoTitles) + { + if (it.Name == url) + { + return it; + } + } + return null; + } + + public Artist? GetArtistByName(string name) + { + foreach(Artist a in artists) + { + if (a.Name == name) + { + return a; + } + } + return null; + } + + public Album? GetAlbumByUrl(string url) + { + foreach(Album a in albums) + { + if (a.ImageURL == url) + { + return a; + } + } + return null; + } + + public CustomTitle? GetCustomTitleByUrl(string custom) + { + foreach(CustomTitle customTitle in customTitles) + { + if(customTitle.Name == custom) + { + return customTitle; + } + } + 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); + } + } + + 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/StubAlbum.cs b/Sources/Model/Stub/StubAlbum.cs new file mode 100644 index 0000000..3de4e1a --- /dev/null +++ b/Sources/Model/Stub/StubAlbum.cs @@ -0,0 +1,61 @@ +using System.Linq; + +namespace Model.Stub; + +public class StubAlbum +{ + public StubArtist StubArtist + { + get + { + return stubArtist; + } + } + + private readonly StubArtist stubArtist; + + public List<Album> Albums + { + get => albums; + } + + private readonly List<Album> albums; + + public StubAlbum() + { + stubArtist = new StubArtist(); + + 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 + }; + } + + 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 new file mode 100644 index 0000000..04b445b --- /dev/null +++ b/Sources/Model/Stub/StubArtist.cs @@ -0,0 +1,48 @@ +namespace Model.Stub; + +public class StubArtist +{ + public List<Artist> Artists + { + get => artists; + } + + private readonly 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"); + + artists = new List<Artist>() + { + Artiste1, Artiste2, Artiste3, Artiste4 + }; + } + + public List<Artist> GetArtists() + { + 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 new file mode 100644 index 0000000..2886a0b --- /dev/null +++ b/Sources/Model/Stub/StubCustomTitle.cs @@ -0,0 +1,51 @@ +namespace Model.Stub; + +public class StubCustomTitle +{ + + public List<CustomTitle> CustomTitles + { + get => customTitles; + } + + private readonly 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; + } + 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 new file mode 100644 index 0000000..3ee4cf2 --- /dev/null +++ b/Sources/Model/Stub/StubInfoTitle.cs @@ -0,0 +1,71 @@ +namespace Model.Stub; + +public class StubInfoTitle +{ + + public StubArtist StubArtist + { + get + { + return stubArtist; + } + } + + private readonly StubArtist stubArtist; + + public List<InfoTitle> InfoTitles + { + get => infoTitles; + } + + private readonly List<InfoTitle> infoTitles; + + public StubInfoTitle() + { + stubArtist = new StubArtist(); + + 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>() + { + 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 static void AddFeat(InfoTitle infoTitle, Artist artist) + { + infoTitle.AddFeat(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 new file mode 100644 index 0000000..ceb463f --- /dev/null +++ b/Sources/Model/Stub/StubManager.cs @@ -0,0 +1,557 @@ +namespace Model.Stub; + +public class StubManager : IDataManager +{ + // Stubs + + public StubAlbum StubAlbum + { + get + { + return stubAlbum; + } + } + + private readonly StubAlbum stubAlbum; + + public StubArtist StubArtist + { + get + { + return stubArtist; + } + } + + private readonly StubArtist stubArtist; + + public StubCustomTitle StubCustomTitle + { + get + { + return stubCustomTitle; + } + } + + private readonly StubCustomTitle stubCustomTitle; + + public StubInfoTitle StubInfoTitle + { + get + { + return stubInfoTitle; + } + } + + private readonly StubInfoTitle stubInfoTitle; + + public StubPlaylist StubPlaylist + { + get + { + return stubPlaylist; + } + } + + private readonly StubPlaylist stubPlaylist; + + public StubManager() + { + stubAlbum = new StubAlbum(); + stubArtist = new StubArtist(); + stubCustomTitle = new StubCustomTitle(); + stubInfoTitle = new StubInfoTitle(); + stubPlaylist = new StubPlaylist(); + StubPlaylist.Playlists.First().AddTitle(StubCustomTitle.CustomTitles.First()); + } + + public List<Album> GetAlbums() + { + return StubAlbum.GetAlbums(); + } + + public List<Artist> GetArtists() + { + return StubArtist.GetArtists(); + } + + public List<Playlist> GetPlaylists() + { + return StubPlaylist.GetPlaylists(); + } + + public List<CustomTitle> GetCustomTitles() + { + return StubCustomTitle.GetCustomTitles(); + } + + public List<InfoTitle> GetInfoTitles() + { + return StubInfoTitle.GetInfoTitles(); + } + + public void AddAlbum(Album album) + { + StubAlbum.AddAlbum(album); + } + + public void AddCustomTitle(CustomTitle title) + { + StubCustomTitle.AddCustomTitle(title); + } + + public void AddInfoTitle(InfoTitle title) + { + StubInfoTitle.AddInfoTitle(title); + } + + public static void AddFeat(InfoTitle infoTitle, Artist artist) + { + StubInfoTitle.AddFeat(infoTitle, artist); + } + + public void AddPlaylist(Playlist playlist) + { + StubPlaylist.AddPlaylist(playlist); + } + + public void AddArtist(Artist artist) + { + StubArtist.AddArtist(artist); + } + + + + public void RemoveAlbum(Album album) + { + StubAlbum.RemoveAlbum(album); + } + + public void RemoveCustomTitle(CustomTitle title) + { + StubCustomTitle.RemoveCustomTitle(title); + } + + public void RemoveInfoTitle(InfoTitle title) + { + StubInfoTitle.RemoveInfoTitle(title); + } + + public void RemovePlaylist(Playlist playlist) + { + StubPlaylist.RemovePlaylist(playlist); + } + + public void RemoveArtist(Artist artist) + { + StubArtist.RemoveArtist(artist); + } + + 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) + { + foreach (CustomTitle customTitle in StubCustomTitle.GetCustomTitles()) + { + if (customTitle.Name == custom) + { + return customTitle; + } + } + 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); + } + } + + 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; + } +} diff --git a/Sources/Model/Stub/StubPlaylist.cs b/Sources/Model/Stub/StubPlaylist.cs new file mode 100644 index 0000000..681750d --- /dev/null +++ b/Sources/Model/Stub/StubPlaylist.cs @@ -0,0 +1,46 @@ +namespace Model.Stub; + +public class StubPlaylist +{ + + public List<Playlist> Playlists + { + get => playlists; + } + + private readonly 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; + } + 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 new file mode 100644 index 0000000..304eb89 --- /dev/null +++ b/Sources/Model/Title.cs @@ -0,0 +1,87 @@ +using Model.Stub; +using System.Xml.Serialization; + +namespace Model +{ + public class Title + { + public string Name + { + get => name; + + set + { + if (value != null && value.Length < Manager.MAX_NAME_LENGTH) + { + name = value; + } + } + } + + private string name = Manager.DEFAULT_NAME; + + public string ImageURL + { + get => imageURL; + + set + { + 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 = Manager.DEFAULT_URL; + + public string Information + { + get => information; + + set + { + if (value != null && value.Length < Manager.MAX_DESCRIPTION_LENGTH) + { + information = value; + } + } + } + + private string information = Manager.DEFAULT_DESC; + + public Title(string nom, string file_Name, string informations) + { + Name = nom; + ImageURL = file_Name; + 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}"; + } + } +} diff --git a/Sources/TestUnitaires/TU_Album.cs b/Sources/TestUnitaires/TU_Album.cs new file mode 100644 index 0000000..17a172f --- /dev/null +++ b/Sources/TestUnitaires/TU_Album.cs @@ -0,0 +1,46 @@ +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) + { + Album album = new Album(nameAlbum, url, new Artist("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); + } + + [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 Artist("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_Artiste.cs b/Sources/TestUnitaires/TU_Artiste.cs new file mode 100644 index 0000000..6f6c19e --- /dev/null +++ b/Sources/TestUnitaires/TU_Artiste.cs @@ -0,0 +1,21 @@ +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) + { + Artist a = new Artist(name); + Assert.True(a.Name != null && a.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..5599ad1 --- /dev/null +++ b/Sources/TestUnitaires/TU_CustomTitle.cs @@ -0,0 +1,31 @@ +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_InfoTitle.cs b/Sources/TestUnitaires/TU_InfoTitle.cs new file mode 100644 index 0000000..8463810 --- /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 Artist("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 Artist("test"), desc, g); + Artist a = new Artist("Lahuiss"); + it.AddFeat(a); + Assert.Contains(a, it.Feat); + it.RemoveFeat(a); + Assert.DoesNotContain(a, it.Feat); + } + } + +} \ No newline at end of file diff --git a/Sources/TestUnitaires/TU_Manager.cs b/Sources/TestUnitaires/TU_Manager.cs new file mode 100644 index 0000000..026112e --- /dev/null +++ b/Sources/TestUnitaires/TU_Manager.cs @@ -0,0 +1,38 @@ +using Model; +using Model.Serialization; +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) + { + 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"); + Manager m = new Manager(DataManager); + m.AddCustomTitle(t); + m.AddPlaylist(p); + m.AddAlbum(album); + Assert.Contains(t, m.CustomTitles); + Assert.Contains(album, m.Albums); + Assert.Contains(p, m.Playlists); + m.RemovePlaylist(p); + m.RemoveAlbum(album); + m.RemoveCustomTitle(t); + Assert.DoesNotContain(t, m.CustomTitles); + Assert.DoesNotContain(p, m.Playlists); + Assert.DoesNotContain(album, m.Albums); + } + } + +} \ 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..ff8219e --- /dev/null +++ b/Sources/TestUnitaires/TU_Playlist.cs @@ -0,0 +1,45 @@ +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) + { + 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); + } + [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); + CustomTitle t = new CustomTitle("Débitage","test. mp3","Banger","path"); + p.AddTitle(t); + Assert.Contains(t,p.Titles); + p.RemoveTitle(t); + Assert.DoesNotContain(t,p.Titles); + + + } + } + +} \ 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..c22de93 --- /dev/null +++ b/Sources/TestUnitaires/TU_Title.cs @@ -0,0 +1,27 @@ +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) + { + 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); + } + } + +} \ 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