Added SZ singleton and services
This commit is contained in:
51
SzCore/Defaults/DefaultLocalFileManager.cs
Normal file
51
SzCore/Defaults/DefaultLocalFileManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace SzCore.Defaults;
|
||||
|
||||
public class DefaultLocalFileManager : 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user