|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System;
|
|
|
|
|
using Model.Stub;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
@ -12,16 +13,72 @@ namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
public class XML_Serializer : IDataManager
|
|
|
|
|
{
|
|
|
|
|
public string Chemin { get; set; }
|
|
|
|
|
public XML_Serializer()
|
|
|
|
|
{
|
|
|
|
|
StubManager stubManager = new StubManager();
|
|
|
|
|
Chemin = Directory.GetCurrentDirectory();
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./personnage.xml"))==false)
|
|
|
|
|
{
|
|
|
|
|
SetPersonnage(stubManager.GetPersonnages().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./bateau.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetBateau(stubManager.GetBateaux().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./fruitdudemon.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetFDD(stubManager.GetFruits().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./bestiaire.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetBestiaire(stubManager.GetBestiaires().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./equipage.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetEquipage(stubManager.GetEquipages().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./ile.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetIle(stubManager.GetIles().ToList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public XML_Serializer(string path)
|
|
|
|
|
{
|
|
|
|
|
Chemin= path;
|
|
|
|
|
StubManager stubManager = new StubManager();
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./personnage.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetPersonnage(stubManager.GetPersonnages().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./bateau.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetBateau(stubManager.GetBateaux().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./fruitdudemon.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetFDD(stubManager.GetFruits().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./bestiaire.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetBestiaire(stubManager.GetBestiaires().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./equipage.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetEquipage(stubManager.GetEquipages().ToList());
|
|
|
|
|
}
|
|
|
|
|
if (File.Exists(Path.Combine(Chemin, "./ile.xml")) == false)
|
|
|
|
|
{
|
|
|
|
|
SetIle(stubManager.GetIles().ToList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPersonnage(List<Personnage> listePerso)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Personnage>));
|
|
|
|
|
string xmlFile = "personnage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -38,7 +95,7 @@ namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<FruitDuDemon>));
|
|
|
|
|
string xmlFile = "fruitdudemon.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -56,7 +113,7 @@ namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bestiaire>));
|
|
|
|
|
string xmlFile = "bestiaire.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -74,7 +131,7 @@ namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Equipage>));
|
|
|
|
|
string xmlFile = "equipage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -92,7 +149,7 @@ namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Ile>));
|
|
|
|
|
string xmlFile = "ile.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -110,7 +167,7 @@ namespace Model.Serializer
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bateau>));
|
|
|
|
|
string xmlFile = "bateau.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -126,24 +183,26 @@ namespace Model.Serializer
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Bateau> GetBateaux()
|
|
|
|
|
{
|
|
|
|
|
List<Bateau> listeBateau = new List<Bateau>();
|
|
|
|
|
List<Bateau>? listeBateau = new List<Bateau>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bateau>));
|
|
|
|
|
string xmlFile = "bateau.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
List<Bestiaire>? listeBest = new List<Bestiaire>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Bestiaire>));
|
|
|
|
|
string xmlFile = "bestiaire.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -153,10 +212,10 @@ namespace Model.Serializer
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Equipage> GetEquipages()
|
|
|
|
|
{
|
|
|
|
|
List<Equipage> listeEquip = new List<Equipage>();
|
|
|
|
|
List<Equipage>? listeEquip = new List<Equipage>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Equipage>));
|
|
|
|
|
string xmlFile = "equipage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -166,10 +225,10 @@ namespace Model.Serializer
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<FruitDuDemon> GetFruits()
|
|
|
|
|
{
|
|
|
|
|
List<FruitDuDemon> listeFDD = new List<FruitDuDemon>();
|
|
|
|
|
List<FruitDuDemon>? listeFDD = new List<FruitDuDemon>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<FruitDuDemon>));
|
|
|
|
|
string xmlFile = "fruitdudemon.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -179,10 +238,10 @@ namespace Model.Serializer
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Ile> GetIles()
|
|
|
|
|
{
|
|
|
|
|
List<Ile> listeIle = new List<Ile>();
|
|
|
|
|
List<Ile>? listeIle = new List<Ile>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Ile>));
|
|
|
|
|
string xmlFile = "ile.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
@ -192,10 +251,10 @@ namespace Model.Serializer
|
|
|
|
|
}
|
|
|
|
|
public IEnumerable<Personnage> GetPersonnages()
|
|
|
|
|
{
|
|
|
|
|
List<Personnage> listePerso = new List<Personnage>();
|
|
|
|
|
List<Personnage>? listePerso = new List<Personnage>();
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(List<Personnage>));
|
|
|
|
|
string xmlFile = "personnage.xml";
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), "./"));
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Chemin, "./"));
|
|
|
|
|
|
|
|
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
|
|
|
{
|
|
|
|
|