/// <summary> /// 初始化插件页及图标 /// </summary> /// <param name="plugin">插件对象</param> /// <param name="index">插件序号</param> private void LoadUIPlugin(IUIPlugin plugin, int index) { PictureBox picture = new PictureBox(); picture.BackColor = Color.Transparent; picture.Image = plugin.PluginPic; picture.InitialImage = null; picture.SizeMode = PictureBoxSizeMode.StretchImage; picture.Size = new Size(66, 66); picture.Margin = new Padding(10, 2, 0, 0); picture.TabStop = false; dicPicbox.Add(index, picture); dicUIPlugins.Add(index, plugin); #region ***取消注释部分代码可预加载页面*** //var iasync = tabCtrlMain.BeginInvoke(new Action(() => //{ // ShowUIPlugin(plugin.PluginForm); //})); //while (!iasync.IsCompleted) // Thread.Sleep(10);//等待加载结束,防止造成阻塞 //Thread.Sleep(50);//防止主线程繁忙导致长时间假死现象 #endregion //单击时切换至插件主界面 picture.Click += (sender, e) => { if (currentindex != -1) { dicPicbox[currentindex].Image = dicUIPlugins[currentindex].PluginPic; } picture.Image = plugin.SelectPluginPic; ShowUIPlugin(plugin.PluginForm, true); currentindex = index; }; }
/// <summary> /// Loads all the plugins from the given assembly. This method automatically searches the classes in the given assembly /// that implement the IUIPlugin interface, creates an instance each of them and registers them for installation. See /// the description of the IUIPlugin interface for more informations. /// </summary> /// <param name="fromAsm">The assembly to load the plugins from.</param> /// <returns>True in case of success, false otherwise.</returns> public bool LoadPlugins(Assembly fromAsm) { if (this.objectDisposed) { throw new ObjectDisposedException("UIRoot"); } if (fromAsm == null) { throw new ArgumentNullException("fromAsm"); } try { Type[] types = fromAsm.GetTypes(); foreach (Type type in types) { Type ifaceType = type.GetInterface("RC.UI.IUIPlugin"); if (ifaceType == typeof(IUIPlugin) && type.IsSealed) { IUIPlugin foundPlugin = fromAsm.CreateInstance(type.FullName) as IUIPlugin; string name = foundPlugin.Name; if (name != null && !this.loadedPlugins.ContainsKey(name)) { this.loadedPlugins.Add(name, foundPlugin); TraceManager.WriteAllTrace(string.Format("Plugin \"{0}\" has been loaded.", name), UITraceFilters.INFO); } else { TraceManager.WriteAllTrace(string.Format("Loading plugin \"{0}\" failed.", name != null ? name : "NULL"), UITraceFilters.ERROR); } } } return(true); } catch (Exception ex) { TraceManager.WriteExceptionAllTrace(ex, false); return(false); } }
protected virtual void OnUIPluginUnloaded(IUIPlugin uiPlugin) { Panel targetControl = !uiPlugin.Target.IsNullOrWhiteSpace() ? this.GetVisualChild<Panel>(uiPlugin.Target) : PlayerRoot; targetControl.IfNotNull(i => i.Children.Remove(uiPlugin.Element)); }