AutoCAD快速开发框架之插件Plugin

插件模块的结构图如下:

AutoCAD快速开发框架之插件Plugin

 插件模块通过LicensableModuleAttribute标记插件需要授权才能使用,通过重载CheckLicense函数验证授权,通过重载Install和Uninstall函数实现加载、卸载时的自定义操作。

PluginManager实现插件的管理,PluginFinder实现插件的查找。

// 2021-08-23 by www.cnblogs.com/ztcad
namespace ztcad.ThCad
{
    [LicensableModule]
    public class Plugin : BasePlugin
    {
        private readonly ILogger _logger;
        private readonly ISettingService _settingService;

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="logger">Logger</param>
        /// <param name="settingService">Settings service</param>
        public Plugin(ILogger logger,
           ISettingService settingService)
        {
            this._logger = logger;
            this._settingService = settingService;
        }

        public static string SystemName
        {
            get
            {
                return "ztcad.ThCad";
            }
        }

        public override bool CheckLicense()
        {
            return true;
        }

        /// <summary>
        /// Install the plugin
        /// </summary>
        public override void Install()
        {
            var settings = new ThCadSettings();
            _settingService.SaveSetting(settings);

            base.Install();

            _logger.Info(string.Format("Plugin installed: SystemName: {0}, Version: {1}, Description: ‘{2}‘", PluginDescriptor.SystemName, PluginDescriptor.Version, PluginDescriptor.FriendlyName));
        }

        /// <summary>
        /// Uninstall the plugin
        /// </summary>
        public override void Uninstall()
        {
            _settingService.DeleteSetting<ThCadSettings>();

            base.Uninstall();
        }
    }
}

 

AutoCAD快速开发框架之插件Plugin

上一篇:and cmake 链接库及播放例子


下一篇:变量、常量、作用域