Commencement du binding de la page connexion pour créé un user mais problème avec la serialisation à corriger avant ( problème de chemin )
continuous-integration/drone/push Build is failing Details

pull/32/head
Yannis DOUMIR FERNANDES 2 years ago
parent 891f53136c
commit 04d6a536a5

@ -11,6 +11,7 @@ using System.Reflection.PortableExecutable;
// Déclaration des Managers (et de leur méthode de sauvegarde)
UserManager userMngr = new UserManager(new LoaderXml());
MonsterManager monsterBase = new MonsterManager(new LoaderStub());
userMngr.addUser
// Variables statiques
bool isUserConnected = false;

@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Runtime.CompilerServices;
using Xunit;
namespace Model
@ -16,19 +18,63 @@ namespace Model
/// </summary>
[DataContract]
public class User
public class User : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName]string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
[DataMember(Order = 3)]
public string Pseudo { get; private set; }
public string Pseudo
{
get => Pseudo;
set
{
if (Pseudo == value)
return;
Pseudo = value;
OnPropertyChanged();
}
}
[DataMember(Order = 1)]
public string Nom { get; private set; }
public string Nom
{
get => Nom;
set
{
if (Nom == value)
return;
Nom = value;
OnPropertyChanged();
}
}
[DataMember(Order = 2)]
public string Prenom { get; private set; }
public string Prenom
{
get => Prenom;
set
{
if (Prenom == value)
return;
Prenom = value;
OnPropertyChanged();
}
}
[DataMember(Order = 4)]
private string Mdp { get; set; }
private string Mdp
{
get => Mdp;
set
{
if (Mdp == value)
return;
Mdp = value;
OnPropertyChanged();
}
}
[DataMember]
@ -59,6 +105,15 @@ namespace Model
Mdp = mdp;
monstresDejaVu = monstresVus;
}
public User()
{
Pseudo = null;
Nom = null;
Prenom = null;
Mdp = null;
monstresDejaVu = null;
}
public bool verifyPssw(string pssw)
{

@ -10,25 +10,41 @@ using System.IO;
using System.Collections.ObjectModel;
using static System.Net.Mime.MediaTypeNames;
using System.Runtime.CompilerServices;
using System.Dynamic;
using System.Xml.Linq;
namespace Persistance
{
public class LoaderXml : IUserDataManager, IMonsterDataManager
{
static string path = "../../../../Persistance/saves/";
static string path = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../../"));
//static string path = Directory.GetCurrentDirectory() + "/../../";
static string fichierUserXML = "users.xml";
static string fichierMonstreXML = "monsters.xml";
// Serialisation / Deserialisation de Monstres
void IMonsterDataManager.saveMonsters(List<Monstre> monstres)
{
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory())); // Setup le chemin d'accès
var serialiserXML = new DataContractSerializer(typeof(List<Monstre>));
XmlWriterSettings xmlSettings = new XmlWriterSettings() { Indent = true }; // Pour avoir le format xml dans le fichier ( indentation etc... )
using (TextWriter tw = File.CreateText(Path.Combine(path, fichierMonstreXML)))
{
using (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
{
serialiserXML.WriteObject(writer, monstres);
}
}
}
public List<Monstre> loadMonsters()
{
var serialiserXML = new DataContractSerializer(typeof(List<Monstre>));
List<Monstre>? monsters;
try
{
using (Stream s = File.OpenRead(fichierMonstreXML))
using (Stream s = File.OpenRead(Path.Combine(path, fichierMonstreXML)))
{
monsters = serialiserXML.ReadObject(s) as List<Monstre>;
}
@ -39,28 +55,12 @@ namespace Persistance
if (monsters != null) return monsters; // ça va faire un code smells
return new List<Monstre> { };
}
void IMonsterDataManager.saveMonsters(List<Monstre> monstres)
{
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path)); // Setup le chemin d'accès
var serialiserXML = new DataContractSerializer(typeof(List<Monstre>));
XmlWriterSettings xmlSettings = new XmlWriterSettings() { Indent = true }; // Pour avoir le format xml dans le fichier ( indentation etc... )
using (TextWriter tw = File.CreateText(fichierMonstreXML))
{
using (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
{
serialiserXML.WriteObject(writer, monstres);
}
}
}
// Serialisation / Deserialisation de Users
public List<User> loadUsers()
{
var serialiserXML = new DataContractSerializer(typeof(List<User>));
List<User>? users;
using (Stream s = File.OpenRead(path + fichierUserXML))
using (Stream s = File.OpenRead(Path.Combine(path, fichierUserXML)))
{
users = serialiserXML.ReadObject(s) as List<User>;
}
@ -73,11 +73,12 @@ namespace Persistance
void IUserDataManager.saveUsers(List<User> users)// Serialise correctement juste voir comment l'appelé en fonction de IUserDataManager
{
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
Directory.CreateDirectory("Saves");
Directory.SetCurrentDirectory(path);
var serialiserXML = new DataContractSerializer(typeof(List<User>));
XmlWriterSettings xmlSettings = new XmlWriterSettings() { Indent = true }; // Pour avoir le format xml dans le fichier ( indentation etc... )
using (TextWriter tw = File.CreateText(fichierUserXML))
using (TextWriter tw = File.CreateText("users.xml"))
{
using (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
{

@ -58,7 +58,8 @@
HeightRequest="70"
Margin="0, 0, 0, 30" />
<Entry Placeholder="Identifiant" />
<Entry Placeholder="Mot de passe" />
<Entry Placeholder="Mot de passe"
IsPassword="True"/>
<Button Style="{StaticResource buttonStyle}"
Text="Valider" />
</FlexLayout>

@ -57,11 +57,18 @@
Source="inscription.png"
HeightRequest="70"
Margin="0, 0, 0, 30" />
<Entry Placeholder="Nom"/>
<Entry Placeholder="Prénom" />
<Entry Placeholder="Identifiant" />
<Entry Placeholder="Mot de passe" />
<Button Style="{StaticResource buttonStyle}" Text="Valider" />
<Entry Placeholder="Nom"
Text="{Binding Nom}"/>
<Entry Placeholder="Prénom"
Text="{Binding Prenom}"/>
<Entry Placeholder="Identifiant"
Text="{Binding Pseudo}"/>
<Entry Placeholder="Mot de passe"
Text="{Binding Mdp}"
IsPassword="True"/>
<Button Style="{StaticResource buttonStyle}"
Text="Valider"
Clicked="Valid_Clicked"/>
</FlexLayout>
</toolkit:DockLayout>
</ContentPage>

@ -1,9 +1,23 @@
using Model;
using Persistance;
namespace Vues;
public partial class Inscription : ContentPage
{
List<User> users = new List<User>();
UserManager userMngr = new UserManager(new LoaderXml());
public User user { get; set; } = new User();
public Inscription()
{
InitializeComponent();
BindingContext=user;
}
private async void Valid_Clicked(object sender, EventArgs e)
{
users.Add(user);
userMngr.saveUsers(users);
}
}
Loading…
Cancel
Save