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.
54 lines
1.5 KiB
54 lines
1.5 KiB
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
using System.Runtime.Serialization.Json;
|
|
using System.Xml;
|
|
using static System.Console;
|
|
using Model;
|
|
using Microsoft.VisualBasic;
|
|
using System.Data;
|
|
|
|
namespace Persistance
|
|
{
|
|
public class DataSerializerXML
|
|
{
|
|
public static void Serializer(string path, Theque theque)
|
|
{
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
|
|
string xmlFile = "theque.xml";
|
|
|
|
var serializer = new DataContractSerializer(typeof(Theque));
|
|
|
|
using (Stream s = File.Create(xmlFile))
|
|
{
|
|
serializer.WriteObject(s, theque);
|
|
}
|
|
}
|
|
|
|
public static Theque Deserializer(string path)
|
|
{
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
|
|
string xmlFile = "theque.xml";
|
|
|
|
var serializer = new DataContractSerializer(typeof(Theque));
|
|
|
|
Theque theque = new Theque();
|
|
if(File.Exists(xmlFile))
|
|
{
|
|
using (Stream s = File.OpenRead(xmlFile))
|
|
{
|
|
Theque? thequeOpt = serializer.ReadObject(s) as Theque;
|
|
if (thequeOpt != null)
|
|
theque = thequeOpt;
|
|
else
|
|
Console.WriteLine("Theque est null");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
theque = Stub.LoadTheque();
|
|
}
|
|
return theque;
|
|
}
|
|
}
|
|
} |