/// <summary> /// 跳转至指定设备的插件。 /// </summary> /// <param name="pluginType">设备插件。</param> /// <param name="devices">设备集合。</param> /// <param name="parameterValues">需要为该界面插件设置的参数默认值,如无参数可不设置。</param> /// <returns></returns> public DevicePluginView LoadView(DevicePluginType pluginType, Device[] devices, params ParameterValue[] parameterValues) { DevicePluginView view = null; foreach (ViewBase v in this.Views) { if (v is DevicePluginView) { DevicePluginView dv = v as DevicePluginView; if (dv.PluginType.Equals(pluginType)) { if (dv.Devices.Length == devices.Length) { bool bolIsEqually = true; for (int intIndex = 0; intIndex < devices.Length; intIndex++) { if (dv.Devices[intIndex].Equals(devices[intIndex]) == false) { bolIsEqually = false; break; } } if (bolIsEqually) { view = v as DevicePluginView; break; } } } } } if (view == null) { view = new DevicePluginView(this, pluginType, devices); if (parameterValues != null && parameterValues.Length > 0) { view.SetParameterValue(parameterValues); } this.Views.Load(view, ViewDockOptions.Center); } else { if (parameterValues != null && parameterValues.Length > 0) { view.SetParameterValue(parameterValues); } view.Focus(); } return(view); }
/// <summary> /// 跳转至指定设备的插件。 /// </summary> /// <param name="devicePluginType">设备插件类型声明。</param> /// <param name="devices">设备集合。</param> /// <param name="parameterValues">需要为该界面插件设置的参数默认值,如无参数可不设置。</param> /// <returns></returns> public DevicePluginView LoadView(Type devicePluginType, Device[] devices, params ParameterValue[] parameterValues) { DevicePluginType pluginType = base.GetDevicePluginType(this.CurrentAccount, devicePluginType, new Type[] { typeof(System.Windows.Forms.Control), typeof(System.Windows.Forms.ToolStripItem) }, devices); if (pluginType != null) { return(this.LoadView(pluginType, devices, parameterValues)); } else { throw new Exception("未发现可用的设备插件“" + devicePluginType + "”"); } }
internal void LoadDeviceView(string pluginTypeName, string deviceIds, string parameters) { Type typPluginType = Function.GetType(pluginTypeName); if (deviceIds != null && deviceIds.Length > 0) { DeviceSearch _Search = new DeviceSearch(base.Application); _Search.Filters.Add(new AC.Base.DeviceSearchs.IdFilter(deviceIds)); Device[] devices = _Search.Search(0).ToArray(); DevicePluginType _PluginType = base.Application.GetDevicePluginType(typPluginType, devices); if (parameters != null && parameters.Length > 1) { List <ParameterValue> lstParameterValues = new List <ParameterValue>(); string[] strParameters = parameters.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); for (int intIndex = 0; intIndex < strParameters.Length; intIndex += 2) { if (strParameters.Length >= intIndex + 2) { ParameterValue _ParameterValue = new ParameterValue(); _ParameterValue.Type = Function.GetType(strParameters[intIndex]); if (_ParameterValue.Type != null) { _ParameterValue.Value = strParameters[intIndex + 1]; lstParameterValues.Add(_ParameterValue); } } } this.Application.LoadView(_PluginType, devices, lstParameterValues.ToArray()); } else { this.Application.LoadView(_PluginType, devices); } } }
//如果返回 true 则表示该次调用有菜单项被输出 private bool GetDeviceMenu(PluginTypeCollection pluginTypes, ToolStripItemCollection menuItems) { bool bolIsOutput = false; for (int intIndex = 0; intIndex < pluginTypes.Count; intIndex++) { DevicePluginType _PluginType = pluginTypes[intIndex] as DevicePluginType; if ((_PluginType.Type.GetInterface(typeof(IDeviceHtmlPlugin).FullName, true) != null) || (Function.IsInheritableBaseType(_PluginType.Type, typeof(System.Windows.Forms.Control)))) { //HTML、控件 ToolStripMenuItem mnuDevicePlugin = new ToolStripMenuItem(); mnuDevicePlugin.Text = _PluginType.Name; mnuDevicePlugin.Image = _PluginType.Icon16; mnuDevicePlugin.Tag = _PluginType; if (_PluginType.Description != null && _PluginType.Description.Length > 0) { mnuDevicePlugin.ToolTipText = _PluginType.Description; } if (_PluginType.Icon16 != null) { mnuDevicePlugin.Image = _PluginType.Icon16; } mnuDevicePlugin.Click += new EventHandler(mnuDevicePlugin_Click); if (_PluginType.Children.Count > 0) { this.GetDeviceMenu(_PluginType.Children, mnuDevicePlugin.DropDownItems); } //mnuDevicePlugin.MouseEnter += new EventHandler(mnuDevicePlugin_MouseEnter); menuItems.Add(mnuDevicePlugin); bolIsOutput = true; } else if (Function.IsInheritableBaseType(_PluginType.Type, typeof(System.Windows.Forms.ToolStripItem))) { //自定义的菜单项 System.Reflection.ConstructorInfo ci = _PluginType.Type.GetConstructor(new System.Type[] { }); object objInstance = ci.Invoke(new object[] { }); IDevicePlugin plugin = objInstance as IDevicePlugin; ToolStripItem mnuDevicePlugin = plugin as ToolStripItem; if (_PluginType.Icon16 != null) { mnuDevicePlugin.Image = _PluginType.Icon16; } menuItems.Add(mnuDevicePlugin); plugin.SetDevices((Device[])mnuDevicePlugin.Owner.Tag); if (plugin is IUseAccount) { IUseAccount useAccount = plugin as IUseAccount; useAccount.SetAccount(this.CurrentAccount); } plugin.SetApplication(this); if (mnuDevicePlugin.Text.Length == 0) { mnuDevicePlugin.Text = _PluginType.Name; } if (_PluginType.Description != null && _PluginType.Description.Length > 0 && (mnuDevicePlugin.ToolTipText == null || mnuDevicePlugin.ToolTipText.Length == 0)) { mnuDevicePlugin.ToolTipText = _PluginType.Description; } //tsi.MouseEnter += new EventHandler(mnuDevicePlugin_MouseEnter); bolIsOutput = true; } else if (_PluginType.Name == null) { //分隔线 if (bolIsOutput && _PluginType.Children.Count > 0) { menuItems.Add(new ToolStripSeparator()); } //分隔线的子插件 if (this.GetDeviceMenu(_PluginType.Children, menuItems)) { bolIsOutput = true; } } else { //作为分类处理 if (_PluginType.Children.Count > 0) { ToolStripMenuItem mnuDevicePlugin = new ToolStripMenuItem(); mnuDevicePlugin.Text = _PluginType.Name; if (_PluginType.Description != null && _PluginType.Description.Length > 0) { mnuDevicePlugin.ToolTipText = _PluginType.Description; } if (_PluginType.Icon16 != null) { mnuDevicePlugin.Image = _PluginType.Icon16; } //mnuDevicePlugin.MouseEnter += new EventHandler(mnuDevicePlugin_MouseEnter); this.GetDeviceMenu(_PluginType.Children, mnuDevicePlugin.DropDownItems); menuItems.Add(mnuDevicePlugin); bolIsOutput = true; } } } return(bolIsOutput); }