Ejemplo n.º 1
0
 public MultiTypeManager(IEnumerable <Assembly> lookassemblies, IEnumerable <Type> typesload,
                         iManagerCallback pcallback, AssemblyLoadTestFunction TestAssembly,
                         TypeManagerLoadProgressCallback pprog, IEnumerable <Assembly> preloadedassemblies)
     : this(lookassemblies, typesload, pcallback, TestAssembly, pprog, null, preloadedassemblies)
 {
 }
Ejemplo n.º 2
0
        public MultiTypeManager(IEnumerable <Assembly> lookassemblies, IEnumerable <Type> typesload,
                                iManagerCallback pcallback, AssemblyLoadTestFunction TestAssembly,
                                TypeManagerLoadProgressCallback pprog,
                                LoadedTypeManager.TypeManagerInspectTypeCallback pinspectioncallback,
                                IEnumerable <Assembly> preloadedassemblies)
        {
            lookassemblies = LoadedTypeManager.RemoveDuplicates(lookassemblies, pcallback).AsParallel();
            //each Type corresponds to a new LoadedTypeManager to load for that type.
            //LoadedTypeManager[] ltm = new LoadedTypeManager[typesload.Length];
            if (TestAssembly == null)
            {
                TestAssembly = ass => true;
            }
            //create the Dictionary first...
            inspectioncallback = pinspectioncallback;
            List <Assembly> buildcheck = new List <Assembly>();

            if (preloadedassemblies != null)
            {
                foreach (var addassembly in preloadedassemblies)
                {
                    if (!buildcheck.Contains(addassembly))
                    {
                        buildcheck.Add(addassembly);
                    }
                }
            }

            if (lookassemblies != null)
            {
                foreach (var addassembly in lookassemblies)
                {
                    if (!buildcheck.Contains(addassembly))
                    {
                        buildcheck.Add(addassembly);
                    }
                }
            }


            Assembly[] checkassemblies = buildcheck.ToArray();
            useassemblies = checkassemblies;
            loadeddata    = new Dictionary <Type, LoadedTypeManager>();
            foreach (Type looptype in typesload)
            {
                // LoadedTypeManager addtm = new LoadedTypeManager(checkassemblies,looptype, IgnoreAssemblies,pcallback);
                LoadedTypeManager addtm = new LoadedTypeManager(looptype);
                addtm.inspectioncallback = inspectioncallback;
                loadeddata.Add(looptype, addtm);
            }


            //now that we have the LoadedTypeManager objects, uninitialized- we can iterate through each assembly and the types
            //in each assembly for matches.
            //assemblyprogressincrement: the amount of progress we will go through after checking each assembly.
            float assemblyprogressincrement = 1f / (float)checkassemblies.Count();
            float currprogress = 0;

            foreach (Assembly loopassembly in checkassemblies)
            {
                if (TestAssembly(loopassembly))
                {
                    pcallback.ShowMessage("Inspecting Assembly:" + loopassembly.GetName().Name);
                    //iterate through each type...
                    currprogress += assemblyprogressincrement;
                    Type[] typesiterate;
                    try
                    {
                        typesiterate = loopassembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException rtle)
                    {
                        pcallback.ShowMessage
                            ("ReflectionTypeLoadException occured;" + rtle.StackTrace +
                            " InnerExceptions:");
                        foreach (Exception loopexception in rtle.LoaderExceptions)
                        {
                            pcallback.ShowMessage
                                ("RTLE Loader Exception:" + loopexception.Message + " Source:" +
                                loopexception.Source + "stack Trace:" + loopexception.StackTrace);
                        }

                        pcallback.ShowMessage("End of RTLE Loader Exceptions");
                        currprogress += assemblyprogressincrement;
                        pprog(currprogress);
                        typesiterate = null;
                    }

                    if (typesiterate != null)
                    {
                        //iterate through each type...

                        //get appropriate percent per type...
                        // float percentpertype = assemblyprogressincrement / typesiterate.Length;

                        foreach (Type looptype in typesiterate)
                        {
                            //currprogress+=percentpertype;

                            //if this is a class type...


                            // pcallback.ShowMessage("Checking type:" + looptype.FullName);
                            //And... for each type, iterate through all the LoadedTypeManagers in our dictionary...
                            foreach (var checkmanager in loadeddata)
                            {
                                if (LoadedTypeManager.CheckType(looptype, checkmanager.Key, pcallback))
                                {
                                    pcallback.ShowMessage
                                        ("Type:" + looptype.FullName + " is a, or implements, " +
                                        checkmanager.Key.Name);

                                    //add it to that manager...
                                    if (inspectioncallback != null)
                                    {
                                        inspectioncallback(looptype);
                                    }
                                    if (looptype != null)
                                    {
                                        checkmanager.Value.ManagedTypes.Add(looptype);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    currprogress += assemblyprogressincrement;
                    pprog(currprogress);
                    pcallback.ShowMessage("Skipped Assembly " + loopassembly.FullName);
                }
            }

            //at the conclusion of the loop, show a summary.
            if (!(pcallback is Nullcallback))
            {
                pcallback.ShowMessage
                    ("Assembly enumeration complete.(" + checkassemblies.Count().ToString() +
                    " Assemblies ");
                //^save time by not doing this for a Nullcallback...
                foreach (var loopltm in loadeddata)
                {
                    pcallback.ShowMessage
                        (" found " + loopltm.Value.ManagedTypes.Count + " instances of type " +
                        loopltm.Key.Name);
                }
            }
        }
Ejemplo n.º 3
0
 public MultiTypeManager(String[] lookfolders, Type[] typesload,
                         iManagerCallback pcallback, AssemblyLoadTestFunction TestAssembly,
                         TypeManagerLoadProgressCallback pp, Assembly[] preloadedassemblies)
     : this(AssembliesFromStrings(lookfolders), typesload, pcallback, TestAssembly, pp, preloadedassemblies)
 {
 }