Rechargement Plugin via MEF
Bonjour,
Je gère des plugin via MEF. Tout les plugin se chargent bien. Je souhaite maintenant pouvoir ajouter d'autre plugin sans arrêter l'application et que les information des plugin déjà présent soient conservé. J'ai donc essayé ceci qui se lance quand je clique sur un bouton recharger :
Code:
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
|
int i = 0;
List<string> listPluginPresent = new List<string>();
static Dictionary<string, IPlugin> _Plugins;
//Charge les plugins qui correspondent à l'interface IPlugin
public object chargementPlugins()
{
i=0;
PluginLoader loader = new PluginLoader("Plugin");
_Plugins = new Dictionary<string, IPlugin>();
IEnumerable<IPlugin> plugins = loader.Plugins;
Button pluginButton = new Button();
Button startButton = new Button();
Button finButton = new Button();
foreach (IPlugin plugin in plugins)
{
bool dejaVu = false;
string titlePlugin = plugin.nomPlugin();
foreach (string pp in listPluginPresent)
{
if (pp == titlePlugin)
{
SetInfos(0, "deja vu", DateTime.Now, titlePlugin);
dejaVu = true;
break;
}
}
if (dejaVu == false)
{
listPluginPresent.Add(titlePlugin);
plugin.Setinfos += SetInfos;
TabPage myTabPage = new TabPage(titlePlugin);
myTabPage.Tag = titlePlugin;
tabControl1.TabPages.Add(myTabPage);
_Plugins.Add(myTabPage.Tag.ToString(), plugin);
i = 1;
}
}
foreach (TabPage pages in tabControl1.TabPages)
{
if (i == 1)
{
if (_Plugins[pages.Text].returnCreerBouton() == true)
{
pluginButton = new Button();
pluginButton.Location = new Point(600, 30);
pluginButton.Text = pages.Text;
pages.Controls.Add(pluginButton);
}
startButton = new Button();
startButton.Location = new Point(50, 20);
startButton.Text = "start";
pages.Controls.Add(startButton);
startButton.Click += new EventHandler(start_Click);
finButton = new Button();
finButton.Location = new Point(50, 40);
finButton.Text = "fin";
pages.Controls.Add(finButton);
finButton.Click += new EventHandler(fin_Click);
}
}
return plugins;
} |
Cependant, je ne peux plus utiliser les plugin qui étaient là avant, j'ai l'erreur : "la clé donné était absente du dictionnaire.D'après ce que je comprends, il me recharge tout à zéro et comme le plugin était déjà là avant il ne le recrée pas.
Sauriez-vous me dire comment faire pour charger uniquement ceux qui sont nouveau?
Merci d'avance !