CONFIG.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 object Get(string configName)
  27. {
  28. return (InnerConfigManager != null) ? InnerConfigManager.GetConfig(configName) : null;
  29. }
  30. public static void Set(string configName, object value)
  31. {
  32. if (InnerConfigManager != null)
  33. InnerConfigManager.SetConfig(configName, value);
  34. }
  35. /// <summary>
  36. /// 返回Config目录下面文件的内容,filename也可以是绝对路径
  37. /// 如果文件不存在,返回NULL。
  38. /// 如果读取错误,返回""
  39. /// </summary>
  40. /// <param name="fileName"></param>
  41. /// <returns></returns>
  42. public static string GetFileContent(string fileName)
  43. {
  44. if (InnerConfigManager != null)
  45. return InnerConfigManager.GetFileContent(fileName);
  46. LOG.Error("Config模块没有初始化,调用GetConfigFile()" + fileName);
  47. return null;
  48. }
  49. public static void Subscribe(string module, string key, Func<object> getter)
  50. {
  51. if (InnerConfigManager != null)
  52. InnerConfigManager.Subscribe(module, key, getter);
  53. }
  54. public static object Poll(string paramName)
  55. {
  56. return (InnerConfigManager == null) ? null : InnerConfigManager.Poll(paramName);
  57. }
  58. //public static object Poll(string module, string paramName)
  59. //{
  60. // return (InnerConfigManager == null) ? null : InnerConfigManager.Poll(string.Format("{0}.{1}", module, paramName));
  61. //}
  62. public static Dictionary<string, object> PollConfig(IEnumerable<string> keys)
  63. {
  64. return (InnerConfigManager == null) ? null : InnerConfigManager.PollConfig(keys);
  65. }
  66. }
  67. }