SubscriptionAttribute.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Aitex.Core.Util
  6. {
  7. [AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field)]
  8. public class SubscriptionAttribute : Attribute
  9. {
  10. public enum FLAG
  11. {
  12. SaveDB = 0x00,
  13. IgnoreSaveDB = 0x01,
  14. }
  15. public string ModuleKey { get { return string.IsNullOrEmpty(Module) ? Key : (Module + "." + Key); } }
  16. public readonly string Key;
  17. public string Module { get; internal set; }
  18. public readonly string Method;
  19. public readonly int Flag;
  20. public readonly object[] Params;
  21. public SubscriptionAttribute(string key, int flag = 0, string module="")
  22. {
  23. if (string.IsNullOrWhiteSpace(key))
  24. throw new ArgumentNullException("key");
  25. Key = key;
  26. Flag = flag;
  27. Module = module;
  28. }
  29. public SubscriptionAttribute(string key, string module)
  30. {
  31. if (string.IsNullOrWhiteSpace(key))
  32. throw new ArgumentNullException("key");
  33. Key = key;
  34. Flag = (int)FLAG.SaveDB;
  35. Module = module;
  36. }
  37. public SubscriptionAttribute(object key, string module)
  38. {
  39. if (string.IsNullOrWhiteSpace(key.ToString()))
  40. throw new ArgumentNullException("key");
  41. Key = key.ToString();
  42. Flag = (int)FLAG.IgnoreSaveDB;
  43. Module = module;
  44. }
  45. public SubscriptionAttribute(object key)
  46. {
  47. if (string.IsNullOrWhiteSpace(key.ToString()))
  48. throw new ArgumentNullException("key");
  49. Key = key.ToString();
  50. Flag = (int)FLAG.IgnoreSaveDB;
  51. Module = "";
  52. }
  53. public void SetModule(string module)
  54. {
  55. Module = module;
  56. }
  57. public SubscriptionAttribute(string key, string module, string deviceName, string deviceType)
  58. {
  59. if (string.IsNullOrWhiteSpace(key))
  60. throw new ArgumentNullException("key");
  61. Key = string.Format("{0}.{1}.{2}", deviceType, deviceName, key);
  62. Flag = (int)FLAG.SaveDB;
  63. Module = module;
  64. }
  65. public SubscriptionAttribute(string key, string module, params object[] args)
  66. {
  67. if (string.IsNullOrWhiteSpace(key))
  68. throw new ArgumentNullException("key");
  69. Key = key;
  70. Flag = (int)FLAG.SaveDB;
  71. Module = module;
  72. Params = args;
  73. }
  74. }
  75. }