-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBasePlugin.cs
More file actions
180 lines (155 loc) · 5.35 KB
/
Copy pathBasePlugin.cs
File metadata and controls
180 lines (155 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using System.Collections.Generic;
using DTI_Tool.AddIn.Common.Interfaces;
using DTI_Tool.AddIn.Common.Models;
using BasePlugin.Core;
using Excel = Microsoft.Office.Interop.Excel;
namespace BasePlugin
{
/// <summary>
/// 基础插件模板 - 演示如何开发DTI Tool插件
/// </summary>
public class BasePlugin : IPlugin
{
#region 私有字段
private PluginLogger _logger;
private FeatureManager _featureManager;
private TaskPaneManager _taskPaneManager;
#endregion
#region IPlugin 接口属性
public string Name => "BasePlugin";
public string Version => "1.0.0";
public string Description => "基础插件开发模板 - 为开发者提供完整的示例代码";
public string Author => "开发者姓名";
#endregion
#region IPlugin 接口方法
/// <summary>
/// 初始化插件
/// </summary>
public void Initialize()
{
try
{
// 初始化日志记录器
_logger = PluginLog.ForPlugin(Name);
_logger.Info("=== 正在初始化 BasePlugin 插件 ===");
_logger.Debug("插件版本: {0}, 作者: {1}", Version, Author);
// 初始化功能管理器
_featureManager = new FeatureManager(_logger);
_featureManager.Initialize();
// 初始化任务窗格管理器
_taskPaneManager = new TaskPaneManager(_logger);
_taskPaneManager.Initialize();
_logger.Info("=== BasePlugin 插件初始化完成 ===");
}
catch (Exception ex)
{
_logger?.Error(ex, "插件初始化失败");
throw;
}
}
/// <summary>
/// 加载插件
/// </summary>
public void Load()
{
using (_logger?.MeasurePerformance("插件加载"))
{
try
{
_logger?.Info("正在加载插件...");
// 加载功能
_featureManager?.Load();
// 加载任务窗格
_taskPaneManager?.Load();
_logger?.Info("插件加载完成,状态:已就绪");
}
catch (Exception ex)
{
_logger?.Error(ex, "插件加载失败");
throw;
}
}
}
/// <summary>
/// 卸载插件
/// </summary>
public void Unload()
{
using (_logger?.MeasurePerformance("插件卸载"))
{
try
{
_logger?.Info("=== 正在卸载 BasePlugin 插件 ===");
// 卸载任务窗格
_taskPaneManager?.Unload();
// 卸载功能
_featureManager?.Unload();
_logger?.Info("=== BasePlugin 插件卸载完成 ===");
}
catch (Exception ex)
{
_logger?.Error(ex, "插件卸载时发生错误");
}
}
}
/// <summary>
/// 释放资源
/// </summary>
public void Dispose()
{
Unload();
}
/// <summary>
/// 获取功能区按钮列表
/// </summary>
public List<RibbonButton> GetRibbonButtons()
{
using (_logger?.MeasurePerformance("获取功能区按钮"))
{
return _featureManager?.GetRibbonButtons() ?? new List<RibbonButton>();
}
}
/// <summary>
/// 获取所有可执行命令
/// </summary>
public List<DTI_Tool.AddIn.Common.Interfaces.PluginCommand> GetCommands()
{
using (_logger?.MeasurePerformance("获取可执行命令"))
{
return _featureManager?.GetCommands() ?? new List<DTI_Tool.AddIn.Common.Interfaces.PluginCommand>();
}
}
/// <summary>
/// 搜索命令
/// </summary>
public List<DTI_Tool.AddIn.Common.Interfaces.PluginCommand> SearchCommands(string keyword)
{
using (_logger?.MeasurePerformance("搜索命令"))
{
return _featureManager?.SearchCommands(keyword) ?? new List<DTI_Tool.AddIn.Common.Interfaces.PluginCommand>();
}
}
/// <summary>
/// 执行命令
/// </summary>
public void ExecuteCommand(string commandId, object[] parameters)
{
using (_logger?.MeasurePerformance($"执行命令 {commandId}"))
{
try
{
_logger?.Debug("开始执行命令: {0},参数个数: {1}", commandId, parameters?.Length ?? 0);
_featureManager?.ExecuteCommand(commandId, parameters);
_logger?.Info("成功执行命令: {0}", commandId);
}
catch (Exception ex)
{
_logger?.Error(ex, "执行命令失败: {0}", commandId);
throw;
}
}
}
#endregion
}
}