Exemplo n.º 1
0
 public static string GetTypeRouteUrl(Type t)
 {
     object[] attributes = t.GetCustomAttributes(typeof(RouteUrlAttribute), false);
     foreach (object item in attributes)
     {
         RouteUrlAttribute at = (RouteUrlAttribute)item;
         return(at.RouteUrl);
     }
     return(string.Empty);
 }
        public static void PrepareReflection()
        {
            if (!SF.UsePlugins())
            {
                List <Type>  PageTypesRepository           = new List <Type>();
                List <Type>  AdminControlerTypesRepository = new List <Type>();
                List <ITask> TasksRepository = new List <ITask>();
                Dictionary <string, Type> PageTypesDictionaryReprository = new Dictionary <string, Type>();

                AppDomain currentDomain = AppDomain.CurrentDomain;
                Assembly  assembly      = currentDomain.GetAssemblies().Where(r => r.FullName.StartsWith("Uco,")).First();

                PageTypesRepository.AddRange(from t in assembly.GetTypes()
                                             where t.IsSubclassOf(typeof(AbstractPage))
                                             select t);

                AdminControlerTypesRepository.AddRange(from t in assembly.GetTypes()
                                                       where t.IsSubclassOf(typeof(BaseAdminController))
                                                       select t);

                var instances = from t in assembly.GetTypes()
                                where t.GetInterfaces().Contains(typeof(ITask)) && t.GetConstructor(Type.EmptyTypes) != null
                                select Activator.CreateInstance(t) as ITask;

                if (SF.UseTasks())
                {
                    TasksRepository.AddRange(instances);
                }
                foreach (Type t in PageTypesRepository)
                {
                    System.Attribute[] attrs = System.Attribute.GetCustomAttributes(t);
                    foreach (System.Attribute attr in attrs)
                    {
                        if (attr is RouteUrlAttribute)
                        {
                            RouteUrlAttribute a = (RouteUrlAttribute)attr;
                            PageTypesDictionaryReprository.Add(a.RouteUrl, t);
                        }
                    }
                }

                LS.Cache["PageTypesRepository"]           = PageTypesRepository;
                LS.Cache["AdminControlerTypesRepository"] = AdminControlerTypesRepository;
                LS.Cache["TasksRepository"] = TasksRepository;
                LS.Cache["PageTypesDictionaryReprository"] = PageTypesDictionaryReprository;
            }
            else
            {
                LS.Cache["PageTypesRepository"]           = new List <Type>();;
                LS.Cache["AdminControlerTypesRepository"] = new List <Type>();;
                LS.Cache["TasksRepository"] = new List <ITask>();
                LS.Cache["PageTypesDictionaryReprository"] = new Dictionary <string, Type>();
            }


            //Dictionary<string, Type> dictionary = new Dictionary<string, Type>();

            //using (AssemblyLocator al = new AssemblyLocator())
            //{
            //    ReadOnlyCollection<Assembly> UcoAssemblies = al.GetUcoAssemblies();
            //    foreach (Assembly item1 in UcoAssemblies)
            //    {
            //        foreach (Type item2 in item1.GetTypes().Where(r => r.IsSubclassOf(typeof(AbstractPage))).ToList())
            //        {
            //            System.Attribute[] attrs = System.Attribute.GetCustomAttributes(item2);
            //            foreach (System.Attribute attr in attrs)
            //            {
            //                if (attr is RouteUrlAttribute)
            //                {
            //                    RouteUrlAttribute a = (RouteUrlAttribute)attr;
            //                    dictionary.Add(a.RouteUrl, item2);
            //                }
            //            }
            //        }
            //    }
            //}

            //LS.Cache[Token] = dictionary;
            //return dictionary;



            //List<ITask> l = new List<ITask>();
            //foreach (var assembly in RP.GetUcoAssemblyReprository())
            //{
            //    var instances = from t in assembly.GetTypes()
            //                    where t.GetInterfaces().Contains(typeof(ITask))
            //                             && t.GetConstructor(Type.EmptyTypes) != null
            //                    select Activator.CreateInstance(t) as ITask;
            //    if (assembly.GetName().Name == "Uco" || RP.GetPluginsReprository().Contains(assembly.GetName().Name))
            //    {
            //        l.AddRange(instances);
            //    }
            //}

            //LS.Cache[Token] = l;
            //return l;
        }