From 0b30a356cbd22acc8a657fba07df7387dd027f0b Mon Sep 17 00:00:00 2001 From: thchazot1 Date: Tue, 17 May 2022 16:51:04 +0200 Subject: [PATCH] Manager + PersistanceManager + stub --- Modèle/Requin.cs | 20 +++++++++----- Persistance/IPersistanceManager.cs | 14 ++++++++++ Persistance/Manager.cs | 43 ++++++++++++++++++++++++++++++ Persistance/Persistance.csproj | 11 ++++++++ StubLib/Stub.cs | 25 +++++++++++++++++ StubLib/StubLib.csproj | 12 +++++++++ WpfApp1.sln | 15 +++++++++++ WpfApp1/MainWindow.xaml | 2 +- WpfApp1/MainWindow.xaml.cs | 2 +- 9 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 Persistance/IPersistanceManager.cs create mode 100644 Persistance/Manager.cs create mode 100644 Persistance/Persistance.csproj create mode 100644 StubLib/Stub.cs create mode 100644 StubLib/StubLib.csproj diff --git a/Modèle/Requin.cs b/Modèle/Requin.cs index a6bcb13..e9d224a 100644 --- a/Modèle/Requin.cs +++ b/Modèle/Requin.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Modèle { - public class Requin + public class Requin : IEquatable { public string Nom { get; private set; } public string NomSci { get; private set; } @@ -89,13 +89,21 @@ namespace Modèle public bool Equals(Requin r) { - if (Nom==r.Nom && NomSci == r.NomSci) - { - return true; - } - return false; + return r.Nom == Nom && r.NomSci == NomSci; } + public override bool Equals(object obj) + { + if (ReferenceEquals(obj, null)) return false; + if (ReferenceEquals(obj, this)) return true; + if (GetType() != obj.GetType()) return false; + return Equals(obj as Requin); + } + + public override int GetHashCode() + { + return Nom.GetHashCode() ^ NomSci.GetHashCode(); + } } } diff --git a/Persistance/IPersistanceManager.cs b/Persistance/IPersistanceManager.cs new file mode 100644 index 0000000..cec430d --- /dev/null +++ b/Persistance/IPersistanceManager.cs @@ -0,0 +1,14 @@ +using Modèle; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Persistance +{ + public interface IPersistanceManager + { + IEnumerable LoadRequins(); + } +} \ No newline at end of file diff --git a/Persistance/Manager.cs b/Persistance/Manager.cs new file mode 100644 index 0000000..ae9b7a5 --- /dev/null +++ b/Persistance/Manager.cs @@ -0,0 +1,43 @@ +using Modèle; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Persistance +{ + class Manager + { + public ReadOnlyCollection Requins { get; private set; } + private List requins = new List(); + public Requin SelectedRequin { get; set; } + + /// + /// DéPENDANCE + /// + public IPersistanceManager Pers { get; private set; } + + /// + /// constructeur avec INJECTION DE LA DéPENDANCE + /// + + public Manager(IPersistanceManager pers) + { + Requins = new ReadOnlyCollection(requins); + Pers = pers; + } + public void LoadRequins() + { + requins.Clear(); + requins.AddRange(Pers.LoadRequins()); + if (requins.Count > 0) + SelectedRequin = requins.First(); + } + + public void SaveRequins() { } + + + } +} \ No newline at end of file diff --git a/Persistance/Persistance.csproj b/Persistance/Persistance.csproj new file mode 100644 index 0000000..f32fd43 --- /dev/null +++ b/Persistance/Persistance.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/StubLib/Stub.cs b/StubLib/Stub.cs new file mode 100644 index 0000000..2416348 --- /dev/null +++ b/StubLib/Stub.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using Modèle; +using Persistance; + +namespace StubLib +{ + public class Stub : IPersistanceManager + { + + List requins = new List(); + + public Stub() + { + List zone = new List { Zone.ATLANTIQUE }; + requins.Add(new Requin("mon requin adoré", "trop cool ce requin", "wow il est trop bo", "Quelle belle photo", "cette vidéo le met si bien en valeur", "oh bah il est nul part", Conservation.EW, zone, "(C'est pas un vrai requin)")); + requins.Add(new Requin("Banane", "Le requin banal", "C'est un requin ultra banal", "Quelle photo banale", "cette vidéo le met si bien en valeur", "oh bah il est nul part", Conservation.LC, zone, "Il est pas aussi banal qu'il en a l'air")); + } + + public IEnumerable LoadRequins() + { + return requins; + } + } +} diff --git a/StubLib/StubLib.csproj b/StubLib/StubLib.csproj new file mode 100644 index 0000000..305dd18 --- /dev/null +++ b/StubLib/StubLib.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/WpfApp1.sln b/WpfApp1.sln index fd9d713..6552911 100644 --- a/WpfApp1.sln +++ b/WpfApp1.sln @@ -20,6 +20,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{18E1E85C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test_requin", "test_requin\test_requin.csproj", "{D82F546C-3455-4857-A705-BDD3F61973CD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubLib", "StubLib\StubLib.csproj", "{3DE43637-4ADE-420B-A78E-BD5A01B7E930}" + ProjectSection(ProjectDependencies) = postProject + {A3496A97-FA54-4FA9-A128-4B0D97D8F7EF} = {A3496A97-FA54-4FA9-A128-4B0D97D8F7EF} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistance", "Persistance\Persistance.csproj", "{A3496A97-FA54-4FA9-A128-4B0D97D8F7EF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -46,6 +53,14 @@ Global {D82F546C-3455-4857-A705-BDD3F61973CD}.Debug|Any CPU.Build.0 = Debug|Any CPU {D82F546C-3455-4857-A705-BDD3F61973CD}.Release|Any CPU.ActiveCfg = Release|Any CPU {D82F546C-3455-4857-A705-BDD3F61973CD}.Release|Any CPU.Build.0 = Release|Any CPU + {3DE43637-4ADE-420B-A78E-BD5A01B7E930}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DE43637-4ADE-420B-A78E-BD5A01B7E930}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DE43637-4ADE-420B-A78E-BD5A01B7E930}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DE43637-4ADE-420B-A78E-BD5A01B7E930}.Release|Any CPU.Build.0 = Release|Any CPU + {A3496A97-FA54-4FA9-A128-4B0D97D8F7EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3496A97-FA54-4FA9-A128-4B0D97D8F7EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3496A97-FA54-4FA9-A128-4B0D97D8F7EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3496A97-FA54-4FA9-A128-4B0D97D8F7EF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WpfApp1/MainWindow.xaml b/WpfApp1/MainWindow.xaml index 488248f..e279091 100644 --- a/WpfApp1/MainWindow.xaml +++ b/WpfApp1/MainWindow.xaml @@ -24,7 +24,7 @@ - + diff --git a/WpfApp1/MainWindow.xaml.cs b/WpfApp1/MainWindow.xaml.cs index ce242e5..c0ab217 100644 --- a/WpfApp1/MainWindow.xaml.cs +++ b/WpfApp1/MainWindow.xaml.cs @@ -26,7 +26,7 @@ namespace WpfApp1 InitializeComponent(); List zones = new List { Zone.ATLANTIQUE, Zone.ARCTIQUE }; uc1.requin = new Requin("Bob le bricoleur", "Heterodontus Mexicanus", "*Ronflements*", "Images/Dormeur-Mexicain.jpg", "Videos/Vid-dormeur-Mexicain.mp4", "Images/rep_Heterodontus_mexicanus.png", Conservation.DD, zones, "Hé laissez moi je fais dodo!"); - uc2.requin = new Requin("Requin Dormeur Mexdzdqzdicain", "Heterodontus Mexicanus", "*Ronflements*", "Images/Dormeur-Mexicain.jpg", "Videos/Vid-dormeur-Mexicain.mp4", "Images/rep_Heterodontus_mexicanus.png", Conservation.DD, zones, "Hé laissez moi je fais dodo!"); + // uc2.requin = new Requin("Requin Dormeur Mexdzdqzdicain", "Heterodontus Mexicanus", "*Ronflements*", "Images/Dormeur-Mexicain.jpg", "Videos/Vid-dormeur-Mexicain.mp4", "Images/rep_Heterodontus_mexicanus.png", Conservation.DD, zones, "Hé laissez moi je fais dodo!"); }