/// <summary> /// 将Assembly加载到面板中,构建面板内容 /// </summary> /// <param name="controlContainer"></param> /// <param name="uiView"></param> private void LoadAssemblyToPanel(DockPanel dockPanel, ControlContainer controlContainer, string assembly, string assemblyType) { if (string.IsNullOrWhiteSpace(assembly)) { return; } string[] temp = assembly.Split(','); if (temp.Length < 2) { return; } string assembleName = temp[1] + "." + assemblyType; string typeName = temp[0]; object obj = AssemblyHelper.GetInstanceFromAssembly(assembleName, typeName); if (obj == null) { logger.Error("加载【" + typeName + "】插件中的【" + assembleName + "】失败,并忽略该插件"); FanMessageBox.Warning("加载【" + typeName + "】插件中的【" + assembleName + "】失败,并忽略该插件", "系统消息"); return; } if (obj is FanUserControl) { FanUserControl userControl = (FanUserControl)obj; userControl.Name = dockPanel.Name; // +"_UserControl"; userControl.OwnerPanel = dockPanel; userControl.Dock = DockStyle.Fill; //将图标集转递给各个面板 userControl.LoadImage16Collection(GlobalParamService.SystemSettingParam.Image16CollectionList); userControl.LoadImage32Collection(GlobalParamService.SystemSettingParam.Image32CollectionList); controlContainer.Controls.Add(userControl); //将面板中的用户控件注册到寻址服务中 this.GetAddressService().Register(userControl.Name, userControl, ControlTypeEnum.UserControl); //this.Container.HookHolder.AddControlHook(userControl.ControlHookHolder); //this.Container.HookHolder.AddUiViewHook(userControl); //_uiViews_cache.Add(userControl); } else { logger.Error("加载【" + typeName + "】插件中的【" + assembleName + "】不是FanUserControl标准用户控件,并忽略该插件"); FanMessageBox.Show("加载【" + typeName + "】插件中的【" + assembleName + "】不是FanUserControl标准用户控件,并忽略该插件", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //else if (obj is UserControl) //{ // UserControl userControl = (UserControl)obj; // userControl.Dock = DockStyle.Fill; // controlContainer.Controls.Add(userControl); //} }
public void AddUiViewHook(string hookName, FanUserControl uiView) { if (hookName == null || uiView == null) { return; } if (!uiViewHookHolder.ContainsKey(hookName)) { this.uiViewHookHolder.Add(hookName, uiView); } else { logger.Error("UI句柄[" + hookName + "]已存在,不能添加到UI句柄列表"); } }
public void Dispose() { var controlList = this.GetControlHookHolder().Values; Control[] controlArray = new Control[controlList.Count]; controlList.CopyTo(controlArray, 0); for (int i = 0; i < controlArray.Length; i++) { try { var item = controlArray[i]; if (item != null && item is Control) { ((Control)item).Dispose(); } else if (item != null && item is Form) { ((Control)item).Dispose(); } } catch { } } controlArray = null; var uiViewHook = this.GetUiViewHookHolder().Values; FanUserControl[] uiAyyay = new FanUserControl[uiViewHook.Count]; uiViewHook.CopyTo(uiAyyay, 0); for (int i = 0; i < uiAyyay.Length; i++) { try { var item = uiAyyay[i]; if (item != null && item is FanUserControl) { ((FanUserControl)item).Dispose(); } } catch { } } uiAyyay = null; this.GetControlHookHolder().Clear(); this.GetUiViewHookHolder().Clear(); controlHookHolder = null; uiViewHookHolder = null; }
public void AddUiViewHook(FanUserControl uiView) { AddUiViewHook(uiView.UiViewName() + "." + uiView.Name, uiView); }