Problème de persistance mit en pose car c'est le sujet du prochain cour et donc on peut rien faire pour l'instant
continuous-integration/drone/push Build is failing Details

pull/32/head
Yannis DOUMIR FERNANDES 2 years ago
parent 9cef034006
commit af5237bb4c

@ -11,7 +11,6 @@ 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;

@ -105,7 +105,7 @@ namespace Model
monstresDejaVu = monstresVus;
}
/*
public User()
{
Pseudo = null;
@ -114,7 +114,7 @@ namespace Model
Mdp = null;
monstresDejaVu = null;
}
*/
public bool verifyPssw(string pssw)
{

@ -14,23 +14,41 @@ using System.Dynamic;
using System.Xml.Linq;
namespace Persistance
{
public class LoaderXml : IUserDataManager, IMonsterDataManager
{/// <summary>
/// Le problème vient du GetCurrentDirectory, le prof à dit que c'était le sujet du prochain cour donc je mets ça en pose.
/// Chelou que ça marchait avant et je suis pas le seul à qui sa fait ça
/// Avant il me mettait dans les fichiers du projet mais plus maintenant
/// EN POSE
/// </summary>
public class LoaderXml : IUserDataManager, IMonsterDataManager
{
static string path = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../../"));
static string path = "/Saves/";
static string fichierUserXML = "users.xml";
static string fichierMonstreXML = "monsters.xml";
/*static string path = "/Saves/";
//static string path = Directory.GetCurrentDirectory() + "/../../";
static string fichierUserXML = "users.xml";
static string fichierMonstreXML = "monsters.xml";
*/
bool exists = System.IO.Directory.Exists(Path.Combine(path, "/Saves/"));
// Serialisation / Deserialisation de Monstres
public void Chargement()
{
if (!exists)
{
Directory.CreateDirectory(path + "/Saves/");
}
}
void IMonsterDataManager.saveMonsters(List<Monstre> monstres)
{
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory())); // Setup le chemin d'accès
//Chargement();
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(Path.Combine(path, fichierMonstreXML)))
using (TextWriter tw = File.CreateText(Path.Combine(fichierMonstreXML)))
{
using (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
{
@ -40,11 +58,13 @@ namespace Persistance
}
public List<Monstre> loadMonsters()
{
//Chargement();
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
var serialiserXML = new DataContractSerializer(typeof(List<Monstre>));
List<Monstre>? monsters;
try
{
using (Stream s = File.OpenRead(Path.Combine(path, fichierMonstreXML)))
using (Stream s = File.OpenRead(fichierMonstreXML))
{
monsters = serialiserXML.ReadObject(s) as List<Monstre>;
}
@ -56,11 +76,29 @@ namespace Persistance
return new List<Monstre> { };
}
// Serialisation / Deserialisation de Users
void IUserDataManager.saveUsers(List<User> users)// Serialise correctement juste voir comment l'appelé en fonction de IUserDataManager
{
//Chargement();
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path)); // Setup le chemin d'accès
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 (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
{
serialiserXML.WriteObject(writer, users);
}
}
}
public List<User> loadUsers()
{
Chargement();
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
var serialiserXML = new DataContractSerializer(typeof(List<User>));
List<User>? users;
using (Stream s = File.OpenRead(Path.Combine(path, fichierUserXML)))
using (Stream s = File.OpenRead(fichierUserXML))
{
users = serialiserXML.ReadObject(s) as List<User>;
}
@ -70,24 +108,5 @@ namespace Persistance
}
return users;
}
void IUserDataManager.saveUsers(List<User> users)// Serialise correctement juste voir comment l'appelé en fonction de IUserDataManager
{
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("users.xml"))
{
using (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
{
serialiserXML.WriteObject(writer, users);
}
}
}
}
}

@ -6,8 +6,8 @@ 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()
public User user { get; set; } = new User();
public Inscription()
{
InitializeComponent();
BindingContext=user;
@ -19,5 +19,5 @@ public partial class Inscription : ContentPage
userMngr.saveUsers(users);
}
*/
}
Loading…
Cancel
Save