CONFIG.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.Core.RT.Log;
  6. namespace Aitex.Core.RT.ConfigCenter
  7. {
  8. public class ConfigItem
  9. {
  10. public object this[string configName]
  11. {
  12. get
  13. {
  14. return CONFIG.Get(configName);
  15. }
  16. set
  17. {
  18. CONFIG.Set(configName, value);
  19. }
  20. }
  21. }
  22. public class CONFIG
  23. {
  24. public static ConfigItem Items = new ConfigItem();
  25. public static ICommonConfig InnerConfigManager { set; private get; }
  26. public static Dictionary<string, ICommonConfig> ModularManager { private set; get; } = new Dictionary<string, ICommonConfig>();
  27. public static bool IsEnable =>InnerConfigManager != null;
  28. public static object Get(string configName)
  29. {
  30. return (InnerConfigManager != null) ? InnerConfigManager.GetConfig(configName) : null;
  31. }
  32. public static void Set(string configName, object value)
  33. {
  34. if (InnerConfigManager != null)
  35. InnerConfigManager.SetConfig(configName, value);
  36. }
  37. public static void Subscribe(string module, string key, Func<object> getter)
  38. {
  39. if (InnerConfigManager != null)
  40. InnerConfigManager.Subscribe(module, key, getter);
  41. }
  42. public static object Poll(string paramName)
  43. {
  44. return (InnerConfigManager == null) ? null : InnerConfigManager.Poll(paramName);
  45. }
  46. public static object Poll(string module, string paramName)
  47. {
  48. if (ModularManager != null && ModularManager.ContainsKey(module) && ModularManager[module] != null)
  49. return ModularManager[module].Poll(paramName);
  50. return Poll(paramName);
  51. }
  52. public static Dictionary<string, object> PollConfig(IEnumerable<string> keys)
  53. {
  54. return (InnerConfigManager == null) ? null : InnerConfigManager.PollConfig(keys);
  55. }
  56. public static Dictionary<string, object> PollConfig(string module, IEnumerable<string> keys)
  57. {
  58. if (ModularManager != null && ModularManager.ContainsKey(module) && ModularManager[module] != null)
  59. return ModularManager[module].PollConfig(keys);
  60. return PollConfig(keys);
  61. }
  62. }
  63. }