Adding nix shell and reworking some parser/local file manager stuff

This commit is contained in:
2026-01-23 23:09:56 -06:00
parent ad2e074991
commit 45cd325818
6 changed files with 48 additions and 16 deletions

View File

@@ -1,4 +1,6 @@
using System.Reflection.Metadata;
using SzLib; using SzLib;
using SzLib.DataObjects;
namespace SzCli; namespace SzCli;
@@ -18,10 +20,16 @@ public class LocalFileManager : ISzFileManager
} }
} }
public string DatasetsPath => Path.Combine(DataPath, "datasets");
public bool SaveFile(string path, string fileContent) public bool SaveFile(string path, string fileContent)
{ {
try try
{ {
var dir = Path.GetDirectoryName(path);
if (dir is null) return false;
Directory.CreateDirectory(dir);
File.WriteAllText(path, fileContent); File.WriteAllText(path, fileContent);
return true; return true;
} }
@@ -31,4 +39,17 @@ public class LocalFileManager : ISzFileManager
return false; return false;
} }
} }
public string? LoadFile(string path)
{
try
{
return File.ReadAllText(path);
}
catch (Exception e)
{
Console.WriteLine($"Error saving file: {e.Message}");
return null;
}
}
} }

View File

@@ -19,8 +19,8 @@ public class Program
Console.WriteLine("Attempting to load dataset..."); Console.WriteLine("Attempting to load dataset...");
var loadedDataset = parser.LoadDataset(dataset.Id); 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);
} }
} }

View File

@@ -1,6 +0,0 @@
namespace SzLib;
public class Class1
{
}

View File

@@ -1,8 +1,12 @@
using SzLib.DataObjects;
namespace SzLib; namespace SzLib;
public interface ISzFileManager public interface ISzFileManager
{ {
public string DataPath {get;} public string DataPath {get;}
public string DatasetsPath {get;}
public bool SaveFile(string path, string fileContent); public bool SaveFile(string path, string fileContent);
public string? LoadFile(string path);
} }

View File

@@ -35,13 +35,12 @@ public class SzParser(ISzFileManager szFileManager)
public bool SaveDataset(SzDataset dataset) public bool SaveDataset(SzDataset dataset)
{ {
var datasetDir = Path.Combine(szFileManager.DataPath, "datasets", dataset.Id); var datasetDir = Path.Combine(szFileManager.DatasetsPath, dataset.Id);
Directory.CreateDirectory(datasetDir);
try try
{ {
var json = SerializeDatasetToJson(dataset); var json = SerializeDatasetToJson(dataset);
File.WriteAllText(Path.Combine(datasetDir, "dataset.json"), json); return szFileManager.SaveFile(Path.Combine(datasetDir, "dataset.json"), json);
return true;
} }
catch (Exception e) catch (Exception e)
{ {

14
shell.nix Normal file
View File

@@ -0,0 +1,14 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
dotnet-sdk
omnisharp-roslyn
];
shellHook = ''
echo "// SESSION ZERO DEV SHELL //"
'';
}