我正在研究类似于C#中Nagios的系统监控应用程序.我有一个插件接口定义为:
public interface IPlugin
{
PluginResult Execute();
}
Run Code Online (Sandbox Code Playgroud)
每个插件,根据其功能,将具有可变数量的参数.例如,ping插件可能会占用主机名,数据包数,超时值等.我希望用户能够在我的用户界面中为每个服务定义这些参数,但很明显这些参数在应用程序发现哪些插件可用.我很好奇其他人如何设计一个插件,以便应用程序可以发现这些变量参数.
现在,作为一个例子,我有一个ping插件:
public class PingPlugin : IPlugin
{
private const string RESULT_MESSAGE = "Average ms: {0}; Packet loss: {1}";
private string _hostname;
private int _packets;
private int _timeout;
private int _warningTimeThreshold;
private int _warningLossThreshold;
private int _errorTimeThreshold;
private int _errorLossThreshold;
public PingPlugin(
string hostname,
int packets,
int timeout,
int warningTimeThreshold,
int warningLossThreshold,
int errorTimeThreshold,
int errorLossThreshold)
{
_hostname = hostname;
_packets = packets;
_timeout = timeout;
_warningTimeThreshold = warningTimeThreshold;
_warningLossThreshold = warningLossThreshold;
_errorTimeThreshold = errorTimeThreshold;
_errorLossThreshold = errorLossThreshold;
}
public PluginResult Execute()
{
// execute the plugin
}
}
Run Code Online (Sandbox Code Playgroud)
我以为我可能能够使用反射发现构造函数参数,并向用户提供属性网格以允许配置插件,但我不确定使用此设计提供一组默认值的最佳方法.可能有哪些替代方案?
Eri*_*sch 18
您是否考虑过查看Managed Extensibility Framework?
| 归档时间: |
|
| 查看次数: |
1277 次 |
| 最近记录: |