|
|
|
@ -0,0 +1,59 @@
|
|
|
|
|
using Model;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Runtime.Serialization.Json;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace Persistance
|
|
|
|
|
{
|
|
|
|
|
public class DataSerializerJson
|
|
|
|
|
{
|
|
|
|
|
public static void Serializer(string path, Theque theque)
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
|
|
|
|
|
string jsonFile = "theque.json";
|
|
|
|
|
|
|
|
|
|
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Theque));
|
|
|
|
|
|
|
|
|
|
using (FileStream stream = File.Create(jsonFile))
|
|
|
|
|
{
|
|
|
|
|
using (var writer = JsonReaderWriterFactory.CreateJsonWriter(stream, System.Text.Encoding.UTF8, false, true))
|
|
|
|
|
{
|
|
|
|
|
jsonSerializer.WriteObject(writer, theque);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Theque Deserializer(string path)
|
|
|
|
|
{
|
|
|
|
|
Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), path));
|
|
|
|
|
string jsonFile = "theque.json";
|
|
|
|
|
|
|
|
|
|
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Theque));
|
|
|
|
|
|
|
|
|
|
Theque? theque = new Theque();
|
|
|
|
|
if (File.Exists(jsonFile))
|
|
|
|
|
{
|
|
|
|
|
using (Stream stream = File.OpenRead(jsonFile))
|
|
|
|
|
{
|
|
|
|
|
Theque? thequeOpt = jsonSerializer.ReadObject(stream) as Theque;
|
|
|
|
|
if (thequeOpt != null)
|
|
|
|
|
theque = thequeOpt;
|
|
|
|
|
else
|
|
|
|
|
Console.WriteLine("Theque est null");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
theque = Stub.LoadTheque();
|
|
|
|
|
}
|
|
|
|
|
return theque;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|