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.

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