DATA.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections.Concurrent;
  6. using System.Reflection;
  7. using System.Threading.Tasks;
  8. using Aitex.Core.Util;
  9. namespace Aitex.Core.RT.DataCenter
  10. {
  11. public static class DATA
  12. {
  13. public static string ModuleKey(string module, string key)
  14. {
  15. return string.Format("{0}.{1}", module, key);
  16. }
  17. public static ICommonData InnerDataManager { set; private get; }
  18. public static void Subscribe<T>(T instance, string keyPrefix = null) where T : class
  19. {
  20. if (InnerDataManager != null)
  21. InnerDataManager.Subscribe<T>(instance, keyPrefix);
  22. }
  23. public static void Subscribe(string key, Func<object> getter, SubscriptionAttribute.FLAG flag = SubscriptionAttribute.FLAG.SaveDB)
  24. {
  25. if (InnerDataManager != null)
  26. InnerDataManager.Subscribe(key, getter, flag);
  27. }
  28. public static void Subscribe(object key, Func<object> getter, SubscriptionAttribute.FLAG flag = SubscriptionAttribute.FLAG.SaveDB)
  29. {
  30. if (InnerDataManager != null)
  31. InnerDataManager.Subscribe(key.ToString(), getter, flag);
  32. }
  33. public static void Subscribe(string module, string key, Func<object> getter, SubscriptionAttribute.FLAG flag = SubscriptionAttribute.FLAG.SaveDB)
  34. {
  35. if (InnerDataManager != null)
  36. InnerDataManager.Subscribe(string.Format("{0}.{1}", module, key), getter, flag);
  37. }
  38. public static void Subscribe(string moduleKey, DataItem<object> dataItem, SubscriptionAttribute.FLAG flag = SubscriptionAttribute.FLAG.SaveDB)
  39. {
  40. if (InnerDataManager != null)
  41. InnerDataManager.Subscribe(moduleKey, dataItem, flag);
  42. }
  43. public static object Poll(string paramName)
  44. {
  45. return (InnerDataManager == null) ? null : InnerDataManager.Poll(paramName);
  46. }
  47. public static object Poll(string module, string paramName)
  48. {
  49. return (InnerDataManager == null) ? null : InnerDataManager.Poll(string.Format("{0}.{1}", module, paramName));
  50. }
  51. public static T Poll<T>(string module, string paramName)
  52. {
  53. return (T)InnerDataManager.Poll(string.Format("{0}.{1}", module, paramName));
  54. }
  55. public static Dictionary<string, object> PollData(IEnumerable<string> keys)
  56. {
  57. return (InnerDataManager == null) ? null : InnerDataManager.PollData(keys);
  58. }
  59. public static void Traverse(object instance, string keyPrefix)
  60. {
  61. if (InnerDataManager != null)
  62. InnerDataManager.Traverse(instance, keyPrefix);
  63. }
  64. public static SortedDictionary<string, Func<object>> GetDBRecorderList()
  65. {
  66. return (InnerDataManager == null) ? null : InnerDataManager.GetDBRecorderList();
  67. }
  68. }
  69. }