You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
using System.Collections.ObjectModel;
|
|
using System.Runtime.Serialization;
|
|
using System.Xml;
|
|
using Model;
|
|
|
|
namespace StimPersistance
|
|
{
|
|
public class Persistance : IPersistance
|
|
{
|
|
public Persistance()
|
|
{
|
|
//Faut refactor ce truc parce que c'est pas portable
|
|
Directory.SetCurrentDirectory("C:\\Users\\Admin\\source\\repos\\Projet_IHM\\Sources\\XML");
|
|
}
|
|
|
|
public void SaveGame(ObservableCollection<Game> games)
|
|
{
|
|
XmlWriterSettings settings = new() { Indent = true };
|
|
DataContractSerializer serializer = new(typeof(ObservableCollection<Game>));
|
|
|
|
using (TextWriter tw = File.CreateText("games.xml"))
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, games);
|
|
}
|
|
|
|
public void SaveUser(List<User> users)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public ObservableCollection<Game> LoadGame()
|
|
{
|
|
if (File.Exists("games.xml"))
|
|
{
|
|
DataContractSerializer serializer = new(typeof(ObservableCollection<Game>));
|
|
using (Stream stream = File.OpenRead("games.xml")) return serializer.ReadObject(stream) as ObservableCollection<Game>;
|
|
}
|
|
return new();
|
|
}
|
|
|
|
public List<User> LoadUser()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |