The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Config.cs 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. using System.Web;
  5. using Newtonsoft.Json;
  6. namespace Teknik
  7. {
  8. public class Config
  9. {
  10. private ReaderWriterLockSlim _ConfigRWLock;
  11. private ReaderWriterLockSlim _ConfigFileRWLock;
  12. private JsonSerializerSettings _JsonSettings;
  13. private bool _DevEnvironment;
  14. private string _Title;
  15. private string _Description;
  16. private string _Author;
  17. private string _Host;
  18. private SMTPConfig _SMTPConfig;
  19. private string _SupportEmail;
  20. private string _BitcoinAddress;
  21. public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
  22. public string Title { get { return _Title; } set { _Title = value; } }
  23. public string Description { get { return _Description; } set { _Description = value; } }
  24. public string Author { get { return _Author; } set { _Author = value; } }
  25. public string Host { get { return _Host; } set { _Host = value; } }
  26. public SMTPConfig SMTPConfig { get { return _SMTPConfig; } set { _SMTPConfig = value; } }
  27. public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
  28. public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
  29. public Config()
  30. {
  31. _ConfigRWLock = new ReaderWriterLockSlim();
  32. _ConfigFileRWLock = new ReaderWriterLockSlim();
  33. _JsonSettings = new JsonSerializerSettings();
  34. _JsonSettings.Formatting = Formatting.Indented;
  35. SetDefaults();
  36. }
  37. public void SetDefaults()
  38. {
  39. DevEnvironment = false;
  40. Title = String.Empty;
  41. Description = String.Empty;
  42. Author = String.Empty;
  43. Host = String.Empty;
  44. SMTPConfig = new SMTPConfig();
  45. SupportEmail = string.Empty;
  46. BitcoinAddress = string.Empty;
  47. }
  48. public static Config Deserialize(string text)
  49. {
  50. return JsonConvert.DeserializeObject<Config>(text);
  51. }
  52. public static string Serialize(Config config)
  53. {
  54. return JsonConvert.SerializeObject(config);
  55. }
  56. public static Config Load()
  57. {
  58. Config config = new Config();
  59. string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
  60. if (File.Exists(Path.Combine(path, "Config.json")))
  61. {
  62. string configContents = File.ReadAllText(Path.Combine(path, "Config.json"));
  63. config = Config.Deserialize(configContents);
  64. }
  65. return config;
  66. }
  67. }
  68. }