예제 #1
0
        /// <summary>
        /// Loading Enesy Command Method (ECM) information in this assembly
        /// </summary>
        /// <param name="markedOnly">Default value: false</param>
        internal void LoadingECM(bool markedOnly)
        {
            // Write message to command window
            Autodesk.AutoCAD.EditorInput.Editor ed =
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.
                MdiActiveDocument.Editor;
            ed.WriteMessage("\nLoading ECM Database ...");

            // Just get the commands for this assembly
            Assembly asm = Assembly.GetExecutingAssembly();

            // for command category
            object[] categorys = asm.GetCustomAttributes(typeof(CommandGroup), true);
            Type[]   catTypes;
            int      catNumtypes = categorys.Length;



            // Get EnesyCommandMethod attributes
            object[] objs = asm.GetCustomAttributes(typeof(EnesyCADCommandMethod), true);
            Type[]   tps;
            int      numTypes = objs.Length;

            if (numTypes > 0)
            {
                tps = new Type[numTypes];
                for (int i = 0; i < numTypes; i++)
                {
                    CommandClassAttribute cca = objs[i] as CommandClassAttribute;
                    if (cca != null)
                    {
                        tps[i] = cca.Type;
                    }
                }
            }
            else
            {
                // If we're only looking for specifically marked CommandClasses, then use an
                // empty list
                if (markedOnly)
                {
                    tps = new Type[0];
                }
                else
                {
                    tps = asm.GetExportedTypes();
                }
            }

            // Append valid value into Database
            foreach (Type tp in tps)
            {
                MethodInfo[] meths = tp.GetMethods();
                foreach (MethodInfo meth in meths)
                {
                    objs = meth.GetCustomAttributes(typeof(EnesyCADCommandMethod), true);
                    foreach (object obj in objs)
                    {
                        EnesyCADCommandMethod attb = (EnesyCADCommandMethod)obj;
                        if (!attb.IsTest)
                        {
                            // get command category
                            object[] cats     = meth.GetCustomAttributes(typeof(CommandGroup), true);
                            string   category = "";
                            int      index    = 0;
                            foreach (object c in cats)
                            {
                                index++;
                                CommandGroup commandCat = c as CommandGroup;
                                //GLOBAL.WriteMessage("Command " + attb.GlobalName + " - Category: " + commandCat.Category);
                                category = commandCat.Category;
                            }
                            //GLOBAL.WriteMessage("\nCategory " + index + "");
                            //
                            CmdRecord cmd = new CmdRecord(attb.GlobalName,
                                                          attb.Tag,
                                                          attb.Description,
                                                          attb.Author,
                                                          attb.Email,
                                                          attb.WebLink,
                                                          category
                                                          );
                            // Check if Database contains this cmd
                            if (!this.CmdTableRecord.Contains(attb.GlobalName))
                            {
                                this.CmdTableRecord.Add(attb.GlobalName,
                                                        attb.Tag,
                                                        !String.IsNullOrEmpty(attb.Tag) ? "[" + attb.Tag + "] " + GetCommandDescription(attb.Description) : GetCommandDescription(attb.Description),
                                                        attb.Author,
                                                        attb.Email,
                                                        attb.WebLink,
                                                        category
                                                        );
                                //if (!String.IsNullOrEmpty(cat.Category))
                                //{
                                //    GLOBAL.WriteMessage("Category: " + cat.Category);
                                //}
                            }
                        }
                    }
                }
            }
            //
        }
예제 #2
0
        /// <summary>
        /// Get information of commands from [EnesyCADCommandMethod] attribute
        /// </summary>
        /// <param name="asm">Assembly that contains .NET function</param>
        /// <param name="markedOnly"></param>
        /// <returns></returns>
        private static List <CommandInfo> GetCommands(Assembly asm, bool markedOnly)
        {
            {
                //StringCollection sc = new StringCollection();
                List <CommandInfo> cmdInfo = new List <CommandInfo>();
                object[]           objs    = asm.GetCustomAttributes(typeof(EnesyCADCommandMethod), true);
                Type[]             tps;
                int numTypes = objs.Length;
                if (numTypes > 0)
                {
                    tps = new Type[numTypes];
                    for (int i = 0; i < numTypes; i++)
                    {
                        CommandClassAttribute cca = objs[i] as CommandClassAttribute;
                        if (cca != null)
                        {
                            tps[i] = cca.Type;
                        }
                    }
                }
                else
                {
                    // If we're only looking for specifically
                    // marked CommandClasses, then use an
                    // empty list
                    if (markedOnly)
                    {
                        tps = new Type[0];
                    }
                    else
                    {
                        tps = asm.GetExportedTypes();
                    }
                }

                foreach (Type tp in tps)
                {
                    MethodInfo[] meths = tp.GetMethods();
                    foreach (MethodInfo meth in meths)
                    {
                        objs = meth.GetCustomAttributes(typeof(EnesyCADCommandMethod), true);
                        foreach (object obj in objs)
                        {
                            EnesyCADCommandMethod attb = (EnesyCADCommandMethod)obj;
                            if (!attb.IsTest)
                            {
                                cmdInfo.Add(new CommandInfo(attb.GlobalName,
                                                            attb.Tag,
                                                            attb.Description,
                                                            attb.Author,
                                                            attb.Email,
                                                            attb.WebLink
                                                            )
                                            );
                            }
                        }
                    }
                }
                return(cmdInfo);
            }
        }