Example #1
0
 public AwareToolEntry(ToolAttribute attribute, Type tt)
 {
     Type        = tt;
     Name        = attribute.Name;
     Description = attribute.Description;
     Keyword     = attribute.Keyword;
 }
Example #2
0
            public void AddTool(Type toolType, ToolAttribute toolAttribute)
            {
                var tool = new Tool {
                    Name        = toolAttribute.Name,
                    Keyword     = toolAttribute.Keyword,
                    Description = toolAttribute.Description
                };

                if (typeof(JSONTool).IsAssignableFrom(toolType))
                {
                    tool.SupportsJson = true;
                }

                if (typeof(IQueryParser).IsAssignableFrom(toolType))
                {
                    tool.SupportsQuery = true;

                    var toolInstance = (IQueryParser)Activator.CreateInstance(toolType);

                    tool.QueryInfo = new QueryInfo {
                        DynamicChoicesKey = toolInstance.DynamicChoicesKey,
                        Types             = new List <QueryTypeJSON>()
                    };
                    foreach (QueryType queryType in toolInstance.QueryTypes)
                    {
                        var typeJson = new QueryTypeJSON {
                            Name              = queryType.Name,
                            HumanName         = queryType.HumanName,
                            DynamicChoicesKey = queryType.DynamicChoicesKey
                        };
                        if (queryType.Tags != null)
                        {
                            typeJson.Tags = new List <QueryTagJSON>();
                            foreach (QueryTag tag in queryType.Tags)
                            {
                                if (tag.HumanName == null)
                                {
                                    continue;                        // avoid stuff that isn't really great e.g special
                                }
                                typeJson.Tags.Add(new QueryTagJSON {
                                    Name              = tag.Name,
                                    HumanName         = tag.HumanName,
                                    FixedValues       = tag.Options,
                                    DynamicChoicesKey = tag.DynamicChoicesKey
                                });
                            }
                        }

                        tool.QueryInfo.Types.Add(typeJson);
                    }
                }

                Tools.Add(tool);
            }
Example #3
0
        /// <summary>
        /// 将工具添加到toolbox中
        /// </summary>
        public void AddButton()
        {
            this.Items.Clear();
            //获得ToolBase组件
            Assembly assembly = Assembly.GetAssembly(typeof(ToolBase));

            Type[] types = assembly.GetTypes();
            //按钮排序,根据ToolAttribute中order进行排序
            SortedList <int, ToolStripButton> toolbtns = new SortedList <int, ToolStripButton>();

            //遍历组件,找出toolbox类
            //并添加天toolbox中
            foreach (Type t in types)
            {
                object[] attributes = t.GetCustomAttributes(typeof(ToolAttribute), true);
                if (attributes.Length > 0)
                {
                    ToolAttribute   toolAttribute = attributes[0] as ToolAttribute;
                    ToolStripButton tsb           = new ToolStripButton();
                    tsb.ToolTipText = toolAttribute.Description;//悬浮提示
                    if (toolAttribute.TooBoxImage != null)
                    {
                        tsb.Image = toolAttribute.TooBoxImage;//图标
                    }
                    tsb.CheckOnClick = true;
                    tsb.Tag          = t;
                    tsb.Click       += new EventHandler(tsb_Click);
                    toolbtns.Add(toolAttribute.Order, tsb);
                }
            }

            //添加toolbutton到toolbox容器中
            foreach (ToolStripButton tbtn in toolbtns.Values)
            {
                this.Items.Add(tbtn);
            }

            if (SelectTool == null && this.Items != null && this.Items.Count > 0)
            {
                selectTool = (ToolBase)Activator.CreateInstance((Type)((ToolStripButton)this.Items[0]).Tag);
                ((ToolStripButton)this.Items[0]).CheckState = CheckState.Indeterminate;
                if (ToolChanged != null)
                {
                    ToolChanged(this, null);
                }
            }
        }
Example #4
0
        public DataToolListView()
        {
            InitializeComponent();
            Type        t     = typeof(IAwareTool);
            Assembly    asm   = t.Assembly;
            List <Type> types = asm.GetTypes().Where(tt => tt.IsClass && t.IsAssignableFrom(tt)).ToList();

            foreach (Type tt in types)
            {
                ToolAttribute attribute = tt.GetCustomAttribute <ToolAttribute>();
                if (tt.IsInterface || attribute == null)
                {
                    continue;
                }

                Tools.Add(new AwareToolEntry(attribute, tt));
            }

            NotifyPropertyChanged(nameof(Tools));
        }
Example #5
0
 public ExpPen(uint id, string name, ToolAttribute attribute)
 {
     _id       = id; _name = name;
     Attribute = attribute;
 }