Meta.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Edge.Core.Processor.Dispatcher.Attributes
  7. {
  8. /// <summary>
  9. /// Providing the jsonSchemas for method's or ctor's parameters.
  10. /// </summary>
  11. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false)]
  12. public class ParamsJsonSchemas : Attribute
  13. {
  14. /// <summary>
  15. /// the jsonSchemas persisted in a resource file.
  16. /// </summary>
  17. /// <param name="schemaEmbededResourceName">the resource file name, only the '.json' file extension can be omit.</param>
  18. public ParamsJsonSchemas(string schemaEmbededResourceName)
  19. {
  20. if (schemaEmbededResourceName.ToLower().EndsWith(".json"))
  21. this.SchemaEmbededResourceName = schemaEmbededResourceName.Trim();
  22. else
  23. this.SchemaEmbededResourceName = schemaEmbededResourceName.Trim() + ".json";
  24. }
  25. /// <summary>
  26. /// the json schema's are defined with inline strings.
  27. /// </summary>
  28. /// <param name="schemaStrings">one for each parameter</param>
  29. public ParamsJsonSchemas(string[] schemaStrings)
  30. {
  31. this.SchemaStrings = schemaStrings;
  32. }
  33. ///// <summary>
  34. ///// Not specify jsonSchema, system will auto generate json schema for parameters
  35. ///// </summary>
  36. //public ParamsJsonSchemas() { }
  37. /// <summary>
  38. /// </summary>
  39. public string SchemaEmbededResourceName { get; private set; }
  40. /// <summary>
  41. /// Array of Json Schema strings, each array element is for a ctor parameter.
  42. /// </summary>
  43. public string[] SchemaStrings { get; private set; }
  44. }
  45. /// <summary>
  46. /// Declare the parts that the current host parts(marked this attribute) required.
  47. /// Mostly used in DeviceHandler that require combine with specific MessageBase,
  48. /// MessageCutter, MessageParser, Communicator, or DeviceProcessor, to construct a Processor.
  49. /// </summary>
  50. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
  51. public class MetaPartsRequired : Attribute
  52. {
  53. /// <summary>
  54. /// </summary>
  55. /// <param name="requiredPartsType">other parts's type</param>
  56. public MetaPartsRequired(Type requiredPartsType)
  57. {
  58. this.RequiredPartsType = requiredPartsType;
  59. }
  60. public Type RequiredPartsType { get; private set; }
  61. //public MetaPartsRequired(bool isSystemInternalComponent, string description)
  62. //{
  63. // this.IsSystemInternalComponent = isSystemInternalComponent;
  64. // this.Description = description;
  65. //}
  66. ///// <summary>
  67. ///// Use this Ctor for the purpose of declaring some info for host class itself.
  68. ///// </summary>
  69. ///// <param name="description">the purpose the host class for, may used for generate in UI</param>
  70. //public MetaPartsRequired(string description) : this(false, description)
  71. //{
  72. //}
  73. //public bool IsSystemInternalComponent { get; private set; }
  74. //public string Description { get; private set; }
  75. /// <summary>
  76. /// This value will be used in instantiate the PartsRequired.
  77. /// Each element in Array is a json value for corresponding ctor parameter that will be used to instantiate parts' instance.
  78. /// like: [1, "helloWorld", "{"name":"Elsa","age":"10"}"]
  79. /// </summary>
  80. public string[] DefaultCtorParamsJsonStrings { get; set; } = new string[] { };
  81. }
  82. /// <summary>
  83. /// Used to declare readable info for DeviceHandler or AppProcessor.
  84. /// </summary>
  85. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
  86. public class MetaPartsDescriptor : Attribute
  87. {
  88. /// <summary>
  89. /// The readable content for decorated class.
  90. /// </summary>
  91. /// <param name="displayName">text that support multi-language, follow the sample string-> lang-zh-cn:X加油机lang-en-us:Xdispenser</param>
  92. /// <param name="description">text that support multi-language, follow the sample string-> lang-zh-cn:用于驱动加油机lang-en-us:Used for driven dispenser</param>
  93. public MetaPartsDescriptor(string displayName, string description)
  94. {
  95. this.DisplayName = displayName;
  96. this.Description = description;
  97. }
  98. /// <summary>
  99. /// The readable content for decorated class, with category specified(by add tags).
  100. /// </summary>
  101. /// <param name="displayName">text that support multi-language, follow the sample string-> lang-zh-cn:X加油机lang-en-us:Xdispenser</param>
  102. /// <param name="description">text that support multi-language, follow the sample string-> lang-zh-cn:用于驱动加油机lang-en-us:Used for driven dispenser</param>
  103. /// <param name="tags">the category of the target, like: Pump, Atg, Terminal and ect. Multi-language is support here, if multi-lang string value is provided, then should at least provide english version of the value, which will be used for filtering(show me api feature).
  104. public MetaPartsDescriptor(string displayName, string description, string[] tags)
  105. {
  106. this.DisplayName = displayName;
  107. this.Description = description;
  108. this.Tags = tags;
  109. }
  110. public string[] Tags { get; private set; }
  111. public string DisplayName { get; private set; }
  112. public string Description { get; private set; }
  113. /// <summary>
  114. /// Gets or sets the value to indicates the decorated class(Either DeviceHanlder or AppProcessor)
  115. /// is a build-in and has no business logic module, this kind of module is always used for
  116. /// providing special management purpose APIs.
  117. /// </summary>
  118. public bool IsSystemInternalComponent { get; set; }
  119. /// <summary>
  120. /// if no concrete parameter specified, this default value will be pass into Parts(defined by Type) to try
  121. /// to instantiate the Parts instance.
  122. /// Each element in Array is a json value for corresponding ctor parameter that will be used to instantiate parts' instance.
  123. /// like: [1, "helloWorld", "{"name":"Peppa","age":"10"}"]
  124. /// </summary>
  125. public string[] DefaultCtorParamsJsonStrings { get; set; }
  126. }
  127. }