|
|
|
@ -39,33 +39,35 @@ namespace MangaMap.Stub
|
|
|
|
|
return (data.Oeuvres, data.Utilisateurs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sauvegarder(List<Oeuvre> o, List<Utilisateur> u)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(DataToPersist));
|
|
|
|
|
|
|
|
|
|
if(!Directory.Exists(FilePath))
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Directory doesn't exist.");
|
|
|
|
|
Directory.CreateDirectory(FilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*using (Stream s = File.Create(Path.Combine(FilePath, FileName)))
|
|
|
|
|
{
|
|
|
|
|
serializer.WriteObject(s, o); //Version d'enregistrement des données sans indentation.
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
DataToPersist data = new DataToPersist();
|
|
|
|
|
data.Oeuvres = o;
|
|
|
|
|
data.Utilisateurs = u;
|
|
|
|
|
|
|
|
|
|
var settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName)))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter w = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
serializer.WriteObject(w, data); //Version d'enregistrement des données avec indentation.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void sauvegarder(List<Oeuvre> o, List<Utilisateur> u)
|
|
|
|
|
{
|
|
|
|
|
var serializer = new DataContractSerializer(typeof(DataToPersist));
|
|
|
|
|
|
|
|
|
|
DataToPersist data;
|
|
|
|
|
if (File.Exists(Path.Combine(FilePath, FileName)))
|
|
|
|
|
{
|
|
|
|
|
using (Stream s = File.OpenRead(Path.Combine(FilePath, FileName)))
|
|
|
|
|
{
|
|
|
|
|
data = serializer.ReadObject(s) as DataToPersist;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data = new DataToPersist();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ajouter le nouvel utilisateur à la liste existante
|
|
|
|
|
data.Utilisateurs.Add(u.Last());
|
|
|
|
|
|
|
|
|
|
var settings = new XmlWriterSettings() { Indent = true };
|
|
|
|
|
using (TextWriter tw = File.CreateText(Path.Combine(FilePath, FileName)))
|
|
|
|
|
{
|
|
|
|
|
using (XmlWriter w = XmlWriter.Create(tw, settings))
|
|
|
|
|
{
|
|
|
|
|
serializer.WriteObject(w, data); // Enregistrer toutes les données dans le fichier
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|