Пример #1
0
 public void Register(IDevicePlugin devicePlugin)
 {
     if (devicePlugins.ContainsKey(devicePlugin.PluginId))
     {
         throw new ArgumentException("Failed to register plugin, because there was already a plugin registered with the same id.");
     }
     devicePlugins[devicePlugin.PluginId] = devicePlugin;
 }
Пример #2
0
        private void HandleMessage(Frame frame)
        {
            Messages.Message msg = null;

            var sourceDevice = Devices.Where(d => d.GroupNumber == frame.GroupNumber && d.ModuleNumber == frame.ModuleNumber).FirstOrDefault();

            IDevicePlugin devicePlugin = sourceDevice?.DevicePlugin;

            msg = devicePlugin?.GetMessage(frame);

            // device plugin don't recognize message? maybe other plugin would
            if (msg == null)
            {
                foreach (var plugin in DevicePlugins)
                {
                    msg = plugin.GetMessage(frame);
                    if (msg != null)
                    {
                        devicePlugin = plugin;
                        break;
                    }
                }
            }

            // still no luck? just create default message
            if (msg == null)
            {
                msg = new Messages.Message(frame);
            }

            Messages.Insert(0, msg);

            if (devicePlugin != null)
            {
                devicePlugin.HandleMessage(msg);
            }
        }
Пример #3
0
 public SecondViewModel(IDevicePlugin plugin)
 {
     _hello = plugin.GetDeviceName();
 }
Пример #4
0
        /// <summary>
        /// 设置插件参数。PluginViewBase将插件初始化后调用该方法,由继承的类对插件进行一些设置后再进行后续的加载步骤。
        /// </summary>
        /// <param name="plugin">需要被设置参数的插件。</param>
        protected override void SetPlugin(IPlugin plugin)
        {
            IDevicePlugin devicePlugin = plugin as IDevicePlugin;

            devicePlugin.SetDevices(this.Devices);
        }
Пример #5
0
        //如果返回 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);
        }