using Autofac; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace GreenTree.Nachtragsmanagement.Core.Plugins { public class PluginDescriptor : IComparable { public PluginDescriptor() { this.SupportedVersions = new List(); this.LimitedToStores = new List(); } public PluginDescriptor(Assembly referencedAssembly, FileInfo originalAssemblyFile, Type pluginType) : this() { this.ReferencedAssembly = referencedAssembly; this.OriginalAssemblyFile = originalAssemblyFile; this.PluginType = pluginType; } /// /// Plugin type /// public virtual string PluginFileName { get; set; } /// /// Plugin type /// public virtual Type PluginType { get; set; } /// /// The assembly that has been shadow copied that is active in the application /// public virtual Assembly ReferencedAssembly { get; internal set; } /// /// The original assembly file that a shadow copy was made from it /// public virtual FileInfo OriginalAssemblyFile { get; internal set; } /// /// Gets or sets the plugin group /// public virtual string Group { get; set; } /// /// Gets or sets the friendly name /// public virtual string FriendlyName { get; set; } /// /// Gets or sets the system name /// public virtual string SystemName { get; set; } /// /// Gets or sets the version /// public virtual string Version { get; set; } /// /// Gets or sets the supported versions of nopCommerce /// public virtual IList SupportedVersions { get; set; } /// /// Gets or sets the author /// public virtual string Author { get; set; } /// /// Gets or sets the display order /// public virtual int DisplayOrder { get; set; } /// /// Gets or sets the list of store identifiers in which this plugin is available. If empty, then this plugin is available in all stores /// public virtual IList LimitedToStores { get; set; } /// /// Gets or sets the value indicating whether plugin is installed /// public virtual bool Installed { get; set; } public virtual T Instance() where T : class, IPlugin { object instance; if (!Singleton.Instance.TryResolve(PluginType, out instance)) { instance = Singleton.Instance.ResolveUnregistered(PluginType); } var typedInstance = instance as T; if (typedInstance != null) typedInstance.PluginDescriptor = this; return typedInstance; } public IPlugin Instance() { return Instance(); } public int CompareTo(PluginDescriptor other) { if (DisplayOrder != other.DisplayOrder) return DisplayOrder.CompareTo(other.DisplayOrder); return FriendlyName.CompareTo(other.FriendlyName); } public override string ToString() { return FriendlyName; } public override bool Equals(object obj) { var other = obj as PluginDescriptor; return other != null && SystemName != null && SystemName.Equals(other.SystemName); } public override int GetHashCode() { return SystemName.GetHashCode(); } } }