2015-07-16 23:54:53 +02:00
|
|
|
|
using System;
|
2015-11-23 07:55:24 +01:00
|
|
|
|
using System.IO;
|
2015-07-16 23:54:53 +02:00
|
|
|
|
using System.Threading;
|
2015-11-23 07:55:24 +01:00
|
|
|
|
using System.Web;
|
2015-07-16 23:54:53 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace Teknik
|
|
|
|
|
{
|
|
|
|
|
public class Config
|
|
|
|
|
{
|
|
|
|
|
private ReaderWriterLockSlim _ConfigRWLock;
|
|
|
|
|
private ReaderWriterLockSlim _ConfigFileRWLock;
|
|
|
|
|
private JsonSerializerSettings _JsonSettings;
|
|
|
|
|
|
|
|
|
|
private bool _DevEnvironment;
|
|
|
|
|
private string _Title;
|
|
|
|
|
private string _Description;
|
|
|
|
|
private string _Author;
|
|
|
|
|
private string _Host;
|
2015-11-23 07:55:24 +01:00
|
|
|
|
private string _BitcoinAddress;
|
2015-07-16 23:54:53 +02:00
|
|
|
|
|
|
|
|
|
public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
|
|
|
|
|
public string Title { get { return _Title; } set { _Title = value; } }
|
|
|
|
|
public string Description { get { return _Description; } set { _Description = value; } }
|
|
|
|
|
public string Author { get { return _Author; } set { _Author = value; } }
|
|
|
|
|
public string Host { get { return _Host; } set { _Host = value; } }
|
2015-11-23 07:55:24 +01:00
|
|
|
|
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
|
2015-07-16 23:54:53 +02:00
|
|
|
|
|
|
|
|
|
public Config()
|
|
|
|
|
{
|
|
|
|
|
_ConfigRWLock = new ReaderWriterLockSlim();
|
|
|
|
|
_ConfigFileRWLock = new ReaderWriterLockSlim();
|
|
|
|
|
_JsonSettings = new JsonSerializerSettings();
|
|
|
|
|
_JsonSettings.Formatting = Formatting.Indented;
|
|
|
|
|
|
|
|
|
|
SetDefaults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetDefaults()
|
|
|
|
|
{
|
|
|
|
|
DevEnvironment = false;
|
|
|
|
|
Title = String.Empty;
|
|
|
|
|
Description = String.Empty;
|
|
|
|
|
Author = String.Empty;
|
|
|
|
|
Host = String.Empty;
|
2015-11-23 07:55:24 +01:00
|
|
|
|
BitcoinAddress = string.Empty;
|
2015-07-16 23:54:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Config Deserialize(string text)
|
|
|
|
|
{
|
|
|
|
|
return JsonConvert.DeserializeObject<Config>(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Serialize(Config config)
|
|
|
|
|
{
|
|
|
|
|
return JsonConvert.SerializeObject(config);
|
|
|
|
|
}
|
2015-11-23 07:55:24 +01:00
|
|
|
|
|
|
|
|
|
public static Config Load()
|
|
|
|
|
{
|
2015-11-23 20:17:57 +01:00
|
|
|
|
Config config = new Config();
|
|
|
|
|
if (File.Exists(HttpContext.Current.Server.MapPath("~/App_Data/Config.json")))
|
|
|
|
|
{
|
|
|
|
|
string configContents = File.ReadAllText(HttpContext.Current.Server.MapPath("~/App_Data/Config.json"));
|
|
|
|
|
config = Config.Deserialize(configContents);
|
|
|
|
|
}
|
2015-11-23 07:55:24 +01:00
|
|
|
|
return config;
|
|
|
|
|
}
|
2015-07-16 23:54:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|