2024-10-24 16:05:50 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
[assembly: InternalsVisibleTo("deployment.tests")]
|
|
|
|
|
namespace greyn.Deployment
|
|
|
|
|
{
|
|
|
|
|
public static class ConfigurationBootstrapper
|
|
|
|
|
{
|
|
|
|
|
private const string confpath = "appsettings.json";
|
|
|
|
|
|
|
|
|
|
public static T Load<T>() where T : new()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists("appsettings.json"))
|
|
|
|
|
{
|
2024-10-30 20:32:33 -04:00
|
|
|
|
/*
|
|
|
|
|
* if the configuration expects new values we write them in.
|
|
|
|
|
* if you left other junk for whatever reason, get rekt
|
2024-10-24 16:05:50 -04:00
|
|
|
|
*/
|
2024-10-30 20:32:33 -04:00
|
|
|
|
var toReturn = JsonConvert.DeserializeObject<T>(File.ReadAllText(confpath)) ?? new T();
|
|
|
|
|
File.WriteAllText(confpath, JsonConvert.SerializeObject(toReturn, Formatting.Indented));
|
2024-10-24 16:05:50 -04:00
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var toReturn = new T();
|
|
|
|
|
File.WriteAllText(confpath, JsonConvert.SerializeObject(toReturn));
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-30 20:32:33 -04:00
|
|
|
|
}
|