diff --git a/OpenNest.Core/IJsonConfigPostProcessor.cs b/OpenNest.Core/IJsonConfigPostProcessor.cs
new file mode 100644
index 00000000..92794278
--- /dev/null
+++ b/OpenNest.Core/IJsonConfigPostProcessor.cs
@@ -0,0 +1,19 @@
+namespace OpenNest
+{
+ ///
+ /// A configurable post whose settings travel as JSON, so a host can keep them somewhere other
+ /// than the post's own file (the nest server's shared copy, for one).
+ ///
+ public interface IJsonConfigPostProcessor : IConfigurablePostProcessor
+ {
+ /// The settings as the post's own file holds them.
+ string SerializeConfig();
+
+ ///
+ /// Replaces the settings with , in the post's file format; the
+ /// file itself is not written. Throws and
+ /// keeps the current settings when the JSON is not usable.
+ ///
+ void LoadConfig(string json);
+ }
+}
diff --git a/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs b/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs
index 69f58b2e..5c76fa63 100644
--- a/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs
+++ b/Posts/OpenNest.Posts.Cincinnati/CincinnatiPostProcessor.cs
@@ -10,7 +10,7 @@ using OpenNest.CNC;
namespace OpenNest.Posts.Cincinnati
{
public sealed class CincinnatiPostProcessor
- : IConfigurablePostProcessor,
+ : IJsonConfigPostProcessor,
IPostProcessorNestAware,
IMaterialProvidingPostProcessor
{
@@ -24,7 +24,7 @@ namespace OpenNest.Posts.Cincinnati
public string Author => "OpenNest";
public string Description => "Cincinnati CL-707/CL-800/CL-900/CL-940/CLX family";
- public CincinnatiPostConfig Config { get; }
+ public CincinnatiPostConfig Config { get; private set; }
object IConfigurablePostProcessor.Config => Config;
@@ -81,10 +81,17 @@ namespace OpenNest.Posts.Cincinnati
public void SaveConfig()
{
var configPath = GetConfigPath();
- var json = JsonSerializer.Serialize(Config, JsonOptions);
+ var json = SerializeConfig();
File.WriteAllText(configPath, json);
}
+ public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
+
+ public void LoadConfig(string json) =>
+ Config =
+ JsonSerializer.Deserialize(json, JsonOptions)
+ ?? throw new JsonException("The post settings are empty.");
+
private static string GetConfigPath()
{
var assemblyPath = typeof(CincinnatiPostProcessor).Assembly.Location;
diff --git a/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs b/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs
index d0dc08cf..1e65ab38 100644
--- a/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs
+++ b/Posts/OpenNest.Posts.CincinnatiCIFiber/CIFiberPostProcessor.cs
@@ -17,7 +17,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber
/// structure of the machine sample (see ).
///
public sealed class CIFiberPostProcessor
- : IConfigurablePostProcessor,
+ : IJsonConfigPostProcessor,
IMultiFilePostProcessor,
IPostVerificationSupport
{
@@ -33,7 +33,7 @@ namespace OpenNest.Posts.CincinnatiCIFiber
public string Description =>
"CI Fiber family laser (TF5200 / nLight CLX), e.g. CI Fiber 4020 8kW";
- public CIFiberPostConfig Config { get; }
+ public CIFiberPostConfig Config { get; private set; }
object IConfigurablePostProcessor.Config => Config;
@@ -62,10 +62,17 @@ namespace OpenNest.Posts.CincinnatiCIFiber
public void SaveConfig()
{
var configPath = GetConfigPath();
- var json = JsonSerializer.Serialize(Config, JsonOptions);
+ var json = SerializeConfig();
File.WriteAllText(configPath, json);
}
+ public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
+
+ public void LoadConfig(string json) =>
+ Config =
+ JsonSerializer.Deserialize(json, JsonOptions)
+ ?? throw new JsonException("The post settings are empty.");
+
private static string GetConfigPath()
{
var assemblyPath = typeof(CIFiberPostProcessor).Assembly.Location;
diff --git a/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs b/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs
index 9de13734..c2e4e054 100644
--- a/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs
+++ b/Posts/OpenNest.Posts.GravographIS/GravographISPostProcessor.cs
@@ -17,7 +17,7 @@ namespace OpenNest.Posts.GravographIS
/// (Scribe) and a cut pass (Cut), each with its own feed/depth from .
/// The cut pass pauses by default so the operator can swap/adjust the tool.
///
- public sealed class GravographISPostProcessor : IConfigurablePostProcessor
+ public sealed class GravographISPostProcessor : IJsonConfigPostProcessor
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
@@ -38,7 +38,7 @@ namespace OpenNest.Posts.GravographIS
public bool AllowReverse { get; set; } = true;
- public GravographISPostConfig Config { get; }
+ public GravographISPostConfig Config { get; private set; }
object IConfigurablePostProcessor.Config => Config;
@@ -67,10 +67,17 @@ namespace OpenNest.Posts.GravographIS
public void SaveConfig()
{
var configPath = GetConfigPath();
- var json = JsonSerializer.Serialize(Config, JsonOptions);
+ var json = SerializeConfig();
File.WriteAllText(configPath, json);
}
+ public string SerializeConfig() => JsonSerializer.Serialize(Config, JsonOptions);
+
+ public void LoadConfig(string json) =>
+ Config =
+ JsonSerializer.Deserialize(json, JsonOptions)
+ ?? throw new JsonException("The post settings are empty.");
+
private static string GetConfigPath()
{
var assemblyPath = typeof(GravographISPostProcessor).Assembly.Location;