/// <summary> /// Load className plugin call SetHostHandleToBaseUserControl with UcHost handle /// as parameter and add the plugin control in groupBoxChild GroupBox /// </summary> /// <param name="className"></param> private void LoadSelectedPlugin(string className) { IPlugin plugin = default(IPlugin); // Create className plugin instance and load it for (int index = 0; index <= plugins.Length - 1; index++) { if (plugins[index].ClassName == className) { plugin = (IPlugin)ServiceUIPlugin.CreatePluginInstance(plugins[index]); // Pass UcHost handle to the uc, now uc can use UcHost properties and methods plugin.SetHostHandleToBaseUserControl(this); // Cache the uc loaded and dock it this.controlLoaded = (Control)plugin; this.controlLoaded.Dock = DockStyle.Fill; // Init some UcHost properties this.groupBoxChild.Text = plugin.PluginName; // Add plugin controlLoaded in the groupBoxChild this.groupBoxChild.Controls.Add(this.controlLoaded); } } }
/// <summary> /// Get plugins and fill comboBoxAuthenticationProvider /// </summary> private void GetPlugins() { // retrieve plugins list try { plugins = ServiceUIPlugin.GetPlugins(Path.GetDirectoryName(Application.ExecutablePath) + DLL_FOLDER_NAME, INTERFACE_PLUGIN_NAME); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (plugins == null) { MessageBox.Show("No plugin found !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } // Fill comboBoxAuthenticationProvider ignore UcBase foreach (var plugin in plugins) { if (plugin.ClassName != USER_CONTROL_CLASS_BASE_NAME) { ComboBoxAuthenticationProviderItem comboBoxItem = new ComboBoxAuthenticationProviderItem(); // Use item 3 as display value: example RFID for Me.AppPass.UI.RFID.UcRFID comboBoxItem.Text = plugin.ClassName.Split('.')[3]; // Value is uc type: example Me.AppPass.UI.RFID.UcRFID comboBoxItem.Value = plugin.ClassName; this.comboBoxAuthenticationProvider.Items.Add(comboBoxItem); } } }