|
|
|
@ -1,12 +1,205 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
internal class XML_Serializer
|
|
|
|
|
public class XML_Serializer : IDataManager
|
|
|
|
|
{
|
|
|
|
|
public XML_Serializer()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPersonnage(List<Personnage> listePerso)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Personnage>));
|
|
|
|
|
string xmlFile = "personnage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serializer.WriteObject(writer, listePerso);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void SetFDD(List<FruitDuDemon> listeFDD)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<FruitDuDemon>));
|
|
|
|
|
string xmlFile = "fruitdudemon.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serializer.WriteObject(writer, listeFDD);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetBestiaire(List<Bestiaire> listeBest)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bestiaire>));
|
|
|
|
|
string xmlFile = "bestiaire.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serializer.WriteObject(writer, listeBest);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetEquipage(List<Equipage> listeEquip)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Equipage>));
|
|
|
|
|
string xmlFile = "equipage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serializer.WriteObject(writer, listeEquip);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetIle(List<Ile> listeIle)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Ile>));
|
|
|
|
|
string xmlFile = "ile.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serializer.WriteObject(writer, listeIle);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetBateau(List<Bateau> listeBateau)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bateau>));
|
|
|
|
|
string xmlFile = "bateau.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
serializer.WriteObject(writer, listeBateau);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Bateau> GetBateaux()
|
|
|
|
|
{
|
|
|
|
|
List<Bateau> listeBateau = new List<Bateau>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bateau>));
|
|
|
|
|
string xmlFile = "bateau.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
listeBateau = serializer.ReadObject(s) as List<Bateau>;
|
|
|
|
|
}
|
|
|
|
|
return listeBateau;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Bestiaire> GetBestiaires()
|
|
|
|
|
{
|
|
|
|
|
List<Bestiaire> listeBest = new List<Bestiaire>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bestiaire>));
|
|
|
|
|
string xmlFile = "bestiaire.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
listeBest = serializer.ReadObject(s) as List<Bestiaire>;
|
|
|
|
|
}
|
|
|
|
|
return listeBest;
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Equipage> GetEquipages()
|
|
|
|
|
{
|
|
|
|
|
List<Equipage> listeEquip = new List<Equipage>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Equipage>));
|
|
|
|
|
string xmlFile = "equipage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
listeEquip = serializer.ReadObject(s) as List<Equipage>;
|
|
|
|
|
}
|
|
|
|
|
return listeEquip;
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<FruitDuDemon> GetFruits()
|
|
|
|
|
{
|
|
|
|
|
List<FruitDuDemon> listeFDD = new List<FruitDuDemon>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<FruitDuDemon>));
|
|
|
|
|
string xmlFile = "fruitdudemon.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
listeFDD = serializer.ReadObject(s) as List<FruitDuDemon>;
|
|
|
|
|
}
|
|
|
|
|
return listeFDD;
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Ile> GetIles()
|
|
|
|
|
{
|
|
|
|
|
List<Ile> listeIle = new List<Ile>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Ile>));
|
|
|
|
|
string xmlFile = "ile.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
listeIle = serializer.ReadObject(s) as List<Ile>;
|
|
|
|
|
}
|
|
|
|
|
return listeIle;
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Personnage> GetPersonnages()
|
|
|
|
|
{
|
|
|
|
|
List<Personnage> listePerso = new List<Personnage>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Personnage>));
|
|
|
|
|
string xmlFile = "personnage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|
listePerso = serializer.ReadObject(s) as List<Personnage>;
|
|
|
|
|
}
|
|
|
|
|
return listePerso;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|