예제 #1
0
        private static void RunAutoexecs(string[] strIncludes, string[] strExcludes)
        {
            HashSet <string> setIncludes = null;
            HashSet <string> setExcludes = null;

            if (strIncludes != null && strIncludes.Length > 0)
            {
                setIncludes = new HashSet <string>();
                foreach (string strInclude in strIncludes)
                {
                    setIncludes.Add(strInclude);
                }
            }
            if (strExcludes != null && strExcludes.Length > 0)
            {
                setExcludes = new HashSet <string>();
                foreach (string strExclude in strExcludes)
                {
                    setExcludes.Add(strExclude);
                }
            }
            if (m_eventLoad == null)
            {
                m_eventLoad = new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
                AppDomain.CurrentDomain.AssemblyLoad += m_eventLoad;
            }
            foreach (Assembly ass in CGestionnaireAssemblies.GetAssemblies())
            {
                RunAutoexec(ass, setIncludes, setExcludes);
            }
        }
예제 #2
0
 private static void LoadTypedsId()
 {
     if (m_bIsInit)
     {
         return;
     }
     m_bIsInit = true;
     foreach (Assembly ass in CGestionnaireAssemblies.GetAssemblies())
     {
         LoadTypesId(ass);
     }
     AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
 }
예제 #3
0
 public static void Autoexec()
 {
     foreach (Assembly ass in CGestionnaireAssemblies.GetAssemblies())
     {
         foreach (Type tp in ass.GetTypes())
         {
             object[] attrs = tp.GetCustomAttributes(typeof(ReplaceClassAttribute), false);
             if (attrs != null)
             {
                 foreach (ReplaceClassAttribute attr in attrs)
                 {
                     CActivatorSurChaine.RegisterTypeObsolete(attr.URITypeRemplace, tp);
                 }
             }
         }
     }
 }
예제 #4
0
        /// ////////////////////////////////////////////////////////////////
        public static CInfoClasseDynamique[] GetAllDynamicClass(params Type[] typesAttributsNecessaires)
        {
            ArrayList lstVals = new ArrayList();

            foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies())
            {
                try
                {
                    foreach (Type tp in ass.GetTypes())
                    {
                        try
                        {
                            object[] attribs = tp.GetCustomAttributes(typeof(DynamicClassAttribute), false);
                            if (attribs != null && attribs.Length == 1)
                            {
                                DynamicClassAttribute dynamicClass = (DynamicClassAttribute)attribs[0];
                                bool bToAdd = true;
                                foreach (Type tpAttrib in typesAttributsNecessaires)
                                {
                                    attribs = tp.GetCustomAttributes(tpAttrib, false);
                                    if (attribs == null || attribs.Length == 0)
                                    {
                                        bToAdd = false;
                                    }
                                }
                                if (bToAdd)
                                {
                                    lstVals.Add(new CInfoClasseDynamique(tp, dynamicClass.NomConvivial));
                                }
                            }
                        }
                        catch {}
                    }
                }
                catch
                {
                    System.Console.WriteLine(I.T("Type loading error|30108"));
                }
            }
            lstVals.Sort(new CInfoClassComparer());
            return((CInfoClasseDynamique[])lstVals.ToArray(typeof(CInfoClasseDynamique)));
        }
예제 #5
0
        /// ////////////////////////////////////////////////////////////////
        public static CInfoClasseDynamique[] GetAllDynamicClassHeritant(params Type[] typesHeritageNecessaires)
        {
            ArrayList lstVals = new ArrayList();

            foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies())
            {
                try
                {
                    foreach (Type tp in ass.GetTypes())
                    {
                        try
                        {
                            bool bOk = true;
                            foreach (Type tpHeritant in typesHeritageNecessaires)
                            {
                                if (!tpHeritant.IsAssignableFrom(tp))
                                {
                                    bOk = false;
                                    break;
                                }
                            }
                            if (bOk)
                            {
                                lstVals.Add(new CInfoClasseDynamique(
                                                tp,
                                                DynamicClassAttribute.GetNomConvivial(tp)));
                            }
                        }
                        catch { }
                    }
                }
                catch
                {
                    System.Console.WriteLine(I.T("Type loading error|30108"));
                }
            }
            lstVals.Sort(new CInfoClassComparer());
            return((CInfoClasseDynamique[])lstVals.ToArray(typeof(CInfoClasseDynamique)));
        }
예제 #6
0
        /// <summary>
        /// Aloue un objet à partir de son type sous forme de texte
        /// </summary>
        /// <param name="strTypeURI"></param>
        /// <param name="parametresConstructeur"></param>
        /// <returns></returns>
        public static Type GetType(string strTypeAdr, bool bAvecDynamicClass, bool bAvecTypeId)
        {
            if (String.IsNullOrEmpty(strTypeAdr))
            {
                return(null);
            }
            string strAss = "";

            Type   tp             = null;
            string strTypeDemande = strTypeAdr;

            if (m_cache.TryGetValue(strTypeAdr, out tp))
            {
                return(tp);
            }
            if (bAvecTypeId)
            {
                tp = TypeIdAttribute.GetType(strTypeAdr);
            }
            if (tp != null)
            {
                return(tp);
            }
            int nPosPipe = strTypeAdr.IndexOf('|');

            if (nPosPipe > 0)            //Si le nom est composé de assembly|nom de classe
            {
                strAss     = strTypeAdr.Substring(0, nPosPipe);
                strTypeAdr = strTypeAdr.Substring(nPosPipe + 1);
            }
            string strTypeUpper = strTypeAdr.ToUpper(CultureInfo.InvariantCulture);

            tp = Type.GetType(strTypeAdr);
            if (tp == null)
            {
                if (!m_cache.TryGetValue(strTypeAdr, out tp) || tp == null)
                {
                    if (strAss.Length > 0)
                    {
                        try
                        {
                            Assembly ass = Assembly.Load(strAss);
                            if (ass != null)
                            {
                                tp = ass.GetType(strTypeAdr);
                            }
                        }
                        catch
                        { }
                    }
                    if (tp == null)
                    {
                        //Tente d'abord en direct dans les assemblies
                        foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies())
                        {
                            tp = ass.GetType(strTypeAdr);
                            if (tp != null)
                            {
                                break;
                            }
                        }
                    }
                    if (tp == null)
                    {
                        //Si on ne trouve pas en recherche directe, balaie tous les assemblies, et cherche à la main dedans
                        foreach (System.Reflection.Assembly ass in CGestionnaireAssemblies.GetAssemblies())
                        {
                            foreach (Type type in ass.GetTypes())
                            {
                                if (type.FullName == strTypeAdr ||
                                    type.Name == strTypeAdr ||
                                    (bAvecDynamicClass && DynamicClassAttribute.GetNomConvivial(
                                         type).ToUpper(CultureInfo.InvariantCulture) == strTypeUpper))
                                {
                                    tp = type;
                                    break;
                                }
                            }
                            if (tp != null)
                            {
                                break;
                            }
                        }
                    }
                    if (tp == null)
                    {
                        //Recherche parmis les types obsolètes
                        if (!m_dicTypesObsoletes.TryGetValue(strTypeAdr, out tp))
                        {
                            tp = null;
                        }
                    }
                    m_cache[strTypeAdr] = tp;
                }
            }
            m_cache[strTypeDemande] = tp;

            return(tp);
        }