From a27d6123d276d1703b71cc410a2879a5794758de Mon Sep 17 00:00:00 2001 From: Clement LESME Date: Wed, 10 May 2023 15:04:10 +0200 Subject: [PATCH] push avant 'logo' du site* --- CanYouBuildIt/App.xaml.cs | 2 +- CanYouBuildIt/AppShell.xaml | 1 - .../DataContractPers.cs | 24 ++++++++++++++++- CanYouBuildIt/Model/Manager.cs | 3 ++- CanYouBuildIt/Model/Utilisateur.cs | 5 ++++ CanYouBuildIt/Views/Acceuil.xaml | 27 ++++++++++--------- CanYouBuildIt/Views/Favoris.xaml | 19 +++++++------ CanYouBuildIt/Views/Favoris.xaml.cs | 1 + 8 files changed, 56 insertions(+), 26 deletions(-) diff --git a/CanYouBuildIt/App.xaml.cs b/CanYouBuildIt/App.xaml.cs index 705b70a..1c5ec6c 100644 --- a/CanYouBuildIt/App.xaml.cs +++ b/CanYouBuildIt/App.xaml.cs @@ -9,7 +9,7 @@ public partial class App : Application { manager.chargeDonne(); manager.Persi = new DataContractPersistance.DataContractPers(); - manager.Persi.sauvegardeDonnee(manager.listUtil); + manager.sauvegardeDonnee(); InitializeComponent(); MainPage = new AppShell(); diff --git a/CanYouBuildIt/AppShell.xaml b/CanYouBuildIt/AppShell.xaml index 0df4354..5fa991f 100644 --- a/CanYouBuildIt/AppShell.xaml +++ b/CanYouBuildIt/AppShell.xaml @@ -7,7 +7,6 @@ xmlns:views="clr-namespace:CanYouBuildIt.Views" Shell.FlyoutBehavior="Disabled" Shell.NavBarIsVisible="False" - Title="CanYouRunIt" > diff --git a/CanYouBuildIt/DataContractPersistance/DataContractPers.cs b/CanYouBuildIt/DataContractPersistance/DataContractPers.cs index e4fabc3..4548dcc 100644 --- a/CanYouBuildIt/DataContractPersistance/DataContractPers.cs +++ b/CanYouBuildIt/DataContractPersistance/DataContractPers.cs @@ -10,18 +10,40 @@ namespace CanYouBuildIt.DataContractPersistance { public class DataContractPers : IPersistanceManager { + public string FilePath { get; set; } = Path.Combine(Directory.GetCurrentDirectory(),"\\Data"); + public string FileName { get; set; } = "UserData.xml"; + + public DataContractPers() { } public List chargeDonnee() { var serializer = new DataContractSerializer(typeof(Utilisateur)); + List lu = new List(); + + using (Stream stream = File.OpenRead(Path.Combine(FilePath, FileName))) + { + lu = serializer.ReadObject(stream) as List; + } return lu; } public bool sauvegardeDonnee(List lu) { - + DataContractSerializer serializer = new DataContractSerializer (typeof(Utilisateur)); + if (!Directory.Exists(FilePath)) + { + Directory.CreateDirectory(FilePath); + File.Create(Path.Combine(FilePath, FileName)); + } + else + { + using (Stream stream = File.OpenWrite(Path.Combine(FilePath, FileName))) + { + serializer.WriteObject(stream, lu); + } + } return true; } } diff --git a/CanYouBuildIt/Model/Manager.cs b/CanYouBuildIt/Model/Manager.cs index dc2c0cc..f2313b4 100644 --- a/CanYouBuildIt/Model/Manager.cs +++ b/CanYouBuildIt/Model/Manager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -10,7 +11,7 @@ namespace CanYouBuildIt.Model public class Manager { public List listUtil { get; private set; } - public IPersistanceManager Persi; + public IPersistanceManager Persi { get; set; } public Manager() { diff --git a/CanYouBuildIt/Model/Utilisateur.cs b/CanYouBuildIt/Model/Utilisateur.cs index dc26f36..a9c3d42 100644 --- a/CanYouBuildIt/Model/Utilisateur.cs +++ b/CanYouBuildIt/Model/Utilisateur.cs @@ -1,15 +1,20 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace CanYouBuildIt.Model { + [DataContract] public class Utilisateur { + [DataMember] public string username; + [DataMember] public string password; + [DataMember] public List listBuild; diff --git a/CanYouBuildIt/Views/Acceuil.xaml b/CanYouBuildIt/Views/Acceuil.xaml index d03ca90..fcf4307 100644 --- a/CanYouBuildIt/Views/Acceuil.xaml +++ b/CanYouBuildIt/Views/Acceuil.xaml @@ -21,19 +21,20 @@ - - - - @@ -61,9 +62,11 @@ + + -