Exemplo n.º 1
0
        public void PopulateDialogBox(SupportedDesignEntityType designElementType, bool testonly = false)
        {
            List <Tuple <CATName, Type, MethodInfo> > listofCATmethods = new List <Tuple <CATName, Type, MethodInfo> >();

            // create the dialog box
            using (CyPhyComponentAuthoringToolGUI CATgut = new CyPhyComponentAuthoringToolGUI(DragNDropHandler))
            {
                // get the current assembly
                Assembly thisAssembly = Assembly.GetExecutingAssembly();

                // scan each class in the current assembly
                foreach (Type classtype in thisAssembly.GetTypes())
                {
                    // send_to_logger(String.Format("Found class {0}", classtype.ToString()), testonly);

                    // Linq query to get all CATModules
                    var CATModulesQuery = classtype.GetCustomAttributes(true)
                                          .OfType <IsCATModule>()
                                          .Where(x => x.ContainsCATmethod)
                                          .Distinct();

                    foreach (var CATMod in CATModulesQuery)
                    {
                        send_to_logger(String.Format("Found CATModule class {0}", classtype.ToString()), testonly);

                        // get a list of all the methods in the class
                        // scan each method in the class for custom attributes
                        foreach (MethodInfo meth in classtype.GetMethods())
                        {
                            // send_to_logger(String.Format("Found method {0}", meth.ToString()), testonly);

                            // Get the custom attributes for this method.
                            // If it has the CATName attribute, we'll add it as a button.
                            foreach (CATName attr in meth.GetCustomAttributes(typeof(CATName), true))
                            {
                                if ((attr.SupportedDesignEntityTypes & designElementType) ==
                                    designElementType)
                                {
                                    listofCATmethods.Add(new Tuple <CATName, Type, MethodInfo>(attr, classtype, meth));
                                }
                            }

                            if (designElementType == SupportedDesignEntityType.Component)
                            {
                                foreach (CATDnD attr in meth.GetCustomAttributes(typeof(CATDnD), true))
                                {
                                    // NOTE: Drag and drop support only on components for now
                                    dictofCATDnDMethods.Add(attr.Extension.ToLowerInvariant(), new Tuple <Type, MethodInfo>(classtype, meth));
                                }
                            }
                        }
                    }
                }

                CATgut.SuspendLayout();
                CATgut.AutoScaleDimensions = new SizeF(6F, 13F);
                foreach (Tuple <CATName, Type, MethodInfo> item in listofCATmethods.OrderBy(i => i.Item1.RoleVal))
                {
                    AddButtontoDialogBox(CATgut, item.Item1, item.Item2, item.Item3);
                }
                CATgut.ResumeLayout();

                // META-2679 Set the start position of CAT dialog box to the center of the screen.
                CATgut.StartPosition = FormStartPosition.CenterScreen;
                // save the dialog box ref for testing
                ThisDialogBox = CATgut;
                // start up the dialog box
                if (!testonly)
                {
                    CATgut.ShowDialog();
                }
            }
        }
        public void PopulateDialogBox(bool testonly = false)
        {
            List<Tuple<CATName, Type, MethodInfo>> listofCATmethods = new List<Tuple<CATName, Type, MethodInfo>>();

            // create the dialog box
            using (CyPhyComponentAuthoringToolGUI CATgut = new CyPhyComponentAuthoringToolGUI())
            {
                // get the current assembly
                Assembly thisAssembly = Assembly.GetExecutingAssembly();

                // scan each class in the current assembly
                foreach (Type classtype in thisAssembly.GetTypes())
                {
                    send_to_logger(String.Format("Found class {0}", classtype.ToString()), testonly);

                    // Linq query to get all CATModules
                    var CATModulesQuery = classtype.GetCustomAttributes(true)
                                                   .OfType<IsCATModule>()
                                                   .Where(x => x.ContainsCATmethod)
                                                   .Distinct();

                    foreach (var CATMod in CATModulesQuery)
                    {
                        send_to_logger(String.Format("Found CATModule {0}", CATMod.ToString()), testonly);

                        // get a list of all the methods in the class
                        // scan each method in the class for custom attributes
                        foreach (MethodInfo meth in classtype.GetMethods())
                        {
                            send_to_logger(String.Format("Found method {0}", meth.ToString()), testonly);

                            // Get the custom attributes for this method.
                            // If it has the CATName attribute, we'll add it as a button.
                            foreach (CATName attr in meth.GetCustomAttributes(typeof(CATName), true))
                            {
                                listofCATmethods.Add(new Tuple<CATName, Type, MethodInfo>(attr, classtype, meth));
                            }
                        }
                    }
                }

                foreach (Tuple<CATName, Type, MethodInfo> item in listofCATmethods.OrderBy(i => i.Item1.RoleVal))
                {
                    AddButtontoDialogBox(CATgut, item.Item1, item.Item2, item.Item3);
                }

                // META-2679 Set the start position of CAT dialog box to the center of the screen.
                CATgut.StartPosition = FormStartPosition.CenterScreen;
                // save the dialog box ref for testing
                ThisDialogBox = CATgut;
                // start up the dialog box
                if (!testonly)
                {
                    CATgut.ShowDialog();
                }
            }
        }