|
|
@ -1,10 +1,7 @@
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Xml;
|
|
|
|
using System.Xml;
|
|
|
|
using Microsoft.VisualBasic;
|
|
|
|
|
|
|
|
using Microsoft.VisualBasic.FileIO;
|
|
|
|
|
|
|
|
using Model;
|
|
|
|
using Model;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
|
|
|
|
|
|
namespace StimPersistance
|
|
|
|
namespace StimPersistance
|
|
|
@ -26,7 +23,7 @@ namespace StimPersistance
|
|
|
|
public void SaveGame(List<Game> games)
|
|
|
|
public void SaveGame(List<Game> games)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
XmlWriterSettings settings = new() { Indent = true };
|
|
|
|
XmlWriterSettings settings = new() { Indent = true };
|
|
|
|
DataContractSerializer serializer = new(typeof(List<Game>));
|
|
|
|
DataContractSerializer serializer = new(typeof(List<Game>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
|
|
|
|
|
|
|
|
|
|
|
using (TextWriter tw = File.CreateText(fullGamePath))
|
|
|
|
using (TextWriter tw = File.CreateText(fullGamePath))
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, games);
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, games);
|
|
|
@ -35,7 +32,7 @@ namespace StimPersistance
|
|
|
|
public void SaveUser(HashSet<User> users)
|
|
|
|
public void SaveUser(HashSet<User> users)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
XmlWriterSettings settings = new() { Indent = true };
|
|
|
|
XmlWriterSettings settings = new() { Indent = true };
|
|
|
|
DataContractSerializer serializer = new(typeof(HashSet<User>));
|
|
|
|
DataContractSerializer serializer = new(typeof(HashSet<User>), new DataContractSerializerSettings() { PreserveObjectReferences = true});
|
|
|
|
|
|
|
|
|
|
|
|
using (TextWriter tw = File.CreateText(fullUserPath))
|
|
|
|
using (TextWriter tw = File.CreateText(fullUserPath))
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, users);
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(tw, settings)) serializer.WriteObject(writer, users);
|
|
|
@ -45,7 +42,7 @@ namespace StimPersistance
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (File.Exists(fullGamePath))
|
|
|
|
if (File.Exists(fullGamePath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataContractSerializer serializer = new(typeof(List<Game>));
|
|
|
|
DataContractSerializer serializer = new(typeof(List<Game>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
|
|
|
using (Stream stream = File.OpenRead(fullGamePath)) return serializer.ReadObject(stream) as List<Game> ?? new();
|
|
|
|
using (Stream stream = File.OpenRead(fullGamePath)) return serializer.ReadObject(stream) as List<Game> ?? new();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new();
|
|
|
|
return new();
|
|
|
@ -55,7 +52,7 @@ namespace StimPersistance
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (File.Exists(fullUserPath))
|
|
|
|
if (File.Exists(fullUserPath))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataContractSerializer serializer = new(typeof(HashSet<User>));
|
|
|
|
DataContractSerializer serializer = new(typeof(HashSet<User>), new DataContractSerializerSettings() { PreserveObjectReferences = true });
|
|
|
|
using (Stream stream = File.OpenRead(fullUserPath)) return serializer.ReadObject(stream) as HashSet<User> ?? new();
|
|
|
|
using (Stream stream = File.OpenRead(fullUserPath)) return serializer.ReadObject(stream) as HashSet<User> ?? new();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new();
|
|
|
|
return new();
|
|
|
|