From 45cd32581845eef05424917f69ead345fcc1d3c5 Mon Sep 17 00:00:00 2001 From: chrisbell Date: Fri, 23 Jan 2026 23:09:56 -0600 Subject: [PATCH] Adding nix shell and reworking some parser/local file manager stuff --- SzCli/LocalFileManager.cs | 23 ++++++++++++++++++++++- SzCli/Program.cs | 4 ++-- SzLib/Class1.cs | 6 ------ SzLib/ISzFileManager.cs | 10 +++++++--- SzLib/SzParser.cs | 7 +++---- shell.nix | 14 ++++++++++++++ 6 files changed, 48 insertions(+), 16 deletions(-) delete mode 100644 SzLib/Class1.cs create mode 100644 shell.nix diff --git a/SzCli/LocalFileManager.cs b/SzCli/LocalFileManager.cs index ae5827e..f0c7d24 100644 --- a/SzCli/LocalFileManager.cs +++ b/SzCli/LocalFileManager.cs @@ -1,4 +1,6 @@ +using System.Reflection.Metadata; using SzLib; +using SzLib.DataObjects; namespace SzCli; @@ -18,10 +20,16 @@ public class LocalFileManager : ISzFileManager } } + public string DatasetsPath => Path.Combine(DataPath, "datasets"); + public bool SaveFile(string path, string fileContent) { try { + var dir = Path.GetDirectoryName(path); + if (dir is null) return false; + Directory.CreateDirectory(dir); + File.WriteAllText(path, fileContent); return true; } @@ -31,4 +39,17 @@ public class LocalFileManager : ISzFileManager return false; } } -} \ No newline at end of file + + public string? LoadFile(string path) + { + try + { + return File.ReadAllText(path); + } + catch (Exception e) + { + Console.WriteLine($"Error saving file: {e.Message}"); + return null; + } + } +} diff --git a/SzCli/Program.cs b/SzCli/Program.cs index 9375ebb..5e2e612 100644 --- a/SzCli/Program.cs +++ b/SzCli/Program.cs @@ -19,8 +19,8 @@ public class Program Console.WriteLine("Attempting to load dataset..."); var loadedDataset = parser.LoadDataset(dataset.Id); - Console.WriteLine($"Successfully loaded dataset? {loadedDataset != null}. Id is {loadedDataset.Id}"); + Console.WriteLine($"Successfully loaded dataset? {loadedDataset != null}. Id is {loadedDataset?.Id}"); - Console.WriteLine(loadedDataset.DataObjects["test"].Fields["value"].Value); + Console.WriteLine(loadedDataset?.DataObjects["test"].Fields["value"].Value); } } \ No newline at end of file diff --git a/SzLib/Class1.cs b/SzLib/Class1.cs deleted file mode 100644 index 782cceb..0000000 --- a/SzLib/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SzLib; - -public class Class1 -{ - -} diff --git a/SzLib/ISzFileManager.cs b/SzLib/ISzFileManager.cs index 64ea745..17b08e4 100644 --- a/SzLib/ISzFileManager.cs +++ b/SzLib/ISzFileManager.cs @@ -1,8 +1,12 @@ +using SzLib.DataObjects; + namespace SzLib; public interface ISzFileManager -{ +{ public string DataPath {get;} - + public string DatasetsPath {get;} + public bool SaveFile(string path, string fileContent); -} \ No newline at end of file + public string? LoadFile(string path); +} diff --git a/SzLib/SzParser.cs b/SzLib/SzParser.cs index 02a2ff6..b0642df 100644 --- a/SzLib/SzParser.cs +++ b/SzLib/SzParser.cs @@ -35,13 +35,12 @@ public class SzParser(ISzFileManager szFileManager) public bool SaveDataset(SzDataset dataset) { - var datasetDir = Path.Combine(szFileManager.DataPath, "datasets", dataset.Id); - Directory.CreateDirectory(datasetDir); + var datasetDir = Path.Combine(szFileManager.DatasetsPath, dataset.Id); + try { var json = SerializeDatasetToJson(dataset); - File.WriteAllText(Path.Combine(datasetDir, "dataset.json"), json); - return true; + return szFileManager.SaveFile(Path.Combine(datasetDir, "dataset.json"), json); } catch (Exception e) { diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..cb64eaa --- /dev/null +++ b/shell.nix @@ -0,0 +1,14 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + + nativeBuildInputs = with pkgs; [ + dotnet-sdk + omnisharp-roslyn + ]; + + shellHook = '' + echo "// SESSION ZERO DEV SHELL //" + ''; +} +