Skip to content

Commit

Permalink
Use JSON for sgen compatible state recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Dec 18, 2023
1 parent a770efe commit 63ae425
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Aeon.Acquisition/Aeon.Acquisition.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageTags>Bonsai Rx Project Aeon Acquisition</PackageTags>
<TargetFramework>net472</TargetFramework>
<VersionPrefix>0.5.0</VersionPrefix>
<VersionSuffix>build231204</VersionSuffix>
<VersionSuffix>build231205</VersionSuffix>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 7 additions & 15 deletions src/Aeon.Acquisition/StateRecovery.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using Newtonsoft.Json;

namespace Aeon.Acquisition
{
Expand All @@ -14,11 +12,8 @@ static string GetFileName(string name) => !string.IsNullOrEmpty(name)
public static void Serialize(string name, TState value)
{
var fileName = GetFileName(name);
var serializer = new XmlSerializer(typeof(TState));
using (var writer = XmlWriter.Create(fileName, new XmlWriterSettings { Indent = true }))
{
serializer.Serialize(writer, value);
}
var json = JsonConvert.SerializeObject(value, Formatting.Indented);
File.WriteAllText(fileName, json);
}

public static TState Deserialize(string name)
Expand All @@ -29,15 +24,12 @@ public static TState Deserialize(string name)
return new TState();
}

var serializer = new XmlSerializer(typeof(TState));
var json = File.ReadAllText(fileName);
try
{
using (var reader = XmlReader.Create(fileName))
{
return (TState)serializer.Deserialize(reader);
}
return JsonConvert.DeserializeObject<TState>(json);
}
catch (InvalidOperationException)
catch (JsonException)
{
return new TState();
}
Expand Down

0 comments on commit 63ae425

Please sign in to comment.