SubscriptionAttribute.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 SubscriptionAttribute(string key, int flag = 0, string module="")
  21. {
  22. if (string.IsNullOrWhiteSpace(key))
  23. throw new ArgumentNullException("key");
  24. Key = key;
  25. Flag = flag;
  26. Module = module;
  27. }
  28. public SubscriptionAttribute(string key, string module)
  29. {
  30. if (string.IsNullOrWhiteSpace(key))
  31. throw new ArgumentNullException("key");
  32. Key = key;
  33. Flag = (int)FLAG.SaveDB;
  34. Module = module;
  35. }
  36. public SubscriptionAttribute(object key, string module)
  37. {
  38. if (string.IsNullOrWhiteSpace(key.ToString()))
  39. throw new ArgumentNullException("key");
  40. Key = key.ToString();
  41. Flag = (int)FLAG.IgnoreSaveDB;
  42. Module = module;
  43. }
  44. public SubscriptionAttribute(object key)
  45. {
  46. if (string.IsNullOrWhiteSpace(key.ToString()))
  47. throw new ArgumentNullException("key");
  48. Key = key.ToString();
  49. Flag = (int)FLAG.IgnoreSaveDB;
  50. Module = "";
  51. }
  52. public void SetModule(string module)
  53. {
  54. Module = module;
  55. }
  56. public SubscriptionAttribute(string key, string module, string deviceName, string deviceType)
  57. {
  58. if (string.IsNullOrWhiteSpace(key))
  59. throw new ArgumentNullException("key");
  60. Key = string.Format("{0}.{1}.{2}", deviceType, deviceName, key);
  61. Flag = (int)FLAG.SaveDB;
  62. Module = module;
  63. }
  64. public SubscriptionAttribute(string module, string method, params object[] args)
  65. {
  66. if (string.IsNullOrWhiteSpace(module))
  67. throw new ArgumentNullException("module");
  68. Module = module;
  69. Method = method;
  70. }
  71. }
  72. }