697a752be0
fix rare issue with summing session scores copy font to expected wwwroot dir in debug mode so we get pretty icons when developing upgrade some packages pretty much reworked the entire server web config to support better validation and stuff.. not really a small fix finish web configuration changes (I think) finish up configuration changes and update shared library nuget
54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using Newtonsoft.Json;
|
|
using SharedLibraryCore.Exceptions;
|
|
using SharedLibraryCore.Interfaces;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SharedLibraryCore.Configuration
|
|
{
|
|
public class BaseConfigurationHandler<T> : IConfigurationHandler<T> where T : IBaseConfiguration
|
|
{
|
|
readonly string _configurationPath;
|
|
T _configuration;
|
|
|
|
public BaseConfigurationHandler(string fn)
|
|
{
|
|
_configurationPath = Path.Join(Utilities.OperatingDirectory, "Configuration", $"{fn}.json");
|
|
Build();
|
|
}
|
|
|
|
public void Build()
|
|
{
|
|
try
|
|
{
|
|
var configContent = File.ReadAllText(_configurationPath);
|
|
_configuration = JsonConvert.DeserializeObject<T>(configContent);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new ConfigurationException("MANAGER_CONFIGURATION_ERROR")
|
|
{
|
|
Errors = new[] { e.Message }
|
|
};
|
|
}
|
|
}
|
|
|
|
public Task Save()
|
|
{
|
|
var appConfigJSON = JsonConvert.SerializeObject(_configuration, Formatting.Indented);
|
|
return File.WriteAllTextAsync(_configurationPath, appConfigJSON);
|
|
}
|
|
|
|
public T Configuration()
|
|
{
|
|
return _configuration;
|
|
}
|
|
|
|
public void Set(T config)
|
|
{
|
|
_configuration = config;
|
|
}
|
|
}
|
|
}
|