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.

64 lines
1.6 KiB

2 years ago
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. /// <summary>
  7. /// Config 的摘要说明
  8. /// </summary>
  9. public static class Config
  10. {
  11. private static bool noCache = true;
  12. private static JObject BuildItems()
  13. {
  14. var json = File.ReadAllText(HttpContext.Current.Server.MapPath("config.json"));
  15. return JObject.Parse(json);
  16. }
  17. public static JObject Items
  18. {
  19. get
  20. {
  21. if (noCache || _Items == null)
  22. {
  23. _Items = BuildItems();
  24. foreach (JProperty o in _Items.Properties())
  25. {
  26. var jv = o.Value;
  27. if (o.Value.ToString() == "baseurl")
  28. {
  29. var url = HttpContext.Current.Request.Url.ToString();//"http://localhost:10553/Ueditor/net/"
  30. var idx = url.IndexOf("Ueditor");
  31. var sBaseUrl = url.Substring(0, idx);
  32. o.Value = sBaseUrl + "Ueditor/net/";
  33. //o.Value = "http://localhost:10553/Ueditor/net/";
  34. }
  35. }
  36. }
  37. return _Items;
  38. }
  39. }
  40. private static JObject _Items;
  41. public static T GetValue<T>(string key)
  42. {
  43. return Items[key].Value<T>();
  44. }
  45. public static String[] GetStringList(string key)
  46. {
  47. return Items[key].Select(x => x.Value<String>()).ToArray();
  48. }
  49. public static String GetString(string key)
  50. {
  51. return GetValue<String>(key);
  52. }
  53. public static int GetInt(string key)
  54. {
  55. return GetValue<int>(key);
  56. }
  57. }