插件架构,图形用户界面 [英] Plugin architecture with GUI

查看:180
本文介绍了插件架构,图形用户界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,使大量使用的插件。该应用程序是在C#中,我想建立配置GUI在WPF。我在如何管理的实际插件本身方面得到了插件架构下来。但是,每个插件有它自己的配置,而这也正是我寻求帮助。

I'm developing an application that makes heavy use of plugins. The app is in C# and I'm thinking about building the configuration GUI in WPF. I got the plugin architecture down in terms of how to manage the actual plugins themselves. However, each plugin has its own configuration, and that's where I'm looking for help.

该插件架构很简单 - 有那个插件实现,我只是加载所有的目录里面的插件的接口。但是,你在哪里插件从中获取它们的配置?我想有处理这方面的一些通用的方式,让每个插件不负责读取自己的配置文件。另外,我想GUI来扩大与各插件 - 也就是说,安装在每个插件应该添加一个标签到GUI与该插件特定的配置方案。然后在保存配置文件(S)将被保存。

The plugin architecture is simple -- there's an interface that plugins implement and I just load all the plugins inside a directory. However, where do the plugins get their configuration from? I'd like to have some generic way of handling this, so that each plugin isn't responsible for reading its own configuration file. Also, I'd like the GUI to expand with each plugin -- that is, each plugin installed should add a tab to the GUI with the specific configuration options for that plugin. Then upon save, the configuration file(s) would be saved.

什么的会对此我最好的方法是什么?

What's my best way of going about this?

推荐答案

定义可配置的插件接口:

Define an interface for configurable plugins:

public interface IConfigurable
{
  public void LoadConfig(string configFile);

  public void ShowConfig();

  // Form or whatever, allows you to integrate it into another control
  public Form GetConfigWindow();
}

刚刚调用IConfigurable接口配置的插件。

The just invoke the IConfigurable interface for configurable plugins.

如果你愿意,你可以使接口工作的另一种方式,使得主要应用提供了一个容器(帧或码头为例)的插件太的感觉,但我会建议周围的其他方法。

If you want you can make the interface work the other way, making the main application provide a container (a frame or a dock for example) to the plugin for it too feel, but I would recommend the other way around.

public interface IConfigurable
{
  void LoadConfig(string configFile);

  void ShowConfig(DockPanel configurationPanel);
}

最后,你可以做硬盘的方式,通过定义到底是什么插件可以提供的配置选项。

Finally you can do it the hard way, by defining exactly what the plugin can offer as configuration option.

public interface IMainConfigInterop
{
  void AddConfigurationCheckBox(ConfigurationText text);
  void AddConfigurationRadioButton(ConfigurationText text);
  void AddConfigurationSpinEdit(Confguration text, int minValue, int maxValue);
}

public interface IConfigurable
{
  void LoadConfig(string configFile);

  void PrepareConfigWindow(IMainConfigInterop configInterop);
}

当然,

这个选项是更严格,更安全的,因为你可以限制如何完美插件能够与配置窗口交互。

of course this option is the more restrictive and more secure one, since you can limit perfectly how the plugin is able to interact with the configuration window.

这篇关于插件架构,图形用户界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆