Пример #1
0
        public static void LoadAttribute(List <Assembly> BusinessDll, ModulePlugin mp)
        {
            List <WinformControllerAttributeInfo> cmdControllerList = new List <WinformControllerAttributeInfo>();

            for (int k = 0; k < BusinessDll.Count; k++)
            {
                //System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                System.Reflection.Assembly assembly = BusinessDll[k];
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    WinformControllerAttribute[] winC = ((WinformControllerAttribute[])types[i].GetCustomAttributes(typeof(WinformControllerAttribute), true));

                    if (winC.Length > 0)
                    {
                        WinformControllerAttributeInfo cmdC = new WinformControllerAttributeInfo();
                        cmdC.controllerName  = types[i].Name;
                        cmdC.defaultViewName = winC[0].DefaultViewName;
                        //cmdC.winformController = (AbstractController)Activator.CreateInstance(types[i], null);
                        cmdC.winformController = (AbstractController)FactoryModel.GetObject(types[i], mp.database, mp.container, mp.cache, mp.plugin.name, null);
                        cmdC.MethodList        = new List <WinformMethodAttributeInfo>();
                        cmdC.ViewList          = new List <WinformViewAttributeInfo>();

                        MethodInfo[] property = types[i].GetMethods();
                        for (int n = 0; n < property.Length; n++)
                        {
                            WinformMethodAttribute[] WinM = (WinformMethodAttribute[])property[n].GetCustomAttributes(typeof(WinformMethodAttribute), true);
                            if (WinM.Length > 0)
                            {
                                WinformMethodAttributeInfo cmdM = new WinformMethodAttributeInfo();
                                cmdM.methodName = property[n].Name;
                                cmdM.methodInfo = property[n];
                                if (WinM[0].OpenDBKeys != null && WinM[0].OpenDBKeys.ToString().Trim() != "")
                                {
                                    cmdM.dbkeys = WinM[0].OpenDBKeys.Split(new char[] { ',' }).ToList();
                                }
                                cmdC.MethodList.Add(cmdM);
                            }
                        }

                        WinformViewAttribute[] viewAttribute = (WinformViewAttribute[])types[i].GetCustomAttributes(typeof(WinformViewAttribute), true);
                        for (int n = 0; n < viewAttribute.Length; n++)
                        {
                            WinformViewAttributeInfo winView = new WinformViewAttributeInfo();
                            winView.Name          = viewAttribute[n].Name;
                            winView.DllName       = viewAttribute[n].DllName;
                            winView.ViewTypeName  = viewAttribute[n].ViewTypeName;
                            winView.IsDefaultView = winView.Name == cmdC.defaultViewName ? true : false;

                            //Assembly _assembly = Assembly.LoadFrom(winView.DllName);
                            winView.ViewType = assembly.GetType(winView.ViewTypeName, false, true);
                            cmdC.ViewList.Add(winView);
                        }
                        cmdControllerList.Add(cmdC);
                    }
                }
            }

            mp.cache.Add(mp.plugin.name + "@" + GetCacheKey(), cmdControllerList);
        }
        public static void LoadAttribute(List<string> BusinessDll,ModulePlugin mp)
        {
            List<WinformControllerAttributeInfo> cmdControllerList = new List<WinformControllerAttributeInfo>();

            for (int k = 0; k < BusinessDll.Count; k++)
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    WinformControllerAttribute[] winC = ((WinformControllerAttribute[])types[i].GetCustomAttributes(typeof(WinformControllerAttribute), true));

                    if (winC.Length > 0)
                    {
                        WinformControllerAttributeInfo cmdC = new WinformControllerAttributeInfo();
                        cmdC.controllerName = types[i].Name;
                        cmdC.defaultViewName = winC[0].DefaultViewName;
                        //cmdC.winformController = (AbstractController)Activator.CreateInstance(types[i], null);
                        cmdC.winformController = (AbstractController)FactoryModel.GetObject(types[i], mp.database, mp.container, mp.cache, mp.plugin.name, null);
                        cmdC.MethodList = new List<WinformMethodAttributeInfo>();
                        cmdC.ViewList = new List<WinformViewAttributeInfo>();

                        MethodInfo[] property = types[i].GetMethods();
                        for (int n = 0; n < property.Length; n++)
                        {
                            WinformMethodAttribute[] WinM = (WinformMethodAttribute[])property[n].GetCustomAttributes(typeof(WinformMethodAttribute), true);
                            if (WinM.Length > 0)
                            {
                                WinformMethodAttributeInfo cmdM = new WinformMethodAttributeInfo();
                                cmdM.methodName = property[n].Name;
                                cmdM.methodInfo = property[n];
                                if (WinM[0].OpenDBKeys != null && WinM[0].OpenDBKeys.ToString().Trim() != "")
                                    cmdM.dbkeys = WinM[0].OpenDBKeys.Split(new char[] { ',' }).ToList();
                                cmdC.MethodList.Add(cmdM);
                            }
                        }

                        WinformViewAttribute[] viewAttribute = (WinformViewAttribute[])types[i].GetCustomAttributes(typeof(WinformViewAttribute), true);
                        for (int n = 0; n < viewAttribute.Length; n++)
                        {
                            WinformViewAttributeInfo winView = new WinformViewAttributeInfo();
                            winView.Name = viewAttribute[n].Name;
                            winView.DllName = viewAttribute[n].DllName;
                            winView.ViewTypeName = viewAttribute[n].ViewTypeName;
                            winView.IsDefaultView = winView.Name == cmdC.defaultViewName ? true : false;

                            Assembly _assembly = Assembly.LoadFrom(winView.DllName);
                            winView.ViewType = _assembly.GetType(winView.ViewTypeName, false, true);
                            cmdC.ViewList.Add(winView);
                        }
                        cmdControllerList.Add(cmdC);
                    }
                }
            }

            mp.cache.Add(mp.plugin.name+"@"+GetCacheKey(), cmdControllerList);
        }
        public static void LoadAttribute()
        {
            List <Assembly> Assemblys = GetLocalAssembly();

            ControllerList = new List <WinformControllerAttributeInfo>();

            for (int k = 0; k < Assemblys.Count; k++)
            {
                //System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(BusinessDll[k]);
                System.Reflection.Assembly assembly = Assemblys[k];
                Type[] types = assembly.GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    WinformControllerAttribute[] winC = ((WinformControllerAttribute[])types[i].GetCustomAttributes(typeof(WinformControllerAttribute), true));

                    if (winC.Length > 0)
                    {
                        WinformControllerAttributeInfo cmdC = new WinformControllerAttributeInfo();
                        cmdC.controllerName    = types[i].Name;
                        cmdC.defaultViewName   = winC[0].DefaultViewName;
                        cmdC.winformController = (WinformFrame.Controller.WinformController)Activator.CreateInstance(types[i], null);
                        cmdC.MethodList        = new List <WinformMethodAttributeInfo>();
                        cmdC.ViewList          = new List <WinformViewAttributeInfo>();

                        MethodInfo[] property = types[i].GetMethods();
                        for (int n = 0; n < property.Length; n++)
                        {
                            WinformMethodAttribute[] WinM = (WinformMethodAttribute[])property[n].GetCustomAttributes(typeof(WinformMethodAttribute), true);
                            if (WinM.Length > 0)
                            {
                                WinformMethodAttributeInfo cmdM = new WinformMethodAttributeInfo();
                                cmdM.methodName = property[n].Name;
                                cmdM.methodInfo = property[n];
                                cmdC.MethodList.Add(cmdM);
                            }
                        }

                        WinformViewAttribute[] viewAttribute = (WinformViewAttribute[])types[i].GetCustomAttributes(typeof(WinformViewAttribute), true);
                        for (int n = 0; n < viewAttribute.Length; n++)
                        {
                            WinformViewAttributeInfo winView = new WinformViewAttributeInfo();
                            winView.Name          = viewAttribute[n].Name;
                            winView.DllName       = viewAttribute[n].DllName;
                            winView.ViewTypeName  = viewAttribute[n].ViewTypeName;
                            winView.IsDefaultView = winView.Name == cmdC.defaultViewName ? true : false;

                            //Assembly _assembly = Assembly.LoadFrom(winView.DllName);
                            winView.ViewType = assembly.GetType(winView.ViewTypeName, false, true);
                            cmdC.ViewList.Add(winView);
                        }
                        ControllerList.Add(cmdC);
                    }
                }
            }
        }