PluginDescriptor.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Autofac;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace GreenTree.Nachtragsmanagement.Core.Plugins
  10. {
  11. public class PluginDescriptor : IComparable<PluginDescriptor>
  12. {
  13. public PluginDescriptor()
  14. {
  15. this.SupportedVersions = new List<string>();
  16. this.LimitedToStores = new List<int>();
  17. }
  18. public PluginDescriptor(Assembly referencedAssembly, FileInfo originalAssemblyFile,
  19. Type pluginType)
  20. : this()
  21. {
  22. this.ReferencedAssembly = referencedAssembly;
  23. this.OriginalAssemblyFile = originalAssemblyFile;
  24. this.PluginType = pluginType;
  25. }
  26. /// <summary>
  27. /// Plugin type
  28. /// </summary>
  29. public virtual string PluginFileName { get; set; }
  30. /// <summary>
  31. /// Plugin type
  32. /// </summary>
  33. public virtual Type PluginType { get; set; }
  34. /// <summary>
  35. /// The assembly that has been shadow copied that is active in the application
  36. /// </summary>
  37. public virtual Assembly ReferencedAssembly { get; internal set; }
  38. /// <summary>
  39. /// The original assembly file that a shadow copy was made from it
  40. /// </summary>
  41. public virtual FileInfo OriginalAssemblyFile { get; internal set; }
  42. /// <summary>
  43. /// Gets or sets the plugin group
  44. /// </summary>
  45. public virtual string Group { get; set; }
  46. /// <summary>
  47. /// Gets or sets the friendly name
  48. /// </summary>
  49. public virtual string FriendlyName { get; set; }
  50. /// <summary>
  51. /// Gets or sets the system name
  52. /// </summary>
  53. public virtual string SystemName { get; set; }
  54. /// <summary>
  55. /// Gets or sets the version
  56. /// </summary>
  57. public virtual string Version { get; set; }
  58. /// <summary>
  59. /// Gets or sets the supported versions of nopCommerce
  60. /// </summary>
  61. public virtual IList<string> SupportedVersions { get; set; }
  62. /// <summary>
  63. /// Gets or sets the author
  64. /// </summary>
  65. public virtual string Author { get; set; }
  66. /// <summary>
  67. /// Gets or sets the display order
  68. /// </summary>
  69. public virtual int DisplayOrder { get; set; }
  70. /// <summary>
  71. /// Gets or sets the list of store identifiers in which this plugin is available. If empty, then this plugin is available in all stores
  72. /// </summary>
  73. public virtual IList<int> LimitedToStores { get; set; }
  74. /// <summary>
  75. /// Gets or sets the value indicating whether plugin is installed
  76. /// </summary>
  77. public virtual bool Installed { get; set; }
  78. public virtual T Instance<T>() where T : class, IPlugin
  79. {
  80. object instance;
  81. if (!Singleton<IContainer>.Instance.TryResolve(PluginType, out instance))
  82. {
  83. instance = Singleton<IContainer>.Instance.ResolveUnregistered(PluginType);
  84. }
  85. var typedInstance = instance as T;
  86. if (typedInstance != null)
  87. typedInstance.PluginDescriptor = this;
  88. return typedInstance;
  89. }
  90. public IPlugin Instance()
  91. {
  92. return Instance<IPlugin>();
  93. }
  94. public int CompareTo(PluginDescriptor other)
  95. {
  96. if (DisplayOrder != other.DisplayOrder)
  97. return DisplayOrder.CompareTo(other.DisplayOrder);
  98. return FriendlyName.CompareTo(other.FriendlyName);
  99. }
  100. public override string ToString()
  101. {
  102. return FriendlyName;
  103. }
  104. public override bool Equals(object obj)
  105. {
  106. var other = obj as PluginDescriptor;
  107. return other != null &&
  108. SystemName != null &&
  109. SystemName.Equals(other.SystemName);
  110. }
  111. public override int GetHashCode()
  112. {
  113. return SystemName.GetHashCode();
  114. }
  115. }
  116. }