|
|
|
@ -16,6 +16,7 @@ namespace Persistance
|
|
|
|
|
public class LoaderXML : IUserDataManager, IMonsterDataManager
|
|
|
|
|
{
|
|
|
|
|
static string fichierXML = "users.xml";
|
|
|
|
|
static string monstreXML = "monsters.xml";
|
|
|
|
|
/*
|
|
|
|
|
#region SauvegardeUser
|
|
|
|
|
public static void sauvegardeUserXML(List<User>) //Fonction de sauvegarde fonctionnelle si on enlève loadUsers car conflit en les deux
|
|
|
|
@ -72,7 +73,15 @@ namespace Persistance
|
|
|
|
|
}
|
|
|
|
|
List<Monstre> IMonsterDataManager.loadMonsters()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
#region Deserialisation
|
|
|
|
|
var serialiserXML = new DataContractSerializer(typeof(List<Monstre>));
|
|
|
|
|
List<Monstre> monsters;
|
|
|
|
|
using (Stream s = File.OpenRead(monstreXML))
|
|
|
|
|
{
|
|
|
|
|
monsters = serialiserXML.ReadObject(s) as List<Monstre>;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
return monsters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -80,18 +89,34 @@ namespace Persistance
|
|
|
|
|
/// CORECTION: à adapter en fonction de IUserDataManager mais sinon fonctionnelle
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IMonsterDataManager.saveMonsters(List<Monstre> monstres)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
#region Serialisation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "../../../../Persistance/saves/")); // Setup le chemin d'accès
|
|
|
|
|
var serialiserXML = new DataContractSerializer(typeof(List<Monstre>));
|
|
|
|
|
|
|
|
|
|
#region Serialisation
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings xmlSettings = new XmlWriterSettings() { Indent = true }; // Pour avoir le format xml dans le fichier ( indentation etc... )
|
|
|
|
|
using (TextWriter tw = File.CreateText(monstreXML))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, xmlSettings))
|
|
|
|
|
{
|
|
|
|
|
serialiserXML.WriteObject(writer, monstres);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IUserDataManager.saveUsers(List<User> users)// Serialise correctement juste voir comment l'appelé en fonction de IUserDataManager
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "../../../../Persistance/saves/")); // Setup le chemin d'accès
|
|
|
|
|
var serialiserXML = new DataContractSerializer(typeof(List<User>));
|
|
|
|
|
|
|
|
|
|
#region Serialisatin
|
|
|
|
|
#region Serialisation
|
|
|
|
|
|
|
|
|
|
XmlWriterSettings xmlSettings = new XmlWriterSettings() { Indent = true }; // Pour avoir le format xml dans le fichier ( indentation etc... )
|
|
|
|
|
using (TextWriter tw = File.CreateText(fichierXML))
|
|
|
|
|