Esempio n. 1
0
        private void AddConnectionTreeViewContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                // dynamically create a drop down list of all connections available in plugins
                addConnectionToolStripMenuItem.DropDownItems.Clear();
                List <Type> connectionTypes = CoreUtility.GetInterfaceImplementorsWithAttribute(typeof(IConnection), typeof(ConnectionAttribute));

                foreach (Type connectionType in connectionTypes)
                {
                    ConnectionAttribute connectionAttribute            = (ConnectionAttribute)Attribute.GetCustomAttribute(connectionType, typeof(ConnectionAttribute));
                    ToolStripMenuItem   addConnectionToolStripMenuItem = new ToolStripMenuItem(connectionType.Name)
                    {
                        ImageScaling = ToolStripItemImageScaling.None,
                        Tag          = connectionType
                    };
                    addConnectionToolStripMenuItem.Click      += AddConnectionToolStripMenuItem_Click;
                    addConnectionToolStripMenuItem.Text        = connectionAttribute.DisplayName;
                    addConnectionToolStripMenuItem.ToolTipText = connectionAttribute.Description;
                    addConnectionToolStripMenuItem.Image       = connectionAttribute.GetIcon(connectionType.Assembly);

                    this.addConnectionToolStripMenuItem.DropDownItems.Add(addConnectionToolStripMenuItem);
                }

                addConnectionToolStripMenuItem.Enabled = addConnectionToolStripMenuItem.DropDownItems.Count > 0;
            }
            catch (Exception ex)
            {
                ApplicationState.Default.RaiseNotification(new NotificationEventArgs(NotificationType.Error, ex.Message, ex));
            }
        }
Esempio n. 2
0
        private void AddConnectionImage(Type type)
        {
            // find the image corresponding with the connection so it can be displayed in the TreeView
            ConnectionAttribute attribute = (ConnectionAttribute)Attribute.GetCustomAttribute(type, typeof(ConnectionAttribute));

            if (attribute?.IconResourceName != null && !connectionImageList.Images.ContainsKey(type.FullName))
            {
                connectionImageList.Images.Add(type.FullName, attribute.GetIcon(type.Assembly));
            }
        }