Added SZ singleton and services

This commit is contained in:
2026-01-25 16:47:29 -06:00
parent 74ee8eefc3
commit 800b5d9def
8 changed files with 140 additions and 12 deletions

View File

@@ -1,55 +0,0 @@
using System.Reflection.Metadata;
using SzCore;
using SzCore.DataObjects;
namespace SzCli;
public class LocalFileManager : ISzFileManager
{
public string DataPath
{
get
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
return path;
}
}
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;
}
catch (Exception e)
{
Console.WriteLine($"Error saving file: {e.Message}");
return false;
}
}
public string? LoadFile(string path)
{
try
{
return File.ReadAllText(path);
}
catch (Exception e)
{
Console.WriteLine($"Error loading file: {e.Message}");
return null;
}
}
}

View File

@@ -1,12 +1,13 @@
using System;
using SzCore;
using SzCore.Defaults;
namespace SzCli;
public class Program
{
private static readonly ISzFileManager _fileManager = new LocalFileManager();
private static readonly ISzLogger _logger = new Logger(_fileManager);
private static readonly DefaultLocalFileManager _fileManager = new();
private static readonly Logger _logger = new(_fileManager);
public static void Main(string[] args)
{
@@ -24,6 +25,6 @@ public class Program
var loadedDataset = parser.LoadDataset(dataset.Id);
_logger.Log($"Successfully loaded dataset? {loadedDataset != null}. Id is {loadedDataset?.Id}");
_logger.Log(loadedDataset?.DataObjects["test"].Fields["value"].Value);
_logger.Log(loadedDataset?.DataObjects["test"].Fields["value"].Value ?? "Could not get value of test.value");
}
}

View File

@@ -6,11 +6,28 @@ public static class Test
{
public static SzDataset CreateTestDataset()
{
var dt = new SzDataObjectTemplate(){
Name = "SzCore - Basic Item",
Id = "szcore-item-basic",
DataObjectType = "item",
Uuid = Guid.NewGuid()
};
var testTemplateField = new SzTemplateField()
{
Id = "cost",
FieldType = SzFieldType.Number,
DefaultValue = "20"
};
dt.TemplateFields.Add(testTemplateField.Id, testTemplateField);
var ds = new SzDataset()
{
Name = "TestDataset",
Id = "test-dataset",
DataObjectTemplateId = "0",
DataObjectTemplateId = dt.Id,
DataObjectTemplateUuid = dt.Uuid,
DataObjectType = "item",
Uuid = Guid.NewGuid(),
};