Adding nix shell and reworking some parser/local file manager stuff
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
public string? LoadFile(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Error saving file: {e.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace SzLib;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
public string? LoadFile(string path);
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user